From 2594b521a5f56a6816c60b5691acd3569f0f697c Mon Sep 17 00:00:00 2001 From: Michael Dockter Date: Wed, 12 Jun 2024 16:14:59 -0400 Subject: [PATCH] 89 dockter 1 (#92) * #89 Update dependencies * #89 Working lint and tests * #89 Prepare for versioned release --- .github/linters/.golangci.yml | 47 ++++++++++++++ .github/linters/.jscpd.json | 4 +- .github/workflows/go-test-darwin.yaml | 18 +++++- .github/workflows/go-test-linux.yaml | 13 +++- .github/workflows/go-test-windows.yaml | 17 +++++- .github/workflows/gofmt.yaml | 12 ---- .github/workflows/golangci-lint.yaml | 36 +++++++++++ .github/workflows/gosec.yaml | 27 -------- .gitignore | 1 + .testcoverage.yml | 49 +++++++++++++++ CHANGELOG.md | 7 +++ Makefile | 31 +++++++++- cmd/cmd_darwin_test.go | 20 ++++++ cmd/cmd_linux_test.go | 20 ++++++ cmd/cmd_test.go | 61 ++++++++++++++++++- cmd/cmd_windows_test.go | 20 ++++++ cmd/completion.go | 2 + cmd/docs.go | 2 + cmd/github.go | 14 ++--- cmd/root.go | 13 +++- go.mod | 21 ++++--- go.sum | 36 +++++------ main_test.go | 6 +- makefiles/darwin.mk | 15 ++++- makefiles/linux.mk | 16 ++++- makefiles/windows.mk | 11 +++- observer/main.go | 6 +- observer/observer_examples_test.go | 10 +++ .../{observer_impl.go => observer_simple.go} | 20 +++--- observer/observer_test.go | 52 ++++------------ 30 files changed, 463 insertions(+), 144 deletions(-) create mode 100644 .github/linters/.golangci.yml delete mode 100644 .github/workflows/gofmt.yaml create mode 100644 .github/workflows/golangci-lint.yaml delete mode 100644 .github/workflows/gosec.yaml create mode 100644 .testcoverage.yml create mode 100644 cmd/cmd_darwin_test.go create mode 100644 cmd/cmd_linux_test.go create mode 100644 cmd/cmd_windows_test.go create mode 100644 observer/observer_examples_test.go rename observer/{observer_impl.go => observer_simple.go} (76%) diff --git a/.github/linters/.golangci.yml b/.github/linters/.golangci.yml new file mode 100644 index 0000000..389317d --- /dev/null +++ b/.github/linters/.golangci.yml @@ -0,0 +1,47 @@ +run: + modules-download-mode: readonly + show-stats: true + +output: + print-linter-name: false + sort-results: true + +linters: + enable: + # List generated from: https://golangci-lint.run/usage/linters/ + # We are enabling all defaults as well as any bug/security related + - asasalint + - asciicheck + - bidichk + - bodyclose + - contextcheck + - durationcheck + - errcheck + - errchkjson + - errorlint + - exhaustive + - exportloopref + - gocheckcompilerdirectives + - gochecksumtype + - gocritic + - gofmt + - gosec + - gosimple + - gosmopolitan + - govet + - ineffassign + - loggercheck + - makezero + - musttag + - nilerr + - noctx + - protogetter + - reassign + - revive + - rowserrcheck + - spancheck + - sqlclosecheck + - staticcheck + - testifylint + - unused + - zerologlint diff --git a/.github/linters/.jscpd.json b/.github/linters/.jscpd.json index 6eb5f17..3a60fa8 100644 --- a/.github/linters/.jscpd.json +++ b/.github/linters/.jscpd.json @@ -1,3 +1,5 @@ { - "threshold": 3 + "ignore": [ + "**/*.go,**/go-test*.yaml" + ] } \ No newline at end of file diff --git a/.github/workflows/go-test-darwin.yaml b/.github/workflows/go-test-darwin.yaml index 7e9d9c4..80381a6 100644 --- a/.github/workflows/go-test-darwin.yaml +++ b/.github/workflows/go-test-darwin.yaml @@ -1,6 +1,7 @@ name: go test darwin -on: [push] +on: [pull_request, workflow_dispatch] + permissions: contents: read @@ -12,7 +13,7 @@ jobs: strategy: matrix: go: ["1.21"] - os: [macos-latest] + os: [macos-13] steps: - name: checkout repository @@ -26,4 +27,15 @@ jobs: go-version: ${{ matrix.go }} - name: run go test - run: go test -v -p 1 ./... + run: go test -v -p 1 -coverprofile=./cover.out -covermode=atomic -coverpkg=./... ./... + + - name: Store coverage file + uses: actions/upload-artifact@v4 + with: + name: cover.out + path: ./cover.out + + coverage: + name: coverage + needs: go-test-darwin + uses: senzing-factory/build-resources/.github/workflows/go-coverage.yaml@v2 diff --git a/.github/workflows/go-test-linux.yaml b/.github/workflows/go-test-linux.yaml index 7d702e8..a016aa1 100644 --- a/.github/workflows/go-test-linux.yaml +++ b/.github/workflows/go-test-linux.yaml @@ -26,4 +26,15 @@ jobs: go-version: ${{ matrix.go }} - name: run go test - run: go test -v -p 1 ./... + run: go test -v -p 1 -coverprofile=./cover.out -covermode=atomic -coverpkg=./... ./... + + - name: Store coverage file + uses: actions/upload-artifact@v4 + with: + name: cover.out + path: ./cover.out + + coverage: + name: coverage + needs: go-test-linux + uses: senzing-factory/build-resources/.github/workflows/go-coverage.yaml@v2 diff --git a/.github/workflows/go-test-windows.yaml b/.github/workflows/go-test-windows.yaml index 593fdc1..0b0a01d 100644 --- a/.github/workflows/go-test-windows.yaml +++ b/.github/workflows/go-test-windows.yaml @@ -1,6 +1,6 @@ name: go test windows -on: [push] +on: [pull_request, workflow_dispatch] permissions: contents: read @@ -26,4 +26,17 @@ jobs: go-version: ${{ matrix.go }} - name: run go test - run: go test -v -p 1 ./... + run: | + go test -v -p 1 -coverprofile=cover -covermode=atomic -coverpkg=./... ./... + cp cover cover.out + + - name: Store coverage file + uses: actions/upload-artifact@v4 + with: + name: cover.out + path: cover.out + + coverage: + name: coverage + needs: go-test-windows + uses: senzing-factory/build-resources/.github/workflows/go-coverage.yaml@v2 diff --git a/.github/workflows/gofmt.yaml b/.github/workflows/gofmt.yaml deleted file mode 100644 index 54b4e5a..0000000 --- a/.github/workflows/gofmt.yaml +++ /dev/null @@ -1,12 +0,0 @@ -name: gofmt - -on: - pull_request: - branches: [main] - -permissions: - contents: read - -jobs: - gofmt: - uses: senzing-factory/build-resources/.github/workflows/gofmt.yaml@v2 diff --git a/.github/workflows/golangci-lint.yaml b/.github/workflows/golangci-lint.yaml new file mode 100644 index 0000000..bffb573 --- /dev/null +++ b/.github/workflows/golangci-lint.yaml @@ -0,0 +1,36 @@ +name: golangci-lint + +on: + push: + branches-ignore: [main] + pull_request: + branches: [main] + +permissions: + # Required: allow read access to the content for analysis. + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + pull-requests: read + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + + steps: + - name: checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: setup go + uses: actions/setup-go@v5 + with: + go-version: 1.21 + + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + args: --config=${{ github.workspace }}/.github/linters/.golangci.yml + only-new-issues: false + version: latest diff --git a/.github/workflows/gosec.yaml b/.github/workflows/gosec.yaml deleted file mode 100644 index 44ccbb7..0000000 --- a/.github/workflows/gosec.yaml +++ /dev/null @@ -1,27 +0,0 @@ -name: gosec - -on: - push: - branches: - - main - pull_request: - branches: - - main - -permissions: - contents: read - -jobs: - gosec: - runs-on: ubuntu-latest - env: - GO111MODULE: on - - steps: - - name: checkout repository - uses: actions/checkout@v4 - - - name: run Gosec Security Scanner - uses: securego/gosec@master - with: - args: ./... diff --git a/.gitignore b/.gitignore index 393d348..a7bf099 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,4 @@ go.work # Makefile target/ +coverage.html diff --git a/.testcoverage.yml b/.testcoverage.yml new file mode 100644 index 0000000..19d5c8e --- /dev/null +++ b/.testcoverage.yml @@ -0,0 +1,49 @@ +# (mandatory) +# Path to coverprofile file (output of `go test -coverprofile` command). +# +# For cases where there are many coverage profiles, such as when running +# unit tests and integration tests separately, you can combine all those +# profiles into one. In this case, the profile should have a comma-separated list +# of profile files, e.g., 'cover_unit.out,cover_integration.out'. +profile: cover.out + +# (optional; but recommended to set) +# When specified reported file paths will not contain local prefix in the output +local-prefix: "github.com/org/project" + +# Holds coverage thresholds percentages, values should be in range [0-100] +threshold: + # (optional; default 0) + # The minimum coverage that each file should have + file: 70 + + # (optional; default 0) + # The minimum coverage that each package should have + package: 70 + + # (optional; default 0) + # The minimum total coverage project should have + total: 70 +# Holds regexp rules which will override thresholds for matched files or packages +# using their paths. +# +# First rule from this list that matches file or package is going to apply +# new threshold to it. If project has multiple rules that match same path, +# override rules should be listed in order from specific to more general rules. +#override: +# Increase coverage threshold to 100% for `foo` package +# (default is 80, as configured above in this example) +#- threshold: 100 +# path: ^pkg/lib/foo$ + +# Holds regexp rules which will exclude matched files or packages +# from coverage statistics +#exclude: +# Exclude files or packages matching their paths +#paths: +# - \.pb\.go$ # excludes all protobuf generated files +# - ^pkg/bar # exclude package `pkg/bar` + +# NOTES: +# - symbol `/` in all path regexps will be replaced by current OS file path separator +# to properly work on Windows diff --git a/CHANGELOG.md b/CHANGELOG.md index 251a46b..2d5e666 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - +## [0.2.2] - 2024-06-12 + +### Changed in 0.2.2 + +- From `ObserverInterface` to `Observer` +- From `ObserverImpl` to `SimpleObserver` + ## [0.2.1] - 2024-04-19 ### Changed in 0.2.1 diff --git a/Makefile b/Makefile index b03deb3..3d78d8f 100644 --- a/Makefile +++ b/Makefile @@ -32,9 +32,10 @@ GO_ARCH = $(word 2, $(GO_OSARCH)) # Conditional assignment. ('?=') # Can be overridden with "export" -# Example: "export LD_LIBRARY_PATH=/path/to/my/senzing/g2/lib" +# Example: "export LD_LIBRARY_PATH=/path/to/my/senzing-garage/g2/lib" LD_LIBRARY_PATH ?= /opt/senzing/g2/lib +GOBIN ?= $(shell go env GOPATH)/bin # Export environment variables. @@ -62,6 +63,12 @@ hello-world: hello-world-osarch-specific # Dependency management # ----------------------------------------------------------------------------- +.PHONY: make-dependencies +make-dependencies: + @go install github.com/vladopajic/go-test-coverage/v2@latest + @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.58.1 + + .PHONY: dependencies dependencies: @go get -u ./... @@ -117,6 +124,28 @@ docker-build: .PHONY: test test: test-osarch-specific +# ----------------------------------------------------------------------------- +# Coverage +# ----------------------------------------------------------------------------- + +.PHONY: coverage +coverage: coverage-osarch-specific + + +.PHONY: check-coverage +check-coverage: export SENZING_LOG_LEVEL=TRACE +check-coverage: + go test ./... -coverprofile=./cover.out -covermode=atomic -coverpkg=./... + ${GOBIN}/go-test-coverage --config=./.testcoverage.yml + +# ----------------------------------------------------------------------------- +# Lint +# ----------------------------------------------------------------------------- + +.PHONY: run-golangci-lint +run-golangci-lint: + ${GOBIN}/golangci-lint run --config=.github/linters/.golangci.yml + # ----------------------------------------------------------------------------- # Run # ----------------------------------------------------------------------------- diff --git a/cmd/cmd_darwin_test.go b/cmd/cmd_darwin_test.go new file mode 100644 index 0000000..3a8118f --- /dev/null +++ b/cmd/cmd_darwin_test.go @@ -0,0 +1,20 @@ +//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 new file mode 100644 index 0000000..b1e8410 --- /dev/null +++ b/cmd/cmd_linux_test.go @@ -0,0 +1,20 @@ +//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 046c5b0..eb8b7a2 100644 --- a/cmd/cmd_test.go +++ b/cmd/cmd_test.go @@ -1,10 +1,69 @@ package cmd import ( + "bytes" + "os" "testing" + + "github.com/stretchr/testify/require" ) +// ---------------------------------------------------------------------------- +// Test public functions +// ---------------------------------------------------------------------------- + /* * The unit tests in this file simulate command line invocation. */ -func TestMain(testing *testing.T) {} +func Test_Execute(test *testing.T) { + _ = test + os.Args = []string{"command-name", "--avoid-serving"} + Execute() +} + +func Test_Execute_completion(test *testing.T) { + _ = test + os.Args = []string{"command-name", "completion"} + Execute() +} + +func Test_Execute_docs(test *testing.T) { + _ = test + os.Args = []string{"command-name", "docs"} + Execute() +} + +func Test_Execute_help(test *testing.T) { + _ = test + os.Args = []string{"command-name", "--help"} + Execute() +} + +func Test_PreRun(test *testing.T) { + _ = test + args := []string{"command-name", "--help"} + PreRun(RootCmd, args) +} + +func Test_RunE(test *testing.T) { + test.Setenv("SENZING_TOOLS_AVOID_SERVING", "true") + err := RunE(RootCmd, []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/cmd_windows_test.go b/cmd/cmd_windows_test.go new file mode 100644 index 0000000..ebb845b --- /dev/null +++ b/cmd/cmd_windows_test.go @@ -0,0 +1,20 @@ +//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/completion.go b/cmd/completion.go index fd00647..f4a6a35 100644 --- a/cmd/completion.go +++ b/cmd/completion.go @@ -20,6 +20,8 @@ To load completions automaticallon on login, add this line to your .bashrc file: source < (observe completion) `, RunE: func(cmd *cobra.Command, args []string) error { + _ = cmd + _ = args return completionAction(os.Stdout) }, } diff --git a/cmd/docs.go b/cmd/docs.go index a261966..0b7c89f 100644 --- a/cmd/docs.go +++ b/cmd/docs.go @@ -16,6 +16,8 @@ var docsCmd = &cobra.Command{ Use: "docs", Short: "Generate documentation for the command", RunE: func(cmd *cobra.Command, args []string) error { + _ = cmd + _ = args dir, err := cmd.Flags().GetString("dir") if err != nil { return err diff --git a/cmd/github.go b/cmd/github.go index 146c5c8..a85ab90 100644 --- a/cmd/github.go +++ b/cmd/github.go @@ -5,11 +5,11 @@ package cmd var ( - githubDate string = "2024-04-19" - githubIteration string = "0" - githubRef string = "refs/tags/0.2.2" - githubRefName string = "0.2.2" - githubRepository string = "senzing-garage/observe" - githubRepositoryName string = "observe" - githubVersion string = "0.2.2" + githubDate = "2024-04-19" + githubIteration = "0" + githubRef = "refs/tags/0.2.2" + githubRefName = "0.2.2" + githubRepository = "senzing-garage/observe" + githubRepositoryName = "observe" + githubVersion = "0.2.2" ) diff --git a/cmd/root.go b/cmd/root.go index 2143ea5..7796f68 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -8,6 +8,7 @@ import ( "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/observe/observer" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -22,6 +23,14 @@ Listen for Observer messages over gRPC and print them to STDOUT. ` ) +var avoidServe = option.ContextVariable{ + Arg: "avoid-serving", + Default: option.OsLookupEnvBool("SENZING_TOOLS_AVOID_SERVING", false), + Envar: "SENZING_TOOLS_AVOID_SERVING", + Help: "Avoid serving. For testing only. [%s]", + Type: optiontype.Bool, +} + // ---------------------------------------------------------------------------- // Context variables // ---------------------------------------------------------------------------- @@ -29,6 +38,7 @@ Listen for Observer messages over gRPC and print them to STDOUT. var ContextVariablesForMultiPlatform = []option.ContextVariable{ option.ObserverGrpcPort, option.LogLevel, + avoidServe, } var ContextVariables = append(ContextVariablesForMultiPlatform, ContextVariablesForOsArch...) @@ -70,7 +80,8 @@ func RunE(_ *cobra.Command, _ []string) error { // Create and run gRPC server. - observer := &observer.ObserverImpl{ + observer := &observer.SimpleObserver{ + AvoidServing: viper.GetBool(avoidServe.Arg), Port: viper.GetInt(option.ObserverGrpcPort.Arg), ServerOptions: serverOptions, } diff --git a/go.mod b/go.mod index 640ae3f..f0f4f82 100644 --- a/go.mod +++ b/go.mod @@ -3,23 +3,26 @@ module github.com/senzing-garage/observe go 1.21 require ( - github.com/senzing-garage/go-cmdhelping v0.2.1 - github.com/senzing-garage/go-observing v0.3.1 + github.com/senzing-garage/go-cmdhelping v0.2.2 + github.com/senzing-garage/go-observing v0.3.2 github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.19.0 + github.com/stretchr/testify v1.9.0 google.golang.org/grpc v1.64.0 ) require ( github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/pelletier/go-toml/v2 v2.2.2 // 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.4.0 // indirect + github.com/sagikazarmark/locafero v0.6.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.11.0 // indirect @@ -27,12 +30,12 @@ require ( github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.6.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect - golang.org/x/net v0.25.0 // indirect - golang.org/x/sys v0.20.0 // indirect - golang.org/x/text v0.15.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240506185236-b8a5c65736ae // indirect - google.golang.org/protobuf v1.34.1 // indirect + golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8 // indirect + golang.org/x/net v0.26.0 // indirect + golang.org/x/sys v0.21.0 // indirect + golang.org/x/text v0.16.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240610135401-a8a62080eff3 // indirect + google.golang.org/protobuf v1.34.2 // 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 a5cc889..4b83d91 100644 --- a/go.sum +++ b/go.sum @@ -32,14 +32,14 @@ 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.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= -github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= +github.com/sagikazarmark/locafero v0.6.0 h1:ON7AQg37yzcRPU69mt7gwhFEBwxI6P9T4Qu3N51bwOk= +github.com/sagikazarmark/locafero v0.6.0/go.mod h1:77OmuIc6VTraTXKXIs/uvUxKGUXjE1GbemJYHqdNjX0= github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= -github.com/senzing-garage/go-cmdhelping v0.2.1 h1:F40uSBtxP03/5aXAUW9C5kMuCFj8lFvmvDlJDvAq9qE= -github.com/senzing-garage/go-cmdhelping v0.2.1/go.mod h1:76FIsPpEWQrsY7DLR5f/I0bi5UB43KfmDd7b1jBfot8= -github.com/senzing-garage/go-observing v0.3.1 h1:EGqe+Uix8VNQ9HCwm5xZkAF0hGoHaC1URAaT/5FW37A= -github.com/senzing-garage/go-observing v0.3.1/go.mod h1:x60vlRIR0ZdJrHDuK82nzmQG4sN0G6oqdLE9vQl9pVc= +github.com/senzing-garage/go-cmdhelping v0.2.2 h1:2DE6uapQuoHodlOu6dFEspo8RNwhEkMZrb9azo+6uiw= +github.com/senzing-garage/go-cmdhelping v0.2.2/go.mod h1:cE/9aV+4NizpnduntqbjGBmRS1+VAGn9oTR0yybgeko= +github.com/senzing-garage/go-observing v0.3.2 h1:jXW5u656aZywe/UEUi7ga7nieBSW4CUO8YKvpNNAFMQ= +github.com/senzing-garage/go-observing v0.3.2/go.mod h1:5yHCwaaIrwX81JOghAL/1Q1V8eF7SQhyBBdhTb7+rgY= github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= @@ -65,20 +65,20 @@ github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8 github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM= -golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc= -golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= -golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240506185236-b8a5c65736ae h1:c55+MER4zkBS14uJhSZMGGmya0yJx5iHV4x/fpOSNRk= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240506185236-b8a5c65736ae/go.mod h1:I7Y+G38R2bu5j1aLzfFmQfTcU/WnFuqDwLZAbvKTKpM= +golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8 h1:LoYXNGAShUG3m/ehNk4iFctuhGX/+R1ZpfJ4/ia80JM= +golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI= +golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= +golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240610135401-a8a62080eff3 h1:9Xyg6I9IWQZhRVfCWjKK+l6kI0jHcPesVlMnT//aHNo= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240610135401-a8a62080eff3/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= -google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= -google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/main_test.go b/main_test.go index f251504..b606e64 100644 --- a/main_test.go +++ b/main_test.go @@ -7,6 +7,8 @@ import ( /* * The unit tests in this file simulate command line invocation. */ -func TestMain(testing *testing.T) { - // main() +func TestMain(test *testing.T) { + _ = test + test.Setenv("SENZING_TOOLS_AVOID_SERVING", "true") + main() } diff --git a/makefiles/darwin.mk b/makefiles/darwin.mk index 74bf170..ee0e4ed 100644 --- a/makefiles/darwin.mk +++ b/makefiles/darwin.mk @@ -20,10 +20,19 @@ build-osarch-specific: darwin/amd64 .PHONY: clean-osarch-specific clean-osarch-specific: - @docker rm --force $(DOCKER_CONTAINER_NAME) 2> /dev/null || true + @docker rm --force $(DOCKER_CONTAINER_NAME) 2> /dev/null || true @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 -f $(GOPATH)/bin/$(PROGRAM_NAME) || true + @rm -f $(MAKEFILE_DIRECTORY)/coverage.html || true + @rm -f $(MAKEFILE_DIRECTORY)/coverage.out || true + @rm -fr $(TARGET_DIRECTORY) || true + + +.PHONY: coverage-osarch-specific +coverage-osarch-specific: + @go test -v -coverprofile=coverage.out -p 1 ./... + @go tool cover -html="coverage.out" -o coverage.html + @open file://$(MAKEFILE_DIRECTORY)/coverage.html .PHONY: hello-world-osarch-specific diff --git a/makefiles/linux.mk b/makefiles/linux.mk index 71267ac..ad7a3ad 100644 --- a/makefiles/linux.mk +++ b/makefiles/linux.mk @@ -15,10 +15,20 @@ build-osarch-specific: linux/amd64 .PHONY: clean-osarch-specific clean-osarch-specific: - @docker rm --force $(DOCKER_CONTAINER_NAME) 2> /dev/null || true + @docker rm --force $(DOCKER_CONTAINER_NAME) 2> /dev/null || true @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 -f $(GOPATH)/bin/$(PROGRAM_NAME) || true + @rm -f $(MAKEFILE_DIRECTORY)/coverage.html || true + @rm -f $(MAKEFILE_DIRECTORY)/coverage.out || true + @rm -fr $(TARGET_DIRECTORY) || true + + +.PHONY: coverage-osarch-specific +coverage-osarch-specific: export SENZING_LOG_LEVEL=TRACE +coverage-osarch-specific: + @go test -v -coverprofile=coverage.out -p 1 ./... + @go tool cover -html="coverage.out" -o coverage.html + @xdg-open $(MAKEFILE_DIRECTORY)/coverage.html .PHONY: hello-world-osarch-specific diff --git a/makefiles/windows.mk b/makefiles/windows.mk index 4c8215f..88576fa 100644 --- a/makefiles/windows.mk +++ b/makefiles/windows.mk @@ -16,8 +16,17 @@ build-osarch-specific: windows/amd64 .PHONY: clean-osarch-specific clean-osarch-specific: - del /F /S /Q $(TARGET_DIRECTORY) del /F /S /Q $(GOPATH)/bin/$(PROGRAM_NAME) + del /F /S /Q $(MAKEFILE_DIRECTORY)/coverage.html + del /F /S /Q $(MAKEFILE_DIRECTORY)/coverage.out + del /F /S /Q $(TARGET_DIRECTORY) + + +.PHONY: coverage-osarch-specific +coverage-osarch-specific: + @go test -v -coverprofile=coverage.out -p 1 ./... + @go tool cover -html="coverage.out" -o coverage.html + @xdg-open file://$(MAKEFILE_DIRECTORY)/coverage.html .PHONY: hello-world-osarch-specific diff --git a/observer/main.go b/observer/main.go index 6feedfb..d94b211 100644 --- a/observer/main.go +++ b/observer/main.go @@ -8,8 +8,8 @@ import ( // Types // ---------------------------------------------------------------------------- -// The ObserverInterface interface for the Observer service. -type ObserverInterface interface { +// The Observer interface for the Observer service. +type Observer interface { Serve(ctx context.Context) error } @@ -18,4 +18,4 @@ type ObserverInterface interface { // ---------------------------------------------------------------------------- // Identfier of the package found messages having the format "senzing-6207xxxx". -const ComponentId = 6207 +const ComponentID = 6207 diff --git a/observer/observer_examples_test.go b/observer/observer_examples_test.go new file mode 100644 index 0000000..0b14da1 --- /dev/null +++ b/observer/observer_examples_test.go @@ -0,0 +1,10 @@ +package observer + +// ---------------------------------------------------------------------------- +// Examples for godoc documentation +// ---------------------------------------------------------------------------- + +func ExampleSimpleObserver_Serve() { + // For more information, visit https://github.com/senzing-garage/observe/blob/main/observer/observer_test.go + //Output: +} diff --git a/observer/observer_impl.go b/observer/observer_simple.go similarity index 76% rename from observer/observer_impl.go rename to observer/observer_simple.go index 530c137..fc582d9 100644 --- a/observer/observer_impl.go +++ b/observer/observer_simple.go @@ -13,8 +13,9 @@ import ( // Types // ---------------------------------------------------------------------------- -// ObserverImpl is an ObserverInterface. -type ObserverImpl struct { +// SimpleObserver is an ObserverInterface. +type SimpleObserver struct { + AvoidServing bool Port int ServerOptions []grpc.ServerOption } @@ -33,15 +34,15 @@ Output - Nothing is returned, except for an error. However, something is printed. See the example output. */ -func (observerImpl *ObserverImpl) Serve(ctx context.Context) error { +func (observerImpl *SimpleObserver) Serve(ctx context.Context) error { // Create a Subject. - aSubject := &subject.SubjectImpl{} + aSubject := &subject.SimpleSubject{} // Register an observer with the Subject. - anObserver := &observer.ObserverRaw{ - Id: "observe", + anObserver := &observer.RawObserver{ + ID: "observe", } err := aSubject.RegisterObserver(ctx, anObserver) @@ -51,12 +52,15 @@ func (observerImpl *ObserverImpl) Serve(ctx context.Context) error { // Run an Observer gRPC service. - aGrpcServer := &grpcserver.GrpcServerImpl{ + aGrpcServer := &grpcserver.SimpleGrpcServer{ Port: observerImpl.Port, ServerOptions: observerImpl.ServerOptions, Subject: aSubject, } - err = aGrpcServer.Serve(ctx) + + if !observerImpl.AvoidServing { + err = aGrpcServer.Serve(ctx) + } return err } diff --git a/observer/observer_test.go b/observer/observer_test.go index 298e0e4..2a29e44 100644 --- a/observer/observer_test.go +++ b/observer/observer_test.go @@ -1,52 +1,22 @@ package observer import ( - "fmt" - "os" + "context" "testing" -) - -// ---------------------------------------------------------------------------- -// Test harness -// ---------------------------------------------------------------------------- - -func TestMain(m *testing.M) { - err := setup() - if err != nil { - fmt.Print(err) - os.Exit(1) - } - code := m.Run() - err = teardown() - if err != nil { - fmt.Print(err) - } - os.Exit(code) -} - -func setup() error { - var err error = nil - return err -} -func teardown() error { - var err error = nil - return err -} + "github.com/stretchr/testify/require" +) // ---------------------------------------------------------------------------- // Test interface functions // ---------------------------------------------------------------------------- -func TestObserverImpl_Serve(test *testing.T) { - -} - -// ---------------------------------------------------------------------------- -// Examples for godoc documentation -// ---------------------------------------------------------------------------- - -func ExampleObserverImpl_Serve() { - // For more information, visit https://github.com/senzing-garage/observe/blob/main/observer/observer_test.go - //Output: +func TestSimpleObserver_Serve(test *testing.T) { + _ = test + ctx := context.TODO() + testObject := &SimpleObserver{ + AvoidServing: true, + } + err := testObject.Serve(ctx) + require.NoError(test, err) }