Skip to content

Commit a7792e2

Browse files
committed
#286 Prepare for versioned release
1 parent 5d855f8 commit a7792e2

21 files changed

+790
-436
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
-
1212

13+
## [0.7.3] - 2024-06-17
14+
15+
### Changed in 0.7.3
16+
17+
- Update methods to Senzing 4.0.0-24162
18+
1319
## [0.7.2] - 2024-05-08
1420

1521
### Added in 0.7.2

cmd/cmd_darwin_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//go:build darwin
2+
3+
package cmd
4+
5+
import (
6+
"bytes"
7+
"testing"
8+
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
// ----------------------------------------------------------------------------
13+
// Test private functions
14+
// ----------------------------------------------------------------------------
15+
16+
func Test_docsAction(test *testing.T) {
17+
var buffer bytes.Buffer
18+
err := docsAction(&buffer, "/tmp")
19+
require.NoError(test, err)
20+
}

cmd/cmd_linux_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//go:build linux
2+
3+
package cmd
4+
5+
import (
6+
"bytes"
7+
"testing"
8+
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
// ----------------------------------------------------------------------------
13+
// Test private functions
14+
// ----------------------------------------------------------------------------
15+
16+
func Test_docsAction(test *testing.T) {
17+
var buffer bytes.Buffer
18+
err := docsAction(&buffer, "/tmp")
19+
require.NoError(test, err)
20+
}

cmd/cmd_test.go

+58-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,69 @@
11
package cmd
22

33
import (
4+
"bytes"
5+
"os"
46
"testing"
7+
8+
"github.com/stretchr/testify/require"
59
)
610

11+
// ----------------------------------------------------------------------------
12+
// Test public functions
13+
// ----------------------------------------------------------------------------
14+
715
/*
816
* The unit tests in this file simulate command line invocation.
917
*/
10-
func TestMain(test *testing.T) {
18+
func Test_Execute(test *testing.T) {
19+
_ = test
20+
os.Args = []string{"command-name", "--avoid-serving"}
21+
Execute()
22+
}
23+
24+
func Test_Execute_completion(test *testing.T) {
25+
_ = test
26+
os.Args = []string{"command-name", "completion"}
27+
Execute()
28+
}
29+
30+
func Test_Execute_docs(test *testing.T) {
31+
_ = test
32+
os.Args = []string{"command-name", "docs"}
33+
Execute()
34+
}
35+
36+
func Test_Execute_help(test *testing.T) {
1137
_ = test
38+
os.Args = []string{"command-name", "--help"}
39+
Execute()
40+
}
41+
42+
func Test_PreRun(test *testing.T) {
43+
_ = test
44+
args := []string{"command-name", "--help"}
45+
PreRun(RootCmd, args)
46+
}
47+
48+
func Test_RunE(test *testing.T) {
49+
test.Setenv("SENZING_TOOLS_AVOID_SERVING", "true")
50+
err := RunE(RootCmd, []string{})
51+
require.NoError(test, err)
52+
}
53+
54+
// ----------------------------------------------------------------------------
55+
// Test private functions
56+
// ----------------------------------------------------------------------------
57+
58+
func Test_completionAction(test *testing.T) {
59+
var buffer bytes.Buffer
60+
err := completionAction(&buffer)
61+
require.NoError(test, err)
62+
}
63+
64+
func Test_docsAction_badDir(test *testing.T) {
65+
var buffer bytes.Buffer
66+
badDir := "/tmp/no/directory/exists"
67+
err := docsAction(&buffer, badDir)
68+
require.Error(test, err)
1269
}

cmd/cmd_windows_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//go:build windows
2+
3+
package cmd
4+
5+
import (
6+
"bytes"
7+
"testing"
8+
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
// ----------------------------------------------------------------------------
13+
// Test private functions
14+
// ----------------------------------------------------------------------------
15+
16+
func Test_docsAction(test *testing.T) {
17+
var buffer bytes.Buffer
18+
err := docsAction(&buffer, "C:\\Temp")
19+
require.NoError(test, err)
20+
}

cmd/root.go

+11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/senzing-garage/go-cmdhelping/cmdhelper"
1010
"github.com/senzing-garage/go-cmdhelping/option"
11+
"github.com/senzing-garage/go-cmdhelping/option/optiontype"
1112
"github.com/senzing-garage/go-cmdhelping/settings"
1213
"github.com/senzing-garage/serve-grpc/grpcserver"
1314
"github.com/spf13/cobra"
@@ -23,6 +24,14 @@ For more information, visit https://github.com/senzing-garage/serve-grpc
2324
`
2425
)
2526

27+
var avoidServe = option.ContextVariable{
28+
Arg: "avoid-serving",
29+
Default: option.OsLookupEnvBool("SENZING_TOOLS_AVOID_SERVING", false),
30+
Envar: "SENZING_TOOLS_AVOID_SERVING",
31+
Help: "Avoid serving. For testing only. [%s]",
32+
Type: optiontype.Bool,
33+
}
34+
2635
// ----------------------------------------------------------------------------
2736
// Context variables
2837
// ----------------------------------------------------------------------------
@@ -45,6 +54,7 @@ var ContextVariablesForMultiPlatform = []option.ContextVariable{
4554
option.LogLevel,
4655
option.ObserverOrigin,
4756
option.ObserverURL,
57+
avoidServe,
4858
}
4959

5060
var ContextVariables = append(ContextVariablesForMultiPlatform, ContextVariablesForOsArch...)
@@ -87,6 +97,7 @@ func RunE(_ *cobra.Command, _ []string) error {
8797
}
8898

8999
grpcserver := &grpcserver.BasicGrpcServer{
100+
AvoidServing: viper.GetBool(avoidServe.Arg),
90101
EnableAll: viper.GetBool(option.EnableAll.Arg),
91102
EnableSzConfig: viper.GetBool(option.EnableSzConfig.Arg),
92103
EnableSzConfigManager: viper.GetBool(option.EnableSzConfigManager.Arg),

grpcserver/grpcserver.go grpcserver/grpcserver_basic.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131

3232
// BasicGrpcServer is the default implementation of the GrpcServer interface.
3333
type BasicGrpcServer struct {
34+
AvoidServing bool
3435
EnableAll bool
3536
EnableSzConfig bool
3637
EnableSzConfigManager bool
@@ -59,7 +60,8 @@ func (grpcServer *BasicGrpcServer) getLogger() logging.Logging {
5960
var err error
6061
if grpcServer.logger == nil {
6162
options := []interface{}{
62-
&logging.OptionCallerSkip{Value: 3},
63+
logging.OptionCallerSkip{Value: 3},
64+
logging.OptionMessageFields{Value: []string{"id", "text", "reason", "errors", "details"}},
6365
}
6466
grpcServer.logger, err = logging.NewSenzingLogger(ComponentID, IDMessages, options...)
6567
if err != nil {
@@ -105,6 +107,9 @@ func (grpcServer *BasicGrpcServer) createGrpcObserver(ctx context.Context, parse
105107
// Add SzConfig service to gRPC server.
106108
func (grpcServer *BasicGrpcServer) enableSzConfig(ctx context.Context, serviceRegistrar grpc.ServiceRegistrar) {
107109
server := &szconfigserver.SzConfigServer{}
110+
111+
fmt.Printf("\n\n>>>>>>>>>>>>>>>>>>>>>>>>>> LogLevelName: %s\n\n", grpcServer.LogLevelName)
112+
108113
err := server.SetLogLevel(ctx, grpcServer.LogLevelName)
109114
if err != nil {
110115
panic(err)
@@ -262,7 +267,6 @@ func (grpcServer *BasicGrpcServer) Serve(ctx context.Context) error {
262267
if err != nil {
263268
grpcServer.log(4001, grpcServer.Port, err)
264269
}
265-
grpcServer.log(2003, listener.Addr())
266270

267271
// Create server.
268272

@@ -292,9 +296,12 @@ func (grpcServer *BasicGrpcServer) Serve(ctx context.Context) error {
292296

293297
// Run server.
294298

295-
err = aGrpcServer.Serve(listener)
296-
if err != nil {
297-
grpcServer.log(5001, err)
299+
if !grpcServer.AvoidServing {
300+
grpcServer.log(2003, listener.Addr())
301+
err = aGrpcServer.Serve(listener)
302+
} else {
303+
grpcServer.log(2004)
304+
err = listener.Close()
298305
}
299306

300307
return err

grpcserver/grpcserver_test.go

+31-19
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import (
99

1010
"github.com/senzing-garage/go-helpers/settings"
1111
"github.com/senzing-garage/go-logging/logging"
12+
"github.com/senzing-garage/go-observing/observer"
1213
"github.com/senzing-garage/sz-sdk-go-core/szconfig"
1314
"github.com/senzing-garage/sz-sdk-go-core/szconfigmanager"
1415
"github.com/senzing-garage/sz-sdk-go-core/szdiagnostic"
1516
"github.com/senzing-garage/sz-sdk-go/senzing"
17+
"github.com/stretchr/testify/require"
1618
)
1719

1820
var (
@@ -163,23 +165,33 @@ func teardown() error {
163165

164166
func TestGrpcServerImpl_Serve(test *testing.T) {
165167
_ = test
166-
// TODO: Implement TestGrpcServerImpl_Serve
167-
// ctx := context.TODO()
168-
169-
// observer1 := &observer.ObserverNull{
170-
// Id: "Observer 1",
171-
// }
172-
173-
// senzingsettings, err := ssettings.BuildSimpleSystemConfigurationJsonUsingEnvVars()
174-
// if err != nil {
175-
// fmt.Print(err)
176-
// }
177-
// grpcServer := &GrpcServerImpl{
178-
// LogLevel: logger.LevelInfo,
179-
// Observers: []observer.Observer{observer1},
180-
// Port: 8258,
181-
// Senzingsettings: senzingsettings,
182-
// SenzingModuleName: "Test gRPC Server",
183-
// }
184-
// grpcServer.Serve(ctx)
168+
ctx := context.TODO()
169+
170+
observer1 := &observer.NullObserver{
171+
ID: "Observer 1",
172+
}
173+
174+
logLevelName := "INFO"
175+
osenvLogLevel := os.Getenv("SENZING_LOG_LEVEL")
176+
if len(osenvLogLevel) > 0 {
177+
logLevelName = osenvLogLevel
178+
}
179+
180+
senzingsettings, err := settings.BuildSimpleSettingsUsingEnvVars()
181+
require.NoError(test, err)
182+
183+
grpcServer := &BasicGrpcServer{
184+
AvoidServing: true,
185+
EnableAll: true,
186+
LogLevelName: logLevelName,
187+
Observers: []observer.Observer{observer1},
188+
ObserverOrigin: "Test Observer origin",
189+
ObserverURL: "grpc://localhost:1234",
190+
Port: 8258,
191+
SenzingInstanceName: "Test gRPC Server",
192+
SenzingSettings: senzingsettings,
193+
}
194+
err = grpcServer.Serve(ctx)
195+
require.NoError(test, err)
196+
185197
}

grpcserver/main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ const DefaultGrpcObserverPort = "8260"
3131
var IDMessages = map[int]string{
3232
2000: "Entry: %+v",
3333
2001: "SENZING_ENGINE_CONFIGURATION_JSON: %v",
34-
2002: "Enabling all services",
34+
2002: "Enabling all services.",
3535
2003: "Server listening at %v",
36+
2004: "Serving avoided.",
3637
4001: "Call to net.Listen(tcp, %s) failed.",
3738
4002: "Call to G2diagnostic.PurgeRepository() failed.",
3839
4003: "Call to G2engine.Destroy() failed.",

main_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"os"
45
"testing"
56
)
67

@@ -9,5 +10,6 @@ import (
910
*/
1011
func TestMain(test *testing.T) {
1112
_ = test
12-
// main()
13+
os.Args = []string{"command-name", "--avoid-serving"}
14+
main()
1315
}

0 commit comments

Comments
 (0)