diff --git a/cmd/root.go b/cmd/root.go index 017228e..8305e98 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -86,7 +86,11 @@ func Execute() { } func init() { - rootCmd.PersistentFlags().Var(&rootFlags.logLevel, logLevelFlagName, common.DefaultWrapHelpString(fmt.Sprintf("Log level for additional details and debugging. Valid values: %s", strings.Join(flags.LogLevelEnum(), ", ")))) + rootCmd.PersistentFlags().Var( + &rootFlags.logLevel, + logLevelFlagName, + common.DefaultWrapHelpString(fmt.Sprintf("Log level for additional details and debugging. Valid values: %s", strings.Join(flags.LogLevelEnum(), ", "))) //nolint:lll // For readability + ) common.SetupRoot(rootCmd, "aerospike-vector-search", "0.0.0") // TODO: Handle version viper.SetEnvPrefix("ASVEC") diff --git a/cmd/utils_test.go b/cmd/utils_test.go new file mode 100644 index 0000000..53c8a84 --- /dev/null +++ b/cmd/utils_test.go @@ -0,0 +1,49 @@ +//go:build unit + +package cmd + +import ( + "asvec/cmd/flags" + "testing" + + avs "github.com/aerospike/aerospike-proximus-client-go" + "github.com/stretchr/testify/assert" +) + +func TestParseBothHostSeedsFlag(t *testing.T) { + testCases := []struct { + seeds *flags.SeedsSliceFlag + host *flags.HostPortFlag + expectedSlice avs.HostPortSlice + expectedIsLoadBalancer bool + }{ + { + &flags.SeedsSliceFlag{ + Seeds: avs.HostPortSlice{ + avs.NewHostPort("1.1.1.1", 5000, false), + }, + }, + flags.NewDefaultHostPortFlag(), + avs.HostPortSlice{ + avs.NewHostPort("1.1.1.1", 5000, false), + }, + false, + }, + { + &flags.SeedsSliceFlag{ + Seeds: avs.HostPortSlice{}, + }, + flags.NewDefaultHostPortFlag(), + avs.HostPortSlice{ + &flags.NewDefaultHostPortFlag().HostPort, + }, + true, + }, + } + + for _, tc := range testCases { + actualSlice, actualBool := parseBothHostSeedsFlag(tc.seeds, tc.host) + assert.Equal(t, tc.expectedSlice, actualSlice) + assert.Equal(t, tc.expectedIsLoadBalancer, actualBool) + } +}