From 089105e7ec2b42cb6f23d3153b1584e6baedb2f2 Mon Sep 17 00:00:00 2001 From: Jesse Schmidt Date: Thu, 13 Jun 2024 13:25:13 -0700 Subject: [PATCH] fix lint --- cmd/root.go | 6 +++++- cmd/utils_test.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 cmd/utils_test.go 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) + } +}