From 6a116c6f3725c73573cf627552d91b7839f89efd Mon Sep 17 00:00:00 2001 From: Michael Dockter Date: Tue, 28 Mar 2023 13:51:17 -0400 Subject: [PATCH] Issue 55.dockter.1 (#61) * #55 Update dependencies * #55 Update test cases * #55 Update test cases * #55 Improve documentation * #55 Improve documentation * #55 Improve documentation * #55 Improve documentation * #55 Update dependencies * #55 change initdatabase to servegrpc * #55 Update dependencies * #55 Update dependencies * #55 Update dependencies * #55 Update dependencies * #55 Update dependencies * #55 Add go-test.yaml * #55 Add go-test.yaml * #55 Prepare for versioned release --- .github/workflows/go-test.yaml | 49 +++++++++++++++ CHANGELOG.md | 9 +++ Makefile | 9 ++- cmd/root.go | 2 +- doc.go | 8 +-- docs/development.md | 47 +++++++++++++-- g2configmgrserver/g2configmgrserver_test.go | 52 ++++++++++------ g2diagnosticserver/g2diagnosticserver_test.go | 59 ++++++++++++------- g2engineserver/g2engineserver.go | 22 +++---- g2engineserver/g2engineserver_test.go | 51 ++++++++++------ go.mod | 2 +- go.sum | 4 +- 12 files changed, 229 insertions(+), 85 deletions(-) create mode 100644 .github/workflows/go-test.yaml diff --git a/.github/workflows/go-test.yaml b/.github/workflows/go-test.yaml new file mode 100644 index 0000000..17ccba9 --- /dev/null +++ b/.github/workflows/go-test.yaml @@ -0,0 +1,49 @@ +# Based on +# -https://github.com/marketplace/actions/setup-go-environment + +name: go-test.yaml + +on: [push] + +env: + LD_LIBRARY_PATH: /opt/senzing/g2/lib + SENZING_ACCEPT_EULA: I_ACCEPT_THE_SENZING_EULA + SENZING_TOOLS_DATABASE_URL: "sqlite3://na:na@/tmp/sqlite/G2C.db" + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + go: ["1.20"] + name: Go ${{ matrix.go }} sample + steps: + - uses: actions/checkout@v3 + - name: Setup go + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go }} + - run: pwd + - run: wget -qO /tmp/senzingrepo_1.0.1-1_amd64.deb https://senzing-production-apt.s3.amazonaws.com/senzingrepo_1.0.1-1_amd64.deb + - run: sudo apt-get -y install /tmp/senzingrepo_1.0.1-1_amd64.deb + - run: sudo apt-get update + - run: sudo --preserve-env apt-get -y install senzingapi + - run: sudo mv /opt/senzing/data/3.0.0/* /opt/senzing/data/ + - run: sudo mkdir /etc/opt/senzing + - run: sudo cp /opt/senzing/g2/resources/templates/cfgVariant.json /etc/opt/senzing + - run: sudo cp /opt/senzing/g2/resources/templates/customGn.txt /etc/opt/senzing + - run: sudo cp /opt/senzing/g2/resources/templates/customOn.txt /etc/opt/senzing + - run: sudo cp /opt/senzing/g2/resources/templates/customSn.txt /etc/opt/senzing + - run: sudo cp /opt/senzing/g2/resources/templates/defaultGNRCP.config /etc/opt/senzing + - run: sudo cp /opt/senzing/g2/resources/templates/stb.config /etc/opt/senzing + - run: sudo cp testdata/senzing-license/g2.lic /etc/opt/senzing + - run: mkdir /tmp/sqlite + - run: cp testdata/sqlite/G2C.db /tmp/sqlite/G2C.db + - run: go test -v -p 1 ./... + # - run: go test -v ./. + # - run: go test -v ./g2configserver + # - run: go test -v ./g2configmgrserver + # - run: go test -v ./g2diagnosticserver + # - run: go test -v ./g2engineserver + # - run: go test -v ./g2productserver + # - run: go test -v ./grpcserver diff --git a/CHANGELOG.md b/CHANGELOG.md index 2135dc9..fc05fe4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - +## [0.3.9] - 2023-03-27 + +### Added in 0.3.9 + +- Added Stream methods + - g2diagnosticserver.StreamEntityListBySize() + - g2engineserver.StreamExportCSVEntityReport() + - g2engineserver.StreamExportJSONEntityReport() +- Update dependencies ## [0.3.8] - 2023-03-14 diff --git a/Makefile b/Makefile index 5fbafe0..da22438 100644 --- a/Makefile +++ b/Makefile @@ -150,6 +150,12 @@ run-servegrpc-trace: build # Utility targets # ----------------------------------------------------------------------------- +.PHONY: new-sqlite +new-sqlite: + @rm -rf /tmp/sqlite + @mkdir /tmp/sqlite + @cp testdata/sqlite/G2C.db /tmp/sqlite/G2C.db + .PHONY: update-pkg-cache update-pkg-cache: @GOPROXY=https://proxy.golang.org GO111MODULE=on \ @@ -164,9 +170,6 @@ clean: @docker rmi --force $(DOCKER_IMAGE_NAME) $(DOCKER_BUILD_IMAGE_NAME) 2> /dev/null || true @rm -rf $(TARGET_DIRECTORY) || true @rm -f $(GOPATH)/bin/$(PROGRAM_NAME) || true - @rm -rf /tmp/sqlite - @mkdir /tmp/sqlite - @cp testdata/sqlite/G2C.db /tmp/sqlite/G2C.db .PHONY: print-make-variables diff --git a/cmd/root.go b/cmd/root.go index c6d9ca5..8d690b1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -37,7 +37,7 @@ const ( var ( buildIteration string = "0" buildVersion string = "0.3.7" - defaultEngineModuleName string = fmt.Sprintf("initdatabase-%d", time.Now().Unix()) + defaultEngineModuleName string = fmt.Sprintf("servegrpc-%d", time.Now().Unix()) ) // If a configuration file is present, load it. diff --git a/doc.go b/doc.go index 98865f1..72dd8cc 100644 --- a/doc.go +++ b/doc.go @@ -7,7 +7,7 @@ One or two paragraph overview of this module... (This page describes the nature of the entire Go module or the top-level command, not an individual package.) -More information at https://github.com/senzing/initdatabase +More information at https://github.com/senzing/servegrpc # Example Package @@ -16,7 +16,7 @@ documentation, tests, and examples should be done. This paragraph (or two) should provide a brief overview while linking the reader to the documentation included in the package itself. -More information can be found in the [pkg/github.com/senzing/initdatabase/examplepackage] documentation. +More information can be found in the [pkg/github.com/senzing/servegrpc/examplepackage] documentation. # Another Header: Package or other module features... @@ -33,8 +33,8 @@ Examples of use can be seen in the main_test.go files. import ( fmt - "github.com/senzing/initdatabase/examplepackage" - "github.com/senzing/initdatabase/anotherpackage" + "github.com/senzing/servegrpc/examplepackage" + "github.com/senzing/servegrpc/anotherpackage" ) func main() { diff --git a/docs/development.md b/docs/development.md index 524d029..1f086ff 100644 --- a/docs/development.md +++ b/docs/development.md @@ -50,22 +50,50 @@ Since the Senzing library is a prerequisite, it must be installed first. ``` -1. Clean up. +## Run + +After running `make build`, +the binary built can be run. + +1. Identify the database by setting the `SENZING_TOOLS_DATABASE_URL` environment variable. + + 1. :pencil2: Create a new Sqlite database. + Examples: + + ```console + export SENZING_TOOLS_DATABASE_URL=sqlite3://na:na@/tmp/sqlite/G2C.db + export LD_LIBRARY_PATH=/opt/senzing/g2/lib/ + senzing-tools initdatabase + + ``` + + 1. :pencil2: Identify an existing PostgreSQL database. + Example: + + ```console + export LOCAL_IP_ADDRESS=$(curl --silent https://raw.githubusercontent.com/Senzing/knowledge-base/main/gists/find-local-ip-address/find-local-ip-address.py | python3 -) + export SENZING_TOOLS_DATABASE_URL=postgresql://postgres:postgres@${LOCAL_IP_ADDRESS}:5432/G2/?sslmode=disable + + ``` + +1. Set `LD_LIBRARY_PATH` and run the command. Example: ```console - cd ${GIT_REPOSITORY_DIR} - make clean + export LD_LIBRARY_PATH=/opt/senzing/g2/lib/ + ${GIT_REPOSITORY_DIR}/target/linux/servegrpc ``` +## Test + ### Test using SQLite database 1. Run tests. ```console cd ${GIT_REPOSITORY_DIR} - make clean test + make clean new-sqlite test ``` @@ -342,4 +370,13 @@ The actual packaging is done in the [senzing-tools](https://github.com/Senzing/s ``` -### FIXME: remove +### Cleanup + +1. Clean up. + Example: + + ```console + cd ${GIT_REPOSITORY_DIR} + make clean + + ``` diff --git a/g2configmgrserver/g2configmgrserver_test.go b/g2configmgrserver/g2configmgrserver_test.go index 06e6e6b..c4b43e7 100644 --- a/g2configmgrserver/g2configmgrserver_test.go +++ b/g2configmgrserver/g2configmgrserver_test.go @@ -12,6 +12,7 @@ import ( "github.com/senzing/g2-sdk-go-base/g2config" "github.com/senzing/g2-sdk-go-base/g2configmgr" "github.com/senzing/g2-sdk-go-base/g2engine" + "github.com/senzing/g2-sdk-go/g2error" g2configpb "github.com/senzing/g2-sdk-proto/go/g2config" g2pb "github.com/senzing/g2-sdk-proto/go/g2configmgr" "github.com/senzing/go-common/g2engineconfigurationjson" @@ -35,6 +36,10 @@ var ( // Internal functions // ---------------------------------------------------------------------------- +func createError(errorId int, err error) error { + return g2error.Cast(localLogger.Error(errorId, err), err) +} + func getTestObject(ctx context.Context, test *testing.T) G2ConfigmgrServer { if g2configmgrServerSingleton == nil { g2configmgrServerSingleton = &G2ConfigmgrServer{} @@ -131,6 +136,15 @@ func testErrorNoFail(test *testing.T, ctx context.Context, g2configmgr G2Configm func TestMain(m *testing.M) { err := setup() if err != nil { + if g2error.Is(err, g2error.G2Unrecoverable) { + fmt.Printf("\nUnrecoverable error detected. \n\n") + } + if g2error.Is(err, g2error.G2Retryable) { + fmt.Printf("\nRetryable error detected. \n\n") + } + if g2error.Is(err, g2error.G2BadUserInput) { + fmt.Printf("\nBad user input error detected. \n\n") + } fmt.Print(err) os.Exit(1) } @@ -148,12 +162,12 @@ func setupSenzingConfig(ctx context.Context, moduleName string, iniParams string aG2config := &g2config.G2config{} err := aG2config.Init(ctx, moduleName, iniParams, verboseLogging) if err != nil { - return localLogger.Error(5906, err) + return createError(5906, err) } configHandle, err := aG2config.Create(ctx) if err != nil { - return localLogger.Error(5907, err) + return createError(5907, err) } datasourceNames := []string{"CUSTOMERS", "REFERENCE", "WATCHLIST"} @@ -161,23 +175,23 @@ func setupSenzingConfig(ctx context.Context, moduleName string, iniParams string datasource := truthset.TruthsetDataSources[datasourceName] _, err := aG2config.AddDataSource(ctx, configHandle, datasource.Json) if err != nil { - return localLogger.Error(5908, err) + return createError(5908, err) } } configStr, err := aG2config.Save(ctx, configHandle) if err != nil { - return localLogger.Error(5909, err) + return createError(5909, err) } err = aG2config.Close(ctx, configHandle) if err != nil { - return localLogger.Error(5910, err) + return createError(5910, err) } err = aG2config.Destroy(ctx) if err != nil { - return localLogger.Error(5911, err) + return createError(5911, err) } // Persist the Senzing configuration to the Senzing repository. @@ -185,23 +199,23 @@ func setupSenzingConfig(ctx context.Context, moduleName string, iniParams string aG2configmgr := &g2configmgr.G2configmgr{} err = aG2configmgr.Init(ctx, moduleName, iniParams, verboseLogging) if err != nil { - return localLogger.Error(5912, err) + return createError(5912, err) } configComments := fmt.Sprintf("Created by g2diagnostic_test at %s", now.UTC()) configID, err := aG2configmgr.AddConfig(ctx, configStr, configComments) if err != nil { - return localLogger.Error(5913, err) + return createError(5913, err) } err = aG2configmgr.SetDefaultConfigID(ctx, configID) if err != nil { - return localLogger.Error(5914, err) + return createError(5914, err) } err = aG2configmgr.Destroy(ctx) if err != nil { - return localLogger.Error(5915, err) + return createError(5915, err) } return err } @@ -210,49 +224,49 @@ func setupPurgeRepository(ctx context.Context, moduleName string, iniParams stri aG2engine := &g2engine.G2engine{} err := aG2engine.Init(ctx, moduleName, iniParams, verboseLogging) if err != nil { - return localLogger.Error(5903, err) + return createError(5903, err) } err = aG2engine.PurgeRepository(ctx) if err != nil { - return localLogger.Error(5904, err) + return createError(5904, err) } err = aG2engine.Destroy(ctx) if err != nil { - return localLogger.Error(5905, err) + return createError(5905, err) } return err } func setup() error { + var err error = nil ctx := context.TODO() moduleName := "Test module name" verboseLogging := 0 - localLogger, err := messagelogger.NewSenzingApiLogger(ProductId, IdMessages, IdStatuses, messagelogger.LevelInfo) + localLogger, err = messagelogger.NewSenzingApiLogger(ProductId, IdMessages, IdStatuses, messagelogger.LevelInfo) if err != nil { - return localLogger.Error(5901, err) + return createError(5901, err) } iniParams, err := g2engineconfigurationjson.BuildSimpleSystemConfigurationJson("") if err != nil { - return localLogger.Error(5902, err) + return createError(5902, err) } // Add Data Sources to Senzing configuration. err = setupSenzingConfig(ctx, moduleName, iniParams, verboseLogging) if err != nil { - return localLogger.Error(5920, err) + return createError(5920, err) } // Purge repository. err = setupPurgeRepository(ctx, moduleName, iniParams, verboseLogging) if err != nil { - return localLogger.Error(5921, err) + return createError(5921, err) } - return err } diff --git a/g2diagnosticserver/g2diagnosticserver_test.go b/g2diagnosticserver/g2diagnosticserver_test.go index 364bd0d..5246966 100644 --- a/g2diagnosticserver/g2diagnosticserver_test.go +++ b/g2diagnosticserver/g2diagnosticserver_test.go @@ -12,6 +12,7 @@ import ( "github.com/senzing/g2-sdk-go-base/g2config" "github.com/senzing/g2-sdk-go-base/g2configmgr" "github.com/senzing/g2-sdk-go-base/g2engine" + "github.com/senzing/g2-sdk-go/g2error" g2configmgrpb "github.com/senzing/g2-sdk-proto/go/g2configmgr" g2pb "github.com/senzing/g2-sdk-proto/go/g2diagnostic" "github.com/senzing/go-common/g2engineconfigurationjson" @@ -36,6 +37,10 @@ var ( // Internal functions // ---------------------------------------------------------------------------- +func createError(errorId int, err error) error { + return g2error.Cast(localLogger.Error(errorId, err), err) +} + func getTestObject(ctx context.Context, test *testing.T) G2DiagnosticServer { if g2diagnosticTestSingleton == nil { g2diagnosticTestSingleton = &G2DiagnosticServer{} @@ -134,6 +139,15 @@ func testErrorNoFail(test *testing.T, ctx context.Context, g2diagnostic G2Diagno func TestMain(m *testing.M) { err := setup() if err != nil { + if g2error.Is(err, g2error.G2Unrecoverable) { + fmt.Printf("\nUnrecoverable error detected. \n\n") + } + if g2error.Is(err, g2error.G2Retryable) { + fmt.Printf("\nRetryable error detected. \n\n") + } + if g2error.Is(err, g2error.G2BadUserInput) { + fmt.Printf("\nBad user input error detected. \n\n") + } fmt.Print(err) os.Exit(1) } @@ -151,12 +165,12 @@ func setupSenzingConfig(ctx context.Context, moduleName string, iniParams string aG2config := &g2config.G2config{} err := aG2config.Init(ctx, moduleName, iniParams, verboseLogging) if err != nil { - return localLogger.Error(5906, err) + return createError(5906, err) } configHandle, err := aG2config.Create(ctx) if err != nil { - return localLogger.Error(5907, err) + return createError(5907, err) } datasourceNames := []string{"CUSTOMERS", "REFERENCE", "WATCHLIST"} @@ -164,23 +178,23 @@ func setupSenzingConfig(ctx context.Context, moduleName string, iniParams string datasource := truthset.TruthsetDataSources[datasourceName] _, err := aG2config.AddDataSource(ctx, configHandle, datasource.Json) if err != nil { - return localLogger.Error(5908, err) + return createError(5908, err) } } configStr, err := aG2config.Save(ctx, configHandle) if err != nil { - return localLogger.Error(5909, err) + return createError(5909, err) } err = aG2config.Close(ctx, configHandle) if err != nil { - return localLogger.Error(5910, err) + return createError(5910, err) } err = aG2config.Destroy(ctx) if err != nil { - return localLogger.Error(5911, err) + return createError(5911, err) } // Persist the Senzing configuration to the Senzing repository. @@ -188,23 +202,23 @@ func setupSenzingConfig(ctx context.Context, moduleName string, iniParams string aG2configmgr := &g2configmgr.G2configmgr{} err = aG2configmgr.Init(ctx, moduleName, iniParams, verboseLogging) if err != nil { - return localLogger.Error(5912, err) + return createError(5912, err) } configComments := fmt.Sprintf("Created by g2diagnostic_test at %s", now.UTC()) configID, err := aG2configmgr.AddConfig(ctx, configStr, configComments) if err != nil { - return localLogger.Error(5913, err) + return createError(5913, err) } err = aG2configmgr.SetDefaultConfigID(ctx, configID) if err != nil { - return localLogger.Error(5914, err) + return createError(5914, err) } err = aG2configmgr.Destroy(ctx) if err != nil { - return localLogger.Error(5915, err) + return createError(5915, err) } return err } @@ -214,7 +228,7 @@ func setupAddRecords(ctx context.Context, moduleName string, iniParams string, v aG2engine := &g2engine.G2engine{} err := aG2engine.Init(ctx, moduleName, iniParams, verboseLogging) if err != nil { - return localLogger.Error(5916, err) + return createError(5916, err) } testRecordIds := []string{"1001", "1002", "1003", "1004", "1005", "1039", "1040"} @@ -222,13 +236,13 @@ func setupAddRecords(ctx context.Context, moduleName string, iniParams string, v testRecord := truthset.CustomerRecords[testRecordId] err := aG2engine.AddRecord(ctx, testRecord.DataSource, testRecord.Id, testRecord.Json, "G2Diagnostic_test") if err != nil { - return localLogger.Error(5917, err) + return createError(5917, err) } } err = aG2engine.Destroy(ctx) if err != nil { - return localLogger.Error(5918, err) + return createError(5918, err) } return err } @@ -237,54 +251,55 @@ func setupPurgeRepository(ctx context.Context, moduleName string, iniParams stri aG2engine := &g2engine.G2engine{} err := aG2engine.Init(ctx, moduleName, iniParams, verboseLogging) if err != nil { - return localLogger.Error(5903, err) + return createError(5903, err) } err = aG2engine.PurgeRepository(ctx) if err != nil { - return localLogger.Error(5904, err) + return createError(5904, err) } err = aG2engine.Destroy(ctx) if err != nil { - return localLogger.Error(5905, err) + return createError(5905, err) } return err } func setup() error { + var err error = nil ctx := context.TODO() moduleName := "Test module name" verboseLogging := 0 - localLogger, err := messagelogger.NewSenzingApiLogger(ProductId, IdMessages, IdStatuses, messagelogger.LevelInfo) + localLogger, err = messagelogger.NewSenzingApiLogger(ProductId, IdMessages, IdStatuses, messagelogger.LevelInfo) if err != nil { - return localLogger.Error(5901, err) + return createError(5901, err) } iniParams, err := g2engineconfigurationjson.BuildSimpleSystemConfigurationJson("") if err != nil { - return localLogger.Error(5902, err) + return createError(5902, err) } // Add Data Sources to Senzing configuration. err = setupSenzingConfig(ctx, moduleName, iniParams, verboseLogging) if err != nil { - return localLogger.Error(5920, err) + return createError(5920, err) } // Purge repository. err = setupPurgeRepository(ctx, moduleName, iniParams, verboseLogging) if err != nil { - return localLogger.Error(5921, err) + return createError(5921, err) } // Add records. err = setupAddRecords(ctx, moduleName, iniParams, verboseLogging) if err != nil { - return localLogger.Error(5922, err) + return createError(5922, err) } return err diff --git a/g2engineserver/g2engineserver.go b/g2engineserver/g2engineserver.go index 19a2297..bb2af83 100644 --- a/g2engineserver/g2engineserver.go +++ b/g2engineserver/g2engineserver.go @@ -1128,26 +1128,27 @@ func (server *G2EngineServer) StreamExportCSVEntityReport(request *g2pb.StreamEx ctx := stream.Context() entryTime := time.Now() g2engine := getG2engine() - rowsFetched := 0 - //get the query handle + // Get the query handle. + var queryHandle uintptr queryHandle, err = g2engine.ExportCSVEntityReport(ctx, request.GetCsvColumnList(), request.GetFlags()) if err != nil { return err } - //defer the CloseExport in case we exit early for any reason + // Defer the CloseExport in case we exit early for any reason. + defer func() { err = g2engine.CloseExport(ctx, queryHandle) if server.isTrace { server.traceExit(159, request, rowsFetched, err, time.Since(entryTime)) } - return }() - //stream the results + // Stream the results. + for { var fetchResult string fetchResult, err = g2engine.FetchNext(ctx, queryHandle) @@ -1178,26 +1179,27 @@ func (server *G2EngineServer) StreamExportJSONEntityReport(request *g2pb.StreamE ctx := stream.Context() entryTime := time.Now() g2engine := getG2engine() - rowsFetched := 0 - //get the query handle + // Get the query handle. + var queryHandle uintptr queryHandle, err = g2engine.ExportJSONEntityReport(ctx, request.GetFlags()) if err != nil { return err } - //defer the CloseExport in case we exit early for any reason + // Defer the CloseExport in case we exit early for any reason. + defer func() { err = g2engine.CloseExport(ctx, queryHandle) if server.isTrace { server.traceExit(162, request, rowsFetched, err, time.Since(entryTime)) } - return }() - //stream the results + // Stream the results. + for { var fetchResult string fetchResult, err = g2engine.FetchNext(ctx, queryHandle) diff --git a/g2engineserver/g2engineserver_test.go b/g2engineserver/g2engineserver_test.go index fa63cce..854f5ec 100644 --- a/g2engineserver/g2engineserver_test.go +++ b/g2engineserver/g2engineserver_test.go @@ -13,6 +13,7 @@ import ( "github.com/senzing/g2-sdk-go-base/g2config" "github.com/senzing/g2-sdk-go-base/g2configmgr" "github.com/senzing/g2-sdk-go-base/g2engine" + "github.com/senzing/g2-sdk-go/g2error" g2pb "github.com/senzing/g2-sdk-proto/go/g2engine" "github.com/senzing/go-common/g2engineconfigurationjson" "github.com/senzing/go-common/record" @@ -42,6 +43,10 @@ var ( // Internal functions // ---------------------------------------------------------------------------- +func createError(errorId int, err error) error { + return g2error.Cast(localLogger.Error(errorId, err), err) +} + func getTestObject(ctx context.Context, test *testing.T) G2EngineServer { if g2engineTestSingleton == nil { g2engineTestSingleton = &G2EngineServer{} @@ -158,6 +163,15 @@ func testErrorNoFail(test *testing.T, ctx context.Context, g2engine G2EngineServ func TestMain(m *testing.M) { err := setup() if err != nil { + if g2error.Is(err, g2error.G2Unrecoverable) { + fmt.Printf("\nUnrecoverable error detected. \n\n") + } + if g2error.Is(err, g2error.G2Retryable) { + fmt.Printf("\nRetryable error detected. \n\n") + } + if g2error.Is(err, g2error.G2BadUserInput) { + fmt.Printf("\nBad user input error detected. \n\n") + } fmt.Print(err) os.Exit(1) } @@ -175,12 +189,12 @@ func setupSenzingConfig(ctx context.Context, moduleName string, iniParams string aG2config := &g2config.G2config{} err := aG2config.Init(ctx, moduleName, iniParams, verboseLogging) if err != nil { - return localLogger.Error(5906, err) + return createError(5906, err) } configHandle, err := aG2config.Create(ctx) if err != nil { - return localLogger.Error(5907, err) + return createError(5907, err) } datasourceNames := []string{"CUSTOMERS", "REFERENCE", "WATCHLIST"} @@ -188,23 +202,23 @@ func setupSenzingConfig(ctx context.Context, moduleName string, iniParams string datasource := truthset.TruthsetDataSources[datasourceName] _, err := aG2config.AddDataSource(ctx, configHandle, datasource.Json) if err != nil { - return localLogger.Error(5908, err) + return createError(5908, err) } } configStr, err := aG2config.Save(ctx, configHandle) if err != nil { - return localLogger.Error(5909, err) + return createError(5909, err) } err = aG2config.Close(ctx, configHandle) if err != nil { - return localLogger.Error(5910, err) + return createError(5910, err) } err = aG2config.Destroy(ctx) if err != nil { - return localLogger.Error(5911, err) + return createError(5911, err) } // Persist the Senzing configuration to the Senzing repository. @@ -212,23 +226,23 @@ func setupSenzingConfig(ctx context.Context, moduleName string, iniParams string aG2configmgr := &g2configmgr.G2configmgr{} err = aG2configmgr.Init(ctx, moduleName, iniParams, verboseLogging) if err != nil { - return localLogger.Error(5912, err) + return createError(5912, err) } configComments := fmt.Sprintf("Created by g2diagnostic_test at %s", now.UTC()) configID, err := aG2configmgr.AddConfig(ctx, configStr, configComments) if err != nil { - return localLogger.Error(5913, err) + return createError(5913, err) } err = aG2configmgr.SetDefaultConfigID(ctx, configID) if err != nil { - return localLogger.Error(5914, err) + return createError(5914, err) } err = aG2configmgr.Destroy(ctx) if err != nil { - return localLogger.Error(5915, err) + return createError(5915, err) } return err } @@ -237,47 +251,48 @@ func setupPurgeRepository(ctx context.Context, moduleName string, iniParams stri aG2engine := &g2engine.G2engine{} err := aG2engine.Init(ctx, moduleName, iniParams, verboseLogging) if err != nil { - return localLogger.Error(5903, err) + return createError(5903, err) } err = aG2engine.PurgeRepository(ctx) if err != nil { - return localLogger.Error(5904, err) + return createError(5904, err) } err = aG2engine.Destroy(ctx) if err != nil { - return localLogger.Error(5905, err) + return createError(5905, err) } return err } func setup() error { + var err error = nil ctx := context.TODO() moduleName := "Test module name" verboseLogging := 0 - localLogger, err := messagelogger.NewSenzingApiLogger(ProductId, IdMessages, IdStatuses, messagelogger.LevelInfo) + localLogger, err = messagelogger.NewSenzingApiLogger(ProductId, IdMessages, IdStatuses, messagelogger.LevelInfo) if err != nil { - return localLogger.Error(5901, err) + return createError(5901, err) } iniParams, err := g2engineconfigurationjson.BuildSimpleSystemConfigurationJson("") if err != nil { - return localLogger.Error(5902, err) + return createError(5902, err) } // Add Data Sources to Senzing configuration. err = setupSenzingConfig(ctx, moduleName, iniParams, verboseLogging) if err != nil { - return localLogger.Error(5920, err) + return createError(5920, err) } // Purge repository. err = setupPurgeRepository(ctx, moduleName, iniParams, verboseLogging) if err != nil { - return localLogger.Error(5921, err) + return createError(5921, err) } return err } diff --git a/go.mod b/go.mod index 0d8dfad..1102e4f 100644 --- a/go.mod +++ b/go.mod @@ -37,7 +37,7 @@ require ( golang.org/x/net v0.8.0 // indirect golang.org/x/sys v0.6.0 // indirect golang.org/x/text v0.8.0 // indirect - google.golang.org/genproto v0.0.0-20230322174352-cde4c949918d // indirect + google.golang.org/genproto v0.0.0-20230327215041-6ac7f18bb9d5 // indirect google.golang.org/protobuf v1.30.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 6c2949d..640dfcc 100644 --- a/go.sum +++ b/go.sum @@ -465,8 +465,8 @@ google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20230322174352-cde4c949918d h1:OE8TncEeAei3Tehf/P/Jdt/K+8GnTUrRY6wzYpbCes4= -google.golang.org/genproto v0.0.0-20230322174352-cde4c949918d/go.mod h1:NWraEVixdDnqcqQ30jipen1STv2r/n24Wb7twVTGR4s= +google.golang.org/genproto v0.0.0-20230327215041-6ac7f18bb9d5 h1:Kd6tRRHXw8z4TlPlWi+NaK10gsePL6GdZBQChptOLGA= +google.golang.org/genproto v0.0.0-20230327215041-6ac7f18bb9d5/go.mod h1:UUQDJDOlWu4KYeJZffbWgBkS1YFobzKbLVfK69pe0Ak= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=