From ab9227f86cd0c0fcba684252e0d36d27978d7168 Mon Sep 17 00:00:00 2001 From: docktermj Date: Mon, 28 Apr 2025 15:03:55 -0400 Subject: [PATCH 1/4] #137 Sync with template-go --- .github/linters/.golangci.yaml | 26 ++ .github/workflows/go-proxy-pull.yaml | 2 +- .github/workflows/go-test-darwin.yaml | 2 +- .github/workflows/go-test-linux.yaml | 2 +- .github/workflows/go-test-windows.yaml | 2 +- .github/workflows/golangci-lint.yaml | 5 +- .github/workflows/govulncheck.yaml | 32 +++ .github/workflows/spellcheck.yaml | 19 ++ .gitignore | 3 +- .vscode/cspell.json | 75 ++++++ Makefile | 325 ++++++++++++++++++++++++- cmd/cmd_test.go | 51 ++-- cmd/completion.go | 14 +- cmd/docs.go | 23 +- cmd/root.go | 6 +- makefiles/darwin.mk | 2 +- makefiles/linux.mk | 2 +- rootfs/app/healthcheck.sh | 2 +- 18 files changed, 534 insertions(+), 59 deletions(-) create mode 100644 .github/workflows/govulncheck.yaml create mode 100644 .github/workflows/spellcheck.yaml create mode 100644 .vscode/cspell.json diff --git a/.github/linters/.golangci.yaml b/.github/linters/.golangci.yaml index da69761..b97858c 100644 --- a/.github/linters/.golangci.yaml +++ b/.github/linters/.golangci.yaml @@ -29,6 +29,7 @@ linters: - fatcontext # - forbidigo - forcetypeassert + - funcorder - funlen - ginkgolinter - gocheckcompilerdirectives @@ -106,6 +107,9 @@ linters: # - wrapcheck # - wsl - zerologlint + disable: + - gochecknoglobals + - gochecknoinits exclusions: generated: lax presets: @@ -117,6 +121,25 @@ linters: - third_party$ - builtin$ - examples$ + settings: + depguard: + rules: + prevent_unmaintained_packages: + list-mode: lax # allow unless explicitely denied + allow: + - github.com/stretchr/testify/* + deny: + - pkg: io/ioutil + desc: "replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil" + exhaustruct: + exclude: + - '.+/cobra\.Command$' + ireturn: + allow: + - anon + - empty + - error + - stdlib formatters: enable: @@ -131,3 +154,6 @@ formatters: - third_party$ - builtin$ - examples$ + settings: + golines: + max-len: 120 diff --git a/.github/workflows/go-proxy-pull.yaml b/.github/workflows/go-proxy-pull.yaml index a4ea2b1..d28ef32 100644 --- a/.github/workflows/go-proxy-pull.yaml +++ b/.github/workflows/go-proxy-pull.yaml @@ -22,7 +22,7 @@ jobs: slack-notification: needs: [go-proxy-pull] - if: ${{ always() && contains(fromJSON('["failure", "cancelled"]'), needs.go-proxy-pull.outputs.status ) }} + if: ${{ always() && contains(fromJSON('["failure", "cancelled"]'), needs.go-proxy-pull.outputs.status) }} secrets: SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} uses: senzing-factory/build-resources/.github/workflows/build-failure-slack-notification.yaml@v2 diff --git a/.github/workflows/go-test-darwin.yaml b/.github/workflows/go-test-darwin.yaml index 2687149..0edff0c 100644 --- a/.github/workflows/go-test-darwin.yaml +++ b/.github/workflows/go-test-darwin.yaml @@ -21,7 +21,7 @@ jobs: with: fetch-depth: 0 - - name: Setup go + - name: Setup go ${{ matrix.go }} uses: actions/setup-go@v5 with: go-version: ${{ matrix.go }} diff --git a/.github/workflows/go-test-linux.yaml b/.github/workflows/go-test-linux.yaml index f9b1314..2ee90fd 100644 --- a/.github/workflows/go-test-linux.yaml +++ b/.github/workflows/go-test-linux.yaml @@ -23,7 +23,7 @@ jobs: with: fetch-depth: 0 - - name: Setup go + - name: Setup go ${{ matrix.go }} uses: actions/setup-go@v5 with: go-version: ${{ matrix.go }} diff --git a/.github/workflows/go-test-windows.yaml b/.github/workflows/go-test-windows.yaml index 2458006..b355581 100644 --- a/.github/workflows/go-test-windows.yaml +++ b/.github/workflows/go-test-windows.yaml @@ -20,7 +20,7 @@ jobs: with: fetch-depth: 0 - - name: Setup go + - name: Setup go ${{ matrix.go }} uses: actions/setup-go@v5 with: go-version: ${{ matrix.go }} diff --git a/.github/workflows/golangci-lint.yaml b/.github/workflows/golangci-lint.yaml index 7692063..c62d628 100644 --- a/.github/workflows/golangci-lint.yaml +++ b/.github/workflows/golangci-lint.yaml @@ -16,6 +16,9 @@ jobs: golangci: name: lint runs-on: ubuntu-latest + strategy: + matrix: + go: ["1.24"] steps: - name: Checkout repository @@ -26,7 +29,7 @@ jobs: - name: Setup go uses: actions/setup-go@v5 with: - go-version: 1.21 + go-version: ${{ matrix.go }} - name: Perform linting uses: golangci/golangci-lint-action@v7 diff --git a/.github/workflows/govulncheck.yaml b/.github/workflows/govulncheck.yaml new file mode 100644 index 0000000..c849032 --- /dev/null +++ b/.github/workflows/govulncheck.yaml @@ -0,0 +1,32 @@ +name: govulncheck + +on: + push: + branches-ignore: [main] + pull_request: + branches: [main] + +permissions: + contents: read + +jobs: + govulncheck: + runs-on: ubuntu-latest + strategy: + matrix: + go: ["1.24"] + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go }} + + - uses: golang/govulncheck-action@v1 + with: + go-version-input: ${{ matrix.go }} diff --git a/.github/workflows/spellcheck.yaml b/.github/workflows/spellcheck.yaml new file mode 100644 index 0000000..a6bc4c6 --- /dev/null +++ b/.github/workflows/spellcheck.yaml @@ -0,0 +1,19 @@ +name: spellcheck + +on: + pull_request: + branches: [main] + +permissions: + contents: read + +jobs: + spellcheck: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: streetsidesoftware/cspell-action@v6 + with: + config: .vscode/cspell.json diff --git a/.gitignore b/.gitignore index 950a688..73e3397 100644 --- a/.gitignore +++ b/.gitignore @@ -24,7 +24,8 @@ go.work .DS_STORE # Visual Studio code -.vscode +.vscode/* +!.vscode/cspell.json *.code-workspace .history diff --git a/.vscode/cspell.json b/.vscode/cspell.json new file mode 100644 index 0000000..650b86e --- /dev/null +++ b/.vscode/cspell.json @@ -0,0 +1,75 @@ +{ + "version": "0.2", + "language": "en", + "words": [ + "andrewslotin", + "aquilax", + "buildx", + "CCLA", + "CFLAGS", + "CODEOWNER", + "CONFIGPATH", + "covermode", + "coverpkg", + "coverprofile", + "dockerhub", + "dockter", + "DYLD", + "examplepackage", + "godoc", + "golangci", + "gomod", + "GOPATH", + "goroutines", + "gosec", + "gotest", + "gotestfmt", + "gotesttools", + "govulncheck", + "ICLA", + "LDFLAGS", + "OSARCH", + "OSTYPE", + "pkill", + "pydevproject", + "RESOURCEPATH", + "rootfs", + "Senzing", + "SENZINGSDK", + "stackoverflow", + "stretchr", + "SUPPORTPATH", + "szapi", + "Szconfig", + "szconfigmanager", + "szconfigmgr", + "Szdiagnostic", + "Szengine", + "szerror", + "szerrors", + "szerrortypes", + "szhelpers", + "szinterface", + "Szproduct", + "SZSDK", + "taskkill", + "testcoverage", + "testdata", + "testrecords", + "truthset", + "unmarshalling", + "USERPROFILE", + "wraperror" + ], + "ignorePaths": [ + ".dockerignore", + ".git/*", + ".github/linters/.golangci.yaml", + ".history/*", + ".gitignore", + "**/*.go", + "**/*.mod", + "**/*.sum", + "Makefile" + ] +} diff --git a/Makefile b/Makefile index 7b72e11..1d5bb07 100644 --- a/Makefile +++ b/Makefile @@ -75,6 +75,8 @@ dependencies-for-development: dependencies-for-development-osarch-specific @go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest @go install github.com/vladopajic/go-test-coverage/v2@latest @go install golang.org/x/tools/cmd/godoc@latest + @go install golang.org/x/vuln/cmd/govulncheck@latest + @sudo npm install -g cspell@latest .PHONY: dependencies @@ -95,7 +97,7 @@ setup: setup-osarch-specific # ----------------------------------------------------------------------------- .PHONY: lint -lint: golangci-lint +lint: golangci-lint govulncheck cspell # ----------------------------------------------------------------------------- # Build @@ -247,6 +249,327 @@ update-pkg-cache: # Specific programs # ----------------------------------------------------------------------------- +.PHONY: cspell +cspell: + @cspell lint --dot . + + +.PHONY: exhaustruct +exhaustruct: + exhaustruct ./... + + +.PHONY: gofumpt +gofumpt: + gofumpt -d ./**/*.go + + .PHONY: golangci-lint golangci-lint: @${GOBIN}/golangci-lint run --config=.github/linters/.golangci.yaml + + +.PHONY: govulncheck +govulncheck: + @${GOBIN}/govulncheck ./... + +# ----------------------------------------------------------------------------- +# Fixers +# ----------------------------------------------------------------------------- + +.PHONY: fix +fix: fix-asciicheck +fix: fix-bidichk +fix: fix-canonicalheader +# fix: fix-copyloopvar +fix: fix-cyclop +fix: fix-dupword +# fix: fix-durationcheck +# fix: fix-err113 +fix: fix-errchkjson +fix: fix-errname +fix: fix-errorlint +# fix: fix-exhaustive +# fix: fix-exhaustruct +# fix: fix-exptostd +# fix: fix-fatcontext +# fix: fix-ginkgolinter +# fix: fix-gocheckcompilerdirectives +# fix: fix-gochecknoglobals +# fix: fix-godot +fix: fix-gofumpt +# fix: fix-grouper +# fix: fix-ifacecheck +# fix: fix-interfacebloat +fix: fix-inamedparam +# fix: fix-ireturn +fix: fix-loggercheck +# fix: fix-maintidx +# fix: fix-mirror +# fix: fix-mnd +fix: fix-nakedret +# fix: fix-nilerr +fix: fix-nilnesserr +fix: fix-nilnil +fix: fix-paralleltest +fix: fix-perfsprint +# fix: fix-predeclared +# fix: fix-protogetter +# fix: fix-rowserrcheck +fix: fix-tagalign +fix: fix-tagliatelle +# fix: fix-testableexamples +fix: fix-testifylint +# fix: fix-testpackage +# fix: fix-thelper +# fix: fix-usestdlibvars +fix: fix-usetesting +# fix: fix-whitespace +fix: fix-wrapcheck +fix: fix-wsl + $(info fixes complete) + + +.PHONY: fix-asciicheck +fix-asciicheck: + @asciicheck --fix ./... + + +.PHONY: fix-bidichk +fix-bidichk: + @bidichk --fix ./... + + +.PHONY: fix-canonicalheader +fix-canonicalheader: + @canonicalheader --fix ./... + + +.PHONY: fix-copyloopvar +fix-copyloopvar: + @copyloopvar --fix ./... + + +.PHONY: fix-cyclop +fix-cyclop: + @cyclop --fix ./... + + +.PHONY: fix-dupword +fix-dupword: + @dupword --fix ./... + + +.PHONY: fix-durationcheck +fix-durationcheck: + @durationcheck --fix ./... + + +.PHONY: fix-err113 +fix-err113: + @err113 --fix ./... + + +.PHONY: fix-errchkjson +fix-errchkjson: + @errchkjson --fix ./... + + +.PHONY: fix-errname +fix-errname: + @errname --fix ./... + + +.PHONY: fix-errorlint +fix-errorlint: + @go-errorlint --fix ./... + + +.PHONY: fix-exhaustive +fix-exhaustive: + @go-exhaustive --fix ./... + + +.PHONY: fix-exhaustruct +fix-exhaustruct: + @go-exhaustruct --fix ./... + + +.PHONY: fix-exptostd +fix-exptostd: + @go-exptostd --fix ./... + + +.PHONY: fix-fatcontext +fix-fatcontext: + @go-fatcontext -fix ./... + + +.PHONY: fix-ginkgolinter +fix-ginkgolinter: + @go-ginkgolinter --fix ./... + + +.PHONY: fix-gocheckcompilerdirectives +fix-gocheckcompilerdirectives: + @go-gocheckcompilerdirectives --fix ./... + + +.PHONY: fix-gochecknoglobals +fix-gochecknoglobals: + @go-gochecknoglobals --fix ./... + + +.PHONY: fix-godot +fix-godot: + @go-godot --fix ./... + + +.PHONY: fix-gofumpt +fix-gofumpt: + @gofumpt -w ./**/*.go + + +.PHONY: fix-grouper +fix-grouper: + @grouper --fix ./... + + +.PHONY: fix-ifacecheck +fix-ifacecheck: + @ifacecheck --fix ./... + + +.PHONY: fix-interfacebloat +fix-interfacebloat: + @interfacebloat --fix ./... + + +.PHONY: fix-inamedparam +fix-inamedparam: + @inamedparam --fix ./... + + +.PHONY: fix-ireturn +fix-ireturn: + @ireturn --fix ./... + + +.PHONY: fix-loggercheck +fix-loggercheck: + @loggercheck --fix ./... + + +.PHONY: fix-maintidx +fix-maintidx: + @maintidx --fix ./... + + +.PHONY: fix-mirror +fix-mirror: + @mirror --fix ./... + + +.PHONY: fix-mnd +fix-mnd: + @mnd --fix ./... + + +.PHONY: fix-nakedret +fix-nakedret: + @nakedret --fix ./... + + +.PHONY: fix-nilerr +fix-nilerr: + @nilerr --fix ./... + + +.PHONY: fix-nilnesserr +fix-nilnesserr: + @nilnesserr --fix ./... + + +.PHONY: fix-nilnil +fix-nilnil: + @nilnil --fix ./... + + +.PHONY: fix-paralleltest +fix-paralleltest: + @paralleltest --fix ./... + + +.PHONY: fix-perfsprint +fix-perfsprint: + @perfsprint --fix ./... + + +.PHONY: fix-predeclared +fix-predeclared: + @predeclared --fix ./... + + +.PHONY: fix-protogetter +fix-protogetter: + @protogetter --fix ./... + + +.PHONY: fix-rowserrcheck +fix-rowserrcheck: + @rowserrcheck --fix ./... + + +.PHONY: fix-tagalign +fix-tagalign: + @tagalign --fix ./... + + +.PHONY: fix-tagliatelle +fix-tagliatelle: + @tagliatelle --fix ./... + + +.PHONY: fix-testableexamples +fix-testableexamples: + @testableexamples --fix ./... + + +.PHONY: fix-testifylint +fix-testifylint: + @testifylint --fix ./... + + +.PHONY: fix-testpackage +fix-testpackage: + @testpackage --fix ./... + + +.PHONY: fix-thelper +fix-thelper: + @thelper --fix ./... + + +.PHONY: fix-usestdlibvars +fix-usestdlibvars: + @usestdlibvars --fix ./... + + +.PHONY: fix-usetesting +fix-usetesting: + @usetesting --fix ./... + + +.PHONY: fix-whitespace +fix-whitespace: + @whitespace --fix ./... + + +.PHONY: fix-wrapcheck +fix-wrapcheck: + @wrapcheck --fix ./... + + +.PHONY: fix-wsl +fix-wsl: + @wsl --fix ./... diff --git a/cmd/cmd_test.go b/cmd/cmd_test.go index f10a450..1d1a4cb 100644 --- a/cmd/cmd_test.go +++ b/cmd/cmd_test.go @@ -12,6 +12,24 @@ import ( // Test public functions // ---------------------------------------------------------------------------- +func Test_CompletionCmd(test *testing.T) { + test.Parallel() + + err := cmd.CompletionCmd.Execute() + require.NoError(test, err) + err = cmd.CompletionCmd.RunE(cmd.CompletionCmd, []string{}) + require.NoError(test, err) +} + +func Test_DocsCmd(test *testing.T) { + test.Parallel() + + err := cmd.DocsCmd.Execute() + require.NoError(test, err) + err = cmd.DocsCmd.RunE(cmd.DocsCmd, []string{}) + require.NoError(test, err) +} + func Test_Execute(test *testing.T) { _ = test os.Args = []string{"command-name", "--avoid-serving"} @@ -55,36 +73,3 @@ func Test_RootCmd(test *testing.T) { err = RootCmd.RunE(RootCmd, []string{}) require.NoError(test, err) } - -func Test_completionCmd(test *testing.T) { - _ = test - err := completionCmd.Execute() - require.NoError(test, err) - err = completionCmd.RunE(completionCmd, []string{}) - require.NoError(test, err) -} - -func Test_docsCmd(test *testing.T) { - _ = test - err := docsCmd.Execute() - require.NoError(test, err) - err = docsCmd.RunE(docsCmd, []string{}) - require.NoError(test, err) -} - -// ---------------------------------------------------------------------------- -// Test private functions -// ---------------------------------------------------------------------------- - -func Test_completionAction(test *testing.T) { - var buffer bytes.Buffer - err := completionAction(&buffer) - require.NoError(test, err) -} - -func Test_docsAction_badDir(test *testing.T) { - var buffer bytes.Buffer - badDir := "/tmp/no/directory/exists" - err := docsAction(&buffer, badDir) - require.Error(test, err) -} diff --git a/cmd/completion.go b/cmd/completion.go index f4a6a35..00bbbca 100644 --- a/cmd/completion.go +++ b/cmd/completion.go @@ -3,14 +3,15 @@ package cmd import ( + "fmt" "io" "os" "github.com/spf13/cobra" ) -// completionCmd represents the completion command -var completionCmd = &cobra.Command{ +// CompletionCmd represents the completion command. +var CompletionCmd = &cobra.Command{ Use: "completion", Short: "Generate bash completion for the command", Long: `To load completions, run: @@ -22,14 +23,19 @@ source < (observe completion) RunE: func(cmd *cobra.Command, args []string) error { _ = cmd _ = args + return completionAction(os.Stdout) }, } func init() { - RootCmd.AddCommand(completionCmd) + RootCmd.AddCommand(CompletionCmd) } func completionAction(out io.Writer) error { - return RootCmd.GenBashCompletion(out) + if err := RootCmd.GenBashCompletion(out); err != nil { + return fmt.Errorf("completionAction: %w", err) + } + + return nil } diff --git a/cmd/docs.go b/cmd/docs.go index 071ca76..eac47b5 100644 --- a/cmd/docs.go +++ b/cmd/docs.go @@ -11,34 +11,39 @@ import ( "github.com/spf13/cobra/doc" ) -// docsCmd represents the docs command -var docsCmd = &cobra.Command{ +// DocsCmd represents the docs command. +var DocsCmd = &cobra.Command{ Use: "docs", Short: "Generate documentation for the command", RunE: func(cmd *cobra.Command, args []string) error { _ = args dir, err := cmd.Flags().GetString("dir") if err != nil { - return err + return fmt.Errorf("getting 'dir' value: %w", err) } if dir == "" { if dir, err = os.MkdirTemp("", "observe"); err != nil { - return err + return fmt.Errorf("constructing cobra.Command: %w", err) } } + return docsAction(os.Stdout, dir) }, } func init() { - RootCmd.AddCommand(docsCmd) - docsCmd.Flags().StringP("dir", "d", "", "Destination directory for docs") + RootCmd.AddCommand(DocsCmd) + DocsCmd.Flags().StringP("dir", "d", "", "Destination directory for docs") } func docsAction(out io.Writer, dir string) error { if err := doc.GenMarkdownTree(RootCmd, dir); err != nil { - return err + return fmt.Errorf("DocsAction: %w", err) + } + + if _, err := fmt.Fprintf(out, "Documentation successfully created in %s\n", dir); err != nil { + return fmt.Errorf("printing succsss: %w", err) } - _, err := fmt.Fprintf(out, "Documentation successfully created in %s\n", dir) - return err + + return nil } diff --git a/cmd/root.go b/cmd/root.go index 486ad32..cfd1688 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -70,12 +70,12 @@ func Execute() { } } -// Used in construction of cobra.Command +// Used in construction of cobra.Command. func PreRun(cobraCommand *cobra.Command, args []string) { cmdhelper.PreRun(cobraCommand, args, Use, ContextVariables) } -// Used in construction of cobra.Command +// Used in construction of cobra.Command. func RunE(_ *cobra.Command, _ []string) error { ctx := context.Background() @@ -93,7 +93,7 @@ func RunE(_ *cobra.Command, _ []string) error { return observer.Serve(ctx) } -// Used in construction of cobra.Command +// Used in construction of cobra.Command. func Version() string { return cmdhelper.Version(githubVersion, githubIteration) } diff --git a/makefiles/darwin.mk b/makefiles/darwin.mk index 17bfbe1..51e738c 100644 --- a/makefiles/darwin.mk +++ b/makefiles/darwin.mk @@ -38,7 +38,7 @@ coverage-osarch-specific: .PHONY: dependencies-for-development-osarch-specific dependencies-for-development-osarch-specific: - @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin latest + @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/main/install.sh | sh -s -- -b $(shell go env GOPATH)/bin latest .PHONY: documentation-osarch-specific diff --git a/makefiles/linux.mk b/makefiles/linux.mk index 5a1678d..ba4ea83 100644 --- a/makefiles/linux.mk +++ b/makefiles/linux.mk @@ -34,7 +34,7 @@ coverage-osarch-specific: .PHONY: dependencies-for-development-osarch-specific dependencies-for-development-osarch-specific: - @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin latest + @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/main/install.sh | sh -s -- -b $(shell go env GOPATH)/bin latest .PHONY: documentation-osarch-specific diff --git a/rootfs/app/healthcheck.sh b/rootfs/app/healthcheck.sh index 898a02b..23e2985 100755 --- a/rootfs/app/healthcheck.sh +++ b/rootfs/app/healthcheck.sh @@ -7,6 +7,6 @@ NOT_OK=1 # Tests. -echo "Doing healthtest." +echo "Doing health test." exit ${OK} From f84a47d860bc95c926e162ebc6c39fb40c3ce91c Mon Sep 17 00:00:00 2001 From: docktermj Date: Mon, 28 Apr 2025 15:16:05 -0400 Subject: [PATCH 2/4] #137 Prep for linting --- .vscode/cspell.json | 4 +++- CHANGELOG.md | 1 - README.md | 2 +- cmd/cmd_test.go | 20 ++++++++++---------- go.mod | 14 +++++++------- go.sum | 27 ++++++++++++++------------- 6 files changed, 35 insertions(+), 33 deletions(-) diff --git a/.vscode/cspell.json b/.vscode/cspell.json index 650b86e..2f039b7 100644 --- a/.vscode/cspell.json +++ b/.vscode/cspell.json @@ -7,6 +7,7 @@ "buildx", "CCLA", "CFLAGS", + "cmdhelping", "CODEOWNER", "CONFIGPATH", "covermode", @@ -35,6 +36,7 @@ "RESOURCEPATH", "rootfs", "Senzing", + "senzingapi", "SENZINGSDK", "stackoverflow", "stretchr", @@ -72,4 +74,4 @@ "**/*.sum", "Makefile" ] -} +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index d7ac6eb..5985ae2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -95,7 +95,6 @@ and this project adheres to [Semantic Versioning]. - Initial functionality - [Keep a Changelog]: https://keepachangelog.com/en/1.0.0/ [markdownlint]: https://dlaa.me/markdownlint/ [Semantic Versioning]: https://semver.org/spec/v2.0.0.html diff --git a/README.md b/README.md index ba58425..f7762b0 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ senzing-tools observe [flags] ### Using Docker -This usage shows how to initialze a database with a Docker container. +This usage shows how to initialize a database with a Docker container. 1. :pencil2: Run `senzing/senzing-tools`. Example: diff --git a/cmd/cmd_test.go b/cmd/cmd_test.go index 1d1a4cb..f855bd0 100644 --- a/cmd/cmd_test.go +++ b/cmd/cmd_test.go @@ -1,10 +1,10 @@ -package cmd +package cmd_test import ( - "bytes" "os" "testing" + "github.com/senzing-garage/observe/cmd" "github.com/stretchr/testify/require" ) @@ -33,43 +33,43 @@ func Test_DocsCmd(test *testing.T) { func Test_Execute(test *testing.T) { _ = test os.Args = []string{"command-name", "--avoid-serving"} - Execute() + cmd.Execute() } func Test_Execute_completion(test *testing.T) { _ = test os.Args = []string{"command-name", "completion"} - Execute() + cmd.Execute() } func Test_Execute_docs(test *testing.T) { _ = test os.Args = []string{"command-name", "docs"} - Execute() + cmd.Execute() } func Test_Execute_help(test *testing.T) { _ = test os.Args = []string{"command-name", "--help"} - Execute() + cmd.Execute() } func Test_PreRun(test *testing.T) { _ = test args := []string{"command-name", "--help"} - PreRun(RootCmd, args) + cmd.PreRun(cmd.RootCmd, args) } func Test_RunE(test *testing.T) { test.Setenv("SENZING_TOOLS_AVOID_SERVING", "true") - err := RunE(RootCmd, []string{}) + err := cmd.RunE(cmd.RootCmd, []string{}) require.NoError(test, err) } func Test_RootCmd(test *testing.T) { _ = test - err := RootCmd.Execute() + err := cmd.RootCmd.Execute() require.NoError(test, err) - err = RootCmd.RunE(RootCmd, []string{}) + err = cmd.RootCmd.RunE(cmd.RootCmd, []string{}) require.NoError(test, err) } diff --git a/go.mod b/go.mod index ad4aca4..fb88cce 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/senzing-garage/observe go 1.24 require ( - github.com/senzing-garage/go-cmdhelping v0.3.3 + github.com/senzing-garage/go-cmdhelping v0.3.4 github.com/senzing-garage/go-observing v0.3.4 github.com/spf13/cobra v1.9.1 github.com/spf13/viper v1.20.1 @@ -12,16 +12,16 @@ require ( ) require ( - github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/fsnotify/fsnotify v1.8.0 // indirect + github.com/fsnotify/fsnotify v1.9.0 // indirect github.com/go-viper/mapstructure/v2 v2.2.1 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/pelletier/go-toml/v2 v2.2.3 // indirect + github.com/pelletier/go-toml/v2 v2.2.4 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/sagikazarmark/locafero v0.8.0 // indirect - github.com/senzing-garage/go-helpers v0.6.10 // indirect + github.com/sagikazarmark/locafero v0.9.0 // indirect + github.com/senzing-garage/go-helpers v0.6.11 // indirect github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.14.0 // indirect github.com/spf13/cast v1.7.1 // indirect @@ -31,7 +31,7 @@ require ( golang.org/x/net v0.39.0 // indirect golang.org/x/sys v0.32.0 // indirect golang.org/x/text v0.24.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20250422160041-2d3770c4ea7f // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20250428153025-10db94c68c34 // indirect google.golang.org/protobuf v1.36.6 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 9a72069..6541b49 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,12 @@ -github.com/cpuguy83/go-md2man/v2 v2.0.6 h1:XJtiaUW6dEEqVuZiMTn1ldk455QWwEIsMIJlo5vtkx0= github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= +github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo= +github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= -github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M= -github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= +github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= +github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= @@ -24,8 +25,8 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= -github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= +github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= +github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= @@ -34,12 +35,12 @@ github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjR github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sagikazarmark/locafero v0.8.0 h1:mXaMVw7IqxNBxfv3LdWt9MDmcWDQ1fagDH918lOdVaQ= -github.com/sagikazarmark/locafero v0.8.0/go.mod h1:UBUyz37V+EdMS3hDF3QWIiVr/2dPrx49OMO0Bn0hJqk= -github.com/senzing-garage/go-cmdhelping v0.3.3 h1:qqGdW0ZkaPjUewiBxH8mmW+1VdyvoIuk47fnHxDghzo= -github.com/senzing-garage/go-cmdhelping v0.3.3/go.mod h1:hqa81cbshd65Xw8BSjV5wNQf2Ujk49YXQKq/LhVI4Rs= -github.com/senzing-garage/go-helpers v0.6.10 h1:38jbZDzSLze2ooRStB/2pnwaxo/Lm4byiqGnGUFF+BI= -github.com/senzing-garage/go-helpers v0.6.10/go.mod h1:98w6+o6u0l1byzoj0vJW7V59hLSGqhBFZ3gaks9n2G0= +github.com/sagikazarmark/locafero v0.9.0 h1:GbgQGNtTrEmddYDSAH9QLRyfAHY12md+8YFTqyMTC9k= +github.com/sagikazarmark/locafero v0.9.0/go.mod h1:UBUyz37V+EdMS3hDF3QWIiVr/2dPrx49OMO0Bn0hJqk= +github.com/senzing-garage/go-cmdhelping v0.3.4 h1:WamPZ2SqUQycBjGFcwRgkW0MQ4cEr3ZAvaQS3c+giOk= +github.com/senzing-garage/go-cmdhelping v0.3.4/go.mod h1:adNIqAhfSrKfPAm4zRcwQxjIj/Ro6Xu1BGzdmvofFno= +github.com/senzing-garage/go-helpers v0.6.11 h1:cwXZLVFKRnriyX+RCaS1Rg9+x7/sJcJjN0TIVZo/vdo= +github.com/senzing-garage/go-helpers v0.6.11/go.mod h1:xjTBckB68M54X5fPyG1ArjXsqfs4rW4CKLNkMDFxAmo= github.com/senzing-garage/go-observing v0.3.4 h1:SQuRmgXZEzcvHYBxObmRf7GYyPt+olZPZhm46ckYGe0= github.com/senzing-garage/go-observing v0.3.4/go.mod h1:EC0jh0estTXmrnLQyUtbsVzSBNdSWFjL5O+gCA/RJJc= github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= @@ -78,8 +79,8 @@ golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0= golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU= -google.golang.org/genproto/googleapis/rpc v0.0.0-20250422160041-2d3770c4ea7f h1:N/PrbTw4kdkqNRzVfWPrBekzLuarFREcbFOiOLkXon4= -google.golang.org/genproto/googleapis/rpc v0.0.0-20250422160041-2d3770c4ea7f/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250428153025-10db94c68c34 h1:h6p3mQqrmT1XkHVTfzLdNz1u7IhINeZkz67/xTbOuWs= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250428153025-10db94c68c34/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A= google.golang.org/grpc v1.72.0 h1:S7UkcVa60b5AAQTaO6ZKamFp1zMZSU0fGDK2WZLbBnM= google.golang.org/grpc v1.72.0/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3izSDM= google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= From 3cc454fd9b47b8fa669c5e59b40d6400faac3864 Mon Sep 17 00:00:00 2001 From: docktermj Date: Mon, 28 Apr 2025 16:25:32 -0400 Subject: [PATCH 3/4] #137 Savepoint --- .github/linters/.golangci.yaml | 35 +++++++++++++++++------------- cmd/cmd_darwin_test.go | 20 ----------------- cmd/cmd_linux_test.go | 20 ----------------- cmd/cmd_test.go | 25 +++++++++++++++------ cmd/cmd_windows_test.go | 20 ----------------- cmd/root.go | 13 +++++++++-- go.mod | 2 +- makefiles/linux.mk | 3 ++- observer/observer_examples_test.go | 5 +++-- observer/observer_simple.go | 13 ++++++++--- observer/observer_test.go | 10 ++++----- 11 files changed, 70 insertions(+), 96 deletions(-) delete mode 100644 cmd/cmd_darwin_test.go delete mode 100644 cmd/cmd_linux_test.go delete mode 100644 cmd/cmd_windows_test.go diff --git a/.github/linters/.golangci.yaml b/.github/linters/.golangci.yaml index b97858c..9882663 100644 --- a/.github/linters/.golangci.yaml +++ b/.github/linters/.golangci.yaml @@ -13,7 +13,7 @@ linters: - copyloopvar - cyclop - decorder - # - depguard + - depguard - dogsled - dupl - dupword @@ -24,24 +24,24 @@ linters: - errname - errorlint - exhaustive - # - exhaustruct + - exhaustruct - exptostd - fatcontext - # - forbidigo + - forbidigo - forcetypeassert - funcorder - funlen - ginkgolinter - gocheckcompilerdirectives - # - gochecknoglobals - # - gochecknoinits + - gochecknoglobals + - gochecknoinits - gochecksumtype - gocognit - goconst - gocritic - gocyclo - # - godot - # - godox + - godot + - godox - goheader - gomoddirectives - gomodguard @@ -70,12 +70,12 @@ linters: - nilerr - nilnesserr - nilnil - # - nlreturn + - nlreturn - noctx - nolintlint - nonamedreturns - nosprintfhostport - # - paralleltest + - paralleltest - perfsprint - prealloc - predeclared @@ -91,21 +91,21 @@ linters: - staticcheck - tagalign - tagliatelle - # - testableexamples + - testableexamples - testifylint - # - testpackage + - testpackage - thelper - tparallel - unconvert - unparam - unused - usestdlibvars - # - usetesting + - usetesting - varnamelen - wastedassign - whitespace - # - wrapcheck - # - wsl + - wrapcheck + - wsl - zerologlint disable: - gochecknoglobals @@ -134,6 +134,11 @@ linters: exhaustruct: exclude: - '.+/cobra\.Command$' + - '.+/grpcserver\.SimpleGrpcServer$' + - '.+/observer\.RawObserver$' + - '.+/observer\.SimpleObserver$' + - '.+/subject\.SimpleSubject$' + ireturn: allow: - anon @@ -145,7 +150,7 @@ formatters: enable: - gci - gofmt - # - gofumpt + - gofumpt - goimports - golines exclusions: diff --git a/cmd/cmd_darwin_test.go b/cmd/cmd_darwin_test.go deleted file mode 100644 index 3a8118f..0000000 --- a/cmd/cmd_darwin_test.go +++ /dev/null @@ -1,20 +0,0 @@ -//go:build darwin - -package cmd - -import ( - "bytes" - "testing" - - "github.com/stretchr/testify/require" -) - -// ---------------------------------------------------------------------------- -// Test private functions -// ---------------------------------------------------------------------------- - -func Test_docsAction(test *testing.T) { - var buffer bytes.Buffer - err := docsAction(&buffer, "/tmp") - require.NoError(test, err) -} diff --git a/cmd/cmd_linux_test.go b/cmd/cmd_linux_test.go deleted file mode 100644 index b1e8410..0000000 --- a/cmd/cmd_linux_test.go +++ /dev/null @@ -1,20 +0,0 @@ -//go:build linux - -package cmd - -import ( - "bytes" - "testing" - - "github.com/stretchr/testify/require" -) - -// ---------------------------------------------------------------------------- -// Test private functions -// ---------------------------------------------------------------------------- - -func Test_docsAction(test *testing.T) { - var buffer bytes.Buffer - err := docsAction(&buffer, "/tmp") - require.NoError(test, err) -} diff --git a/cmd/cmd_test.go b/cmd/cmd_test.go index f855bd0..2b52438 100644 --- a/cmd/cmd_test.go +++ b/cmd/cmd_test.go @@ -31,43 +31,54 @@ func Test_DocsCmd(test *testing.T) { } func Test_Execute(test *testing.T) { - _ = test + test.Parallel() + os.Args = []string{"command-name", "--avoid-serving"} + cmd.Execute() } func Test_Execute_completion(test *testing.T) { - _ = test + test.Parallel() + os.Args = []string{"command-name", "completion"} + cmd.Execute() } func Test_Execute_docs(test *testing.T) { - _ = test + test.Parallel() + os.Args = []string{"command-name", "docs"} + cmd.Execute() } func Test_Execute_help(test *testing.T) { - _ = test + test.Parallel() + os.Args = []string{"command-name", "--help"} + cmd.Execute() } func Test_PreRun(test *testing.T) { - _ = test + test.Parallel() + args := []string{"command-name", "--help"} cmd.PreRun(cmd.RootCmd, args) } func Test_RunE(test *testing.T) { - test.Setenv("SENZING_TOOLS_AVOID_SERVING", "true") + test.Setenv("SENZING_TOOLS_AVOID_SERVING", "True") + err := cmd.RunE(cmd.RootCmd, []string{}) require.NoError(test, err) } func Test_RootCmd(test *testing.T) { - _ = test + test.Parallel() + err := cmd.RootCmd.Execute() require.NoError(test, err) err = cmd.RootCmd.RunE(cmd.RootCmd, []string{}) diff --git a/cmd/cmd_windows_test.go b/cmd/cmd_windows_test.go deleted file mode 100644 index ebb845b..0000000 --- a/cmd/cmd_windows_test.go +++ /dev/null @@ -1,20 +0,0 @@ -//go:build windows - -package cmd - -import ( - "bytes" - "testing" - - "github.com/stretchr/testify/require" -) - -// ---------------------------------------------------------------------------- -// Test private functions -// ---------------------------------------------------------------------------- - -func Test_docsAction(test *testing.T) { - var buffer bytes.Buffer - err := docsAction(&buffer, "C:\\Temp") - require.NoError(test, err) -} diff --git a/cmd/root.go b/cmd/root.go index cfd1688..7413ae9 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -4,11 +4,13 @@ package cmd import ( "context" + "fmt" "os" "github.com/senzing-garage/go-cmdhelping/cmdhelper" "github.com/senzing-garage/go-cmdhelping/option" "github.com/senzing-garage/go-cmdhelping/option/optiontype" + "github.com/senzing-garage/go-helpers/wraperror" "github.com/senzing-garage/observe/observer" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -79,18 +81,25 @@ func PreRun(cobraCommand *cobra.Command, args []string) { func RunE(_ *cobra.Command, _ []string) error { ctx := context.Background() - // TODO: Support various gRPC server options. + // IMPROVE: Support various gRPC server options. serverOptions := []grpc.ServerOption{} // Create and run gRPC server. + fmt.Printf(">>>>>>> avoidServe.Arg %t\n", viper.GetBool(avoidServe.Arg)) + observer := &observer.SimpleObserver{ AvoidServing: viper.GetBool(avoidServe.Arg), Port: viper.GetInt(option.ObserverGrpcPort.Arg), ServerOptions: serverOptions, } - return observer.Serve(ctx) + + if err := observer.Serve(ctx); err != nil { + return wraperror.Errorf(err, "observe.cmd.RunE error: %w", err) + } + + return nil } // Used in construction of cobra.Command. diff --git a/go.mod b/go.mod index fb88cce..fd226f7 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.24 require ( github.com/senzing-garage/go-cmdhelping v0.3.4 + github.com/senzing-garage/go-helpers v0.6.11 github.com/senzing-garage/go-observing v0.3.4 github.com/spf13/cobra v1.9.1 github.com/spf13/viper v1.20.1 @@ -21,7 +22,6 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sagikazarmark/locafero v0.9.0 // indirect - github.com/senzing-garage/go-helpers v0.6.11 // indirect github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.14.0 // indirect github.com/spf13/cast v1.7.1 // indirect diff --git a/makefiles/linux.mk b/makefiles/linux.mk index ba4ea83..a674595 100644 --- a/makefiles/linux.mk +++ b/makefiles/linux.mk @@ -69,7 +69,8 @@ setup-osarch-specific: .PHONY: test-osarch-specific test-osarch-specific: - @go test -json -v -p 1 ./... 2>&1 | tee /tmp/gotest.log | gotestfmt + # @go test -json -v -p 1 ./... 2>&1 | tee /tmp/gotest.log | gotestfmt + @go test -v -p 1 ./... # ----------------------------------------------------------------------------- # Makefile targets supported only by this platform. diff --git a/observer/observer_examples_test.go b/observer/observer_examples_test.go index 0b14da1..ddb76db 100644 --- a/observer/observer_examples_test.go +++ b/observer/observer_examples_test.go @@ -1,4 +1,4 @@ -package observer +package observer_test // ---------------------------------------------------------------------------- // Examples for godoc documentation @@ -6,5 +6,6 @@ package observer func ExampleSimpleObserver_Serve() { // For more information, visit https://github.com/senzing-garage/observe/blob/main/observer/observer_test.go - //Output: + + // Output: } diff --git a/observer/observer_simple.go b/observer/observer_simple.go index fc582d9..e938769 100644 --- a/observer/observer_simple.go +++ b/observer/observer_simple.go @@ -2,7 +2,10 @@ package observer import ( "context" + "fmt" + "os" + "github.com/senzing-garage/go-helpers/wraperror" "github.com/senzing-garage/go-observing/grpcserver" "github.com/senzing-garage/go-observing/observer" "github.com/senzing-garage/go-observing/subject" @@ -36,7 +39,6 @@ Output */ func (observerImpl *SimpleObserver) Serve(ctx context.Context) error { // Create a Subject. - aSubject := &subject.SimpleSubject{} // Register an observer with the Subject. @@ -47,7 +49,7 @@ func (observerImpl *SimpleObserver) Serve(ctx context.Context) error { err := aSubject.RegisterObserver(ctx, anObserver) if err != nil { - return err + return wraperror.Errorf(err, "observer.Serve.RegisterObserver error: %w", err) } // Run an Observer gRPC service. @@ -58,9 +60,14 @@ func (observerImpl *SimpleObserver) Serve(ctx context.Context) error { Subject: aSubject, } + fmt.Printf(">>>>>>> SENZING_TOOLS_AVOID_SERVING: %s\n", os.Getenv("SENZING_TOOLS_AVOID_SERVING")) + fmt.Printf(">>>>>>> observerImpl.AvoidServing %t\n", observerImpl.AvoidServing) + if !observerImpl.AvoidServing { err = aGrpcServer.Serve(ctx) } - return err + fmt.Printf(">>>>>>> observerImpl.AvoidServing done\n") + + return wraperror.Errorf(err, "observer.Serve error: %w", err) } diff --git a/observer/observer_test.go b/observer/observer_test.go index 2a29e44..cceeccc 100644 --- a/observer/observer_test.go +++ b/observer/observer_test.go @@ -1,9 +1,9 @@ -package observer +package observer_test import ( - "context" "testing" + "github.com/senzing-garage/observe/observer" "github.com/stretchr/testify/require" ) @@ -12,9 +12,9 @@ import ( // ---------------------------------------------------------------------------- func TestSimpleObserver_Serve(test *testing.T) { - _ = test - ctx := context.TODO() - testObject := &SimpleObserver{ + test.Parallel() + ctx := test.Context() + testObject := &observer.SimpleObserver{ AvoidServing: true, } err := testObject.Serve(ctx) From 605877ea0cad8c7e4b4be277b820a5aee9f59c52 Mon Sep 17 00:00:00 2001 From: docktermj Date: Mon, 28 Apr 2025 17:27:58 -0400 Subject: [PATCH 4/4] #137 Prepare for versioned release --- CHANGELOG.md | 6 ++++++ cmd/cmd_test.go | 8 ++++++-- cmd/root.go | 3 --- main_test.go | 1 - makefiles/linux.mk | 3 +-- observer/observer_simple.go | 7 ------- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5985ae2..8aea675 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning]. - +## [0.3.2] - 2025-04-28 + +### Changed in 0.3.2 + +- Update dependencies + ## [0.3.1] - 2024-09-09 ### Changed in 0.3.1 diff --git a/cmd/cmd_test.go b/cmd/cmd_test.go index 2b52438..10f77a3 100644 --- a/cmd/cmd_test.go +++ b/cmd/cmd_test.go @@ -15,6 +15,8 @@ import ( func Test_CompletionCmd(test *testing.T) { test.Parallel() + os.Args = []string{"command-name", "--avoid-serving"} + err := cmd.CompletionCmd.Execute() require.NoError(test, err) err = cmd.CompletionCmd.RunE(cmd.CompletionCmd, []string{}) @@ -24,6 +26,8 @@ func Test_CompletionCmd(test *testing.T) { func Test_DocsCmd(test *testing.T) { test.Parallel() + os.Args = []string{"command-name", "--avoid-serving"} + err := cmd.DocsCmd.Execute() require.NoError(test, err) err = cmd.DocsCmd.RunE(cmd.DocsCmd, []string{}) @@ -70,8 +74,8 @@ func Test_PreRun(test *testing.T) { } func Test_RunE(test *testing.T) { - test.Setenv("SENZING_TOOLS_AVOID_SERVING", "True") - + test.Setenv("SENZING_TOOLS_AVOID_SERVING", "true") + cmd.PreRun(cmd.RootCmd, []string{}) err := cmd.RunE(cmd.RootCmd, []string{}) require.NoError(test, err) } diff --git a/cmd/root.go b/cmd/root.go index 7413ae9..22e53a9 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -4,7 +4,6 @@ package cmd import ( "context" - "fmt" "os" "github.com/senzing-garage/go-cmdhelping/cmdhelper" @@ -87,8 +86,6 @@ func RunE(_ *cobra.Command, _ []string) error { // Create and run gRPC server. - fmt.Printf(">>>>>>> avoidServe.Arg %t\n", viper.GetBool(avoidServe.Arg)) - observer := &observer.SimpleObserver{ AvoidServing: viper.GetBool(avoidServe.Arg), Port: viper.GetInt(option.ObserverGrpcPort.Arg), diff --git a/main_test.go b/main_test.go index b7a90be..2b73339 100644 --- a/main_test.go +++ b/main_test.go @@ -5,7 +5,6 @@ import ( ) func TestMain(test *testing.T) { - _ = test test.Setenv("SENZING_TOOLS_AVOID_SERVING", "true") main() } diff --git a/makefiles/linux.mk b/makefiles/linux.mk index a674595..ba4ea83 100644 --- a/makefiles/linux.mk +++ b/makefiles/linux.mk @@ -69,8 +69,7 @@ setup-osarch-specific: .PHONY: test-osarch-specific test-osarch-specific: - # @go test -json -v -p 1 ./... 2>&1 | tee /tmp/gotest.log | gotestfmt - @go test -v -p 1 ./... + @go test -json -v -p 1 ./... 2>&1 | tee /tmp/gotest.log | gotestfmt # ----------------------------------------------------------------------------- # Makefile targets supported only by this platform. diff --git a/observer/observer_simple.go b/observer/observer_simple.go index e938769..24c9aaa 100644 --- a/observer/observer_simple.go +++ b/observer/observer_simple.go @@ -2,8 +2,6 @@ package observer import ( "context" - "fmt" - "os" "github.com/senzing-garage/go-helpers/wraperror" "github.com/senzing-garage/go-observing/grpcserver" @@ -60,14 +58,9 @@ func (observerImpl *SimpleObserver) Serve(ctx context.Context) error { Subject: aSubject, } - fmt.Printf(">>>>>>> SENZING_TOOLS_AVOID_SERVING: %s\n", os.Getenv("SENZING_TOOLS_AVOID_SERVING")) - fmt.Printf(">>>>>>> observerImpl.AvoidServing %t\n", observerImpl.AvoidServing) - if !observerImpl.AvoidServing { err = aGrpcServer.Serve(ctx) } - fmt.Printf(">>>>>>> observerImpl.AvoidServing done\n") - return wraperror.Errorf(err, "observer.Serve error: %w", err) }