Skip to content

Commit

Permalink
#271 Update examples (#272)
Browse files Browse the repository at this point in the history
* #271 Savepoint

* #271 Savepoint

* #271 Savepoint

* #271 Savepoint

* #271 Savepoint

* #271 Savepoint

* #271 Prepare for versioned release
  • Loading branch information
docktermj authored Jan 31, 2025
1 parent f2efaf8 commit 7d5937d
Show file tree
Hide file tree
Showing 10 changed files with 934 additions and 300 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ and this project adheres to [Semantic Versioning].

-

## [0.8.8] - 2025-01-31

### Changed in 0.8.8

- Update dependencies
- Updated test cases and examples

## [0.8.7] - 2025-01-24

### Changed in 0.8.7
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect
golang.org/x/exp v0.0.0-20250128182459-e0ece0dbea4c // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250122153221-138b5a5a4fd4 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250127172529-29210b9bc287 // indirect
google.golang.org/grpc v1.70.0 // indirect
google.golang.org/protobuf v1.36.4 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ go.opentelemetry.io/otel/sdk/metric v1.32.0 h1:rZvFnvmvawYb0alrYkjraqJq0Z4ZUJAiy
go.opentelemetry.io/otel/sdk/metric v1.32.0/go.mod h1:PWeZlq0zt9YkYAp3gjKZ0eicRYvOh1Gd+X99x6GHpCQ=
go.opentelemetry.io/otel/trace v1.32.0 h1:WIC9mYrXf8TmY/EXuULKc8hR17vE+Hjv2cssQDe03fM=
go.opentelemetry.io/otel/trace v1.32.0/go.mod h1:+i4rkvCraA+tG6AzwloGaCtkx53Fa+L+V8e9a7YvhT8=
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 h1:yqrTHse8TCMW1M1ZCP+VAR/l0kKxwaAIqN/il7x4voA=
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8/go.mod h1:tujkw807nyEEAamNbDrEGzRav+ilXA7PCRAd6xsmwiU=
golang.org/x/exp v0.0.0-20250128182459-e0ece0dbea4c h1:KL/ZBHXgKGVmuZBZ01Lt57yE5ws8ZPSkkihmEyq7FXc=
golang.org/x/exp v0.0.0-20250128182459-e0ece0dbea4c/go.mod h1:tujkw807nyEEAamNbDrEGzRav+ilXA7PCRAd6xsmwiU=
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250122153221-138b5a5a4fd4 h1:yrTuav+chrF0zF/joFGICKTzYv7mh/gr9AgEXrVU8ao=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250122153221-138b5a5a4fd4/go.mod h1:+2Yz8+CLJbIfL9z73EW45avw8Lmge3xVElCP9zEKi50=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250127172529-29210b9bc287 h1:J1H9f+LEdWAfHcez/4cvaVBox7cOYT+IU6rgqj5x++8=
google.golang.org/genproto/googleapis/rpc v0.0.0-20250127172529-29210b9bc287/go.mod h1:8BS3B93F/U1juMFq9+EDk+qOT5CO1R9IzXxG3PTqiRk=
google.golang.org/grpc v1.70.0 h1:pWFv03aZoHzlRKHWicjsZytKAiYCtNS0dHbXnIdq7jQ=
google.golang.org/grpc v1.70.0/go.mod h1:ofIJqVKDXx/JiXrwr2IG4/zwdH9txy3IlF40RmcJSQw=
google.golang.org/protobuf v1.36.4 h1:6A3ZDJHn/eNqc1i+IdefRzy/9PokBTPvcqMySR7NNIM=
Expand Down
87 changes: 68 additions & 19 deletions szabstractfactory/szabstractfactory_examples_test.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
//go:build linux

package szabstractfactory
package szabstractfactory_test

import (
"context"
"fmt"
"path/filepath"

"github.com/senzing-garage/go-helpers/settings"
"github.com/senzing-garage/sz-sdk-go-core/szabstractfactory"
"github.com/senzing-garage/sz-sdk-go/senzing"
)

const (
instanceName = "SzAbstractFactory Test"
verboseLogging = senzing.SzNoLogging
)

// ----------------------------------------------------------------------------
// Interface methods - Examples for godoc documentation
// ----------------------------------------------------------------------------

