Skip to content

Commit

Permalink
#3 Savepoint
Browse files Browse the repository at this point in the history
  • Loading branch information
docktermj committed Aug 21, 2023
1 parent e3b1475 commit 3b07a11
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 18 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ print-make-variables:

.PHONY: setup
setup:
@echo "No setup required."
@rm -rf /tmp/sqlite
@mkdir /tmp/sqlite
@cp testdata/sqlite/G2C.db /tmp/sqlite/G2C.db


.PHONY: update-pkg-cache
Expand Down
48 changes: 48 additions & 0 deletions checkself/checkengineconfigurationjson.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package checkself

import (
"context"
"fmt"
"os"

"github.com/senzing/go-cmdhelping/option"
"github.com/senzing/go-common/engineconfigurationjsonparser"
)

func (checkself *CheckSelfImpl) CheckEngineConfigurationJson(ctx context.Context, reportChecks []string, reportErrors []string) ([]string, []string, error) {
var err error = nil

// Short-circuit exit.

if len(checkself.EngineConfigurationJson) == 0 {
return reportChecks, reportErrors, err
}

// Check Config path.

reportChecks = append(reportChecks, fmt.Sprintf("%s=%s", option.EngineConfigurationJson.Envar, checkself.EngineConfigurationJson))

parsedEngineConfigurationJson := &engineconfigurationjsonparser.EngineConfigurationJsonParserImpl{
EngineConfigurationJson: checkself.EngineConfigurationJson,
}

// Test ConfigPath

configPath, err := parsedEngineConfigurationJson.GetConfigPath(ctx)
if err != nil {
return reportChecks, reportErrors, err
}

requiredFiles := []string{
"cfgVariant.json",
"defaultGNRCP.config",
}
for _, requiredFile := range requiredFiles {
targetFile := fmt.Sprintf("%s/%s", configPath, requiredFile)
if _, err := os.Stat(targetFile); err != nil {
reportErrors = append(reportErrors, fmt.Sprintf("%s=%s is misconfigured. Could not find %s. For more information, visit https://hub.senzing.com/...", option.ConfigPath.Envar, checkself.ConfigPath, targetFile))
}
}

return reportChecks, reportErrors, err
}
54 changes: 38 additions & 16 deletions checkself/checkself.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,49 @@ func (checkself *CheckSelfImpl) CheckSelf(ctx context.Context) error {
reportChecks := []string{}
reportErrors := []string{}

// Perform tests.

reportChecks, reportErrors, err = checkself.CheckConfigPath(ctx, reportChecks, reportErrors)
if err != nil {
return err
// List tests.

testFunctions := []func(ctx context.Context, reportChecks []string, reportErrors []string) ([]string, []string, error){
checkself.CheckConfigPath,
checkself.CheckResourcePath,
checkself.CheckSupportPath,
checkself.CheckDatabaseUrl,
checkself.CheckEngineConfigurationJson,
}

reportChecks, reportErrors, err = checkself.CheckResourcePath(ctx, reportChecks, reportErrors)
if err != nil {
return err
}
// Perform tests.

reportChecks, reportErrors, err = checkself.CheckSupportPath(ctx, reportChecks, reportErrors)
if err != nil {
return err
for _, testFunction := range testFunctions {
reportChecks, reportErrors, err = testFunction(ctx, reportChecks, reportErrors)
if err != nil {
return err
}
}

reportChecks, reportErrors, err = checkself.CheckDatabaseUrl(ctx, reportChecks, reportErrors)
if err != nil {
return err
}
// reportChecks, reportErrors, err = checkself.CheckConfigPath(ctx, reportChecks, reportErrors)
// if err != nil {
// return err
// }

// reportChecks, reportErrors, err = checkself.CheckResourcePath(ctx, reportChecks, reportErrors)
// if err != nil {
// return err
// }

// reportChecks, reportErrors, err = checkself.CheckSupportPath(ctx, reportChecks, reportErrors)
// if err != nil {
// return err
// }

// reportChecks, reportErrors, err = checkself.CheckDatabaseUrl(ctx, reportChecks, reportErrors)
// if err != nil {
// return err
// }

// reportChecks, reportErrors, err = checkself.CheckEngineConfigurationJson(ctx, reportChecks, reportErrors)
// if err != nil {
// return err
// }

// Output reports.

Expand Down
26 changes: 25 additions & 1 deletion checkself/checkself_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"testing"

"github.com/senzing/go-common/g2engineconfigurationjson"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -41,13 +42,36 @@ func teardown() error {
// Test interface functions
// ----------------------------------------------------------------------------

func TestCheckSelfImpl_CheckSelf(test *testing.T) {
func TestCheckSelfImpl_CheckSelf_Null(test *testing.T) {
ctx := context.TODO()
testObject := &CheckSelfImpl{}
err := testObject.CheckSelf(ctx)
assert.Nil(test, err)
}

func TestCheckSelfImpl_CheckSelf_Paths(test *testing.T) {
ctx := context.TODO()
testObject := &CheckSelfImpl{
ConfigPath: "/etc/opt/senzing",
DatabaseUrl: "sqlite3://na:na@/tmp/sqlite/G2C.db",
ResourcePath: "/opt/senzing/g2/resources",
SupportPath: "/opt/senzing/data",
}
err := testObject.CheckSelf(ctx)
assert.Nil(test, err)
}

func TestCheckSelfImpl_CheckSelf_EngineConfigurationJson(test *testing.T) {
ctx := context.TODO()
engineConfigurationJson, err := g2engineconfigurationjson.BuildSimpleSystemConfigurationJsonUsingEnvVars()
assert.Nil(test, err)
testObject := &CheckSelfImpl{
EngineConfigurationJson: engineConfigurationJson,
}
err = testObject.CheckSelf(ctx)
assert.Nil(test, err)
}

// ----------------------------------------------------------------------------
// Examples for godoc documentation
// ----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ toolchain go1.21.0

require (
github.com/senzing/go-cmdhelping v0.1.7
github.com/senzing/go-common v0.2.13
github.com/senzing/go-databasing v0.2.7
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.16.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/senzing/go-cmdhelping v0.1.7 h1:+/yVeCbevrkpfHbn3XmcbZ7rDqf1cwWTqMv0HJD6IIw=
github.com/senzing/go-cmdhelping v0.1.7/go.mod h1:kgOPFyV2bjvNlGEqvq3gzZAZHp0RVuGfm2maftgJ0Pw=
github.com/senzing/go-common v0.2.13 h1:dvKmO2by+wA8kK9gcpQRp/9r6zyAyT0idcm6OOf08iU=
github.com/senzing/go-common v0.2.13/go.mod h1:Dqvq3hZc8KNT7SJKkjJhJ5ZZYbsmZEDIMFT6eFZ+Kt0=
github.com/senzing/go-databasing v0.2.7 h1:G9wFURcI4G0cRpzDfdK5K6K3PETNsqB/bS7s2zzL2ZQ=
github.com/senzing/go-databasing v0.2.7/go.mod h1:/IES+UzM6EZTzyLbNGgtr7afUP5LV+Bqmzj7EIQrebA=
github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM=
Expand Down

0 comments on commit 3b07a11

Please sign in to comment.