func ExampleSzabstractfactory_CreateConfig() {
// For more information, visit https://github.com/senzing-garage/sz-sdk-go-core/blob/main/szabstractfactory/szabstractfactory_examples_test.go
ctx := context.TODO()
szAbstractFactory := getSzAbstractFactoryExample(ctx)
szAbstractFactory := getSzAbstractFactory(ctx)
defer func() { handleError(szAbstractFactory.Destroy(ctx)) }()
szConfig, err := szAbstractFactory.CreateConfig(ctx)
if err != nil {
fmt.Println(err)
handleError(err)
}
_ = szConfig // szConfig can now be used.
// Output:
Expand All @@ -29,11 +37,11 @@ func ExampleSzabstractfactory_CreateConfig() {
func ExampleSzabstractfactory_CreateConfigManager() {
// For more information, visit https://github.com/senzing-garage/sz-sdk-go-core/blob/main/szabstractfactory/szabstractfactory_examples_test.go
ctx := context.TODO()
szAbstractFactory := getSzAbstractFactoryExample(ctx)
szAbstractFactory := getSzAbstractFactory(ctx)
defer func() { handleError(szAbstractFactory.Destroy(ctx)) }()
szConfigManager, err := szAbstractFactory.CreateConfigManager(ctx)
if err != nil {
fmt.Println(err)
handleError(err)
}
_ = szConfigManager // szConfigManager can now be used.
// Output:
Expand All @@ -42,11 +50,11 @@ func ExampleSzabstractfactory_CreateConfigManager() {
func ExampleSzabstractfactory_CreateDiagnostic() {
// For more information, visit https://github.com/senzing-garage/sz-sdk-go-core/blob/main/szabstractfactory/szabstractfactory_examples_test.go
ctx := context.TODO()
szAbstractFactory := getSzAbstractFactoryExample(ctx)
szAbstractFactory := getSzAbstractFactory(ctx)
defer func() { handleError(szAbstractFactory.Destroy(ctx)) }()
szDiagnostic, err := szAbstractFactory.CreateDiagnostic(ctx)
if err != nil {
fmt.Println(err)
handleError(err)
}
_ = szDiagnostic // szDiagnostic can now be used.
// Output:
Expand All @@ -55,11 +63,11 @@ func ExampleSzabstractfactory_CreateDiagnostic() {
func ExampleSzabstractfactory_CreateEngine() {
// For more information, visit https://github.com/senzing-garage/sz-sdk-go-core/blob/main/szabstractfactory/szabstractfactory_examples_test.go
ctx := context.TODO()
szAbstractFactory := getSzAbstractFactoryExample(ctx)
szAbstractFactory := getSzAbstractFactory(ctx)
defer func() { handleError(szAbstractFactory.Destroy(ctx)) }()
szEngine, err := szAbstractFactory.CreateEngine(ctx)
if err != nil {
fmt.Println(err)
handleError(err)
}
_ = szEngine // szEngine can now be used.
// Output:
Expand All @@ -68,11 +76,11 @@ func ExampleSzabstractfactory_CreateEngine() {
func ExampleSzabstractfactory_CreateProduct() {
// For more information, visit https://github.com/senzing-garage/sz-sdk-go-core/blob/main/szabstractfactory/szabstractfactory_examples_test.go
ctx := context.TODO()
szAbstractFactory := getSzAbstractFactoryExample(ctx)
szAbstractFactory := getSzAbstractFactory(ctx)
defer func() { handleError(szAbstractFactory.Destroy(ctx)) }()
szProduct, err := szAbstractFactory.CreateProduct(ctx)
if err != nil {
fmt.Println(err)
handleError(err)
}
_ = szProduct // szProduct can now be used.
// Output:
Expand All @@ -81,30 +89,30 @@ func ExampleSzabstractfactory_CreateProduct() {
func ExampleSzabstractfactory_Destroy() {
// For more information, visit https://github.com/senzing-garage/sz-sdk-go-core/blob/main/szabstractfactory/szabstractfactory_examples_test.go
ctx := context.TODO()
szAbstractFactory := getSzAbstractFactoryExample(ctx)
szAbstractFactory := getSzAbstractFactory(ctx)
err := szAbstractFactory.Destroy(ctx)
if err != nil {
fmt.Println(err)
handleError(err)
}
// Output:
}

func ExampleSzabstractfactory_Reinitialize() {
// For more information, visit https://github.com/senzing-garage/sz-sdk-go-core/blob/main/szabstractfactory/szabstractfactory_examples_test.go
ctx := context.TODO()
szAbstractFactory := getSzAbstractFactoryExample(ctx)
szAbstractFactory := getSzAbstractFactory(ctx)
defer func() { handleError(szAbstractFactory.Destroy(ctx)) }()
szConfigManager, err := szAbstractFactory.CreateConfigManager(ctx)
if err != nil {
fmt.Println(err)
handleError(err)
}
configID, err := szConfigManager.GetDefaultConfigID(ctx)
if err != nil {
fmt.Println(err)
handleError(err)
}
err = szAbstractFactory.Reinitialize(ctx, configID)
if err != nil {
fmt.Println(err)
handleError(err)
}
// Output:
}
Expand All @@ -113,10 +121,51 @@ func ExampleSzabstractfactory_Reinitialize() {
// Helper functions
// ----------------------------------------------------------------------------

func getSzAbstractFactoryExample(ctx context.Context) senzing.SzAbstractFactory {
result, err := getSzAbstractFactory(ctx)
func getSettings() (string, error) {
var result string

// Determine Database URL.

testDirectoryPath := getTestDirectoryPath()
dbTargetPath, err := filepath.Abs(filepath.Join(testDirectoryPath, "G2C.db"))
if err != nil {
return result, fmt.Errorf("failed to make target database path (%s) absolute. Error: %w", dbTargetPath, err)
}
databaseURL := fmt.Sprintf("sqlite3://na:na@nowhere/%s", dbTargetPath)

// Create Senzing engine configuration JSON.

configAttrMap := map[string]string{"databaseUrl": databaseURL}
result, err = settings.BuildSimpleSettingsUsingMap(configAttrMap)
if err != nil {
return result, fmt.Errorf("failed to BuildSimpleSettingsUsingMap(%s) Error: %w", configAttrMap, err)
}
return result, err
}

func getSzAbstractFactory(ctx context.Context) senzing.SzAbstractFactory {
var err error
var result senzing.SzAbstractFactory
_ = ctx
settings, err := getSettings()
if err != nil {
panic(err)
}
result = &szabstractfactory.Szabstractfactory{
ConfigID: senzing.SzInitializeWithDefaultConfiguration,
InstanceName: instanceName,
Settings: settings,
VerboseLogging: verboseLogging,
}
return result
}

func getTestDirectoryPath() string {
return filepath.FromSlash("../target/test/szconfig")
}

func handleError(err error) {
if err != nil {
fmt.Println("Error:", err)
}
}
Loading

0 comments on commit 7d5937d

Please sign in to comment.