From f2d98eee2a238f6c4d5728239482a4a530add350 Mon Sep 17 00:00:00 2001 From: Jesse S Date: Tue, 1 Oct 2024 15:32:23 -0700 Subject: [PATCH] test: Add more test coverage (#15) --- cmd/nodeList.go | 9 ----- cmd/rolesList.go | 9 ----- cmd/userList.go | 9 ----- e2e_test.go | 96 +++++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 91 insertions(+), 32 deletions(-) diff --git a/cmd/nodeList.go b/cmd/nodeList.go index ab2e3ae..a8df335 100644 --- a/cmd/nodeList.go +++ b/cmd/nodeList.go @@ -37,8 +37,6 @@ func newNodeListFlagSet() *pflag.FlagSet { return flagSet } -var nodeListRequiredFlags = []string{} - // nodeListCmd creates a new cobra command for listing nodes. func newNodeListCmd() *cobra.Command { return &cobra.Command{ @@ -318,11 +316,4 @@ func init() { nodeCmd.AddCommand(nodeListCmd) nodeListCmd.Flags().AddFlagSet(newNodeListFlagSet()) - - for _, flag := range nodeListRequiredFlags { - err := nodeListCmd.MarkFlagRequired(flag) - if err != nil { - panic(err) - } - } } diff --git a/cmd/rolesList.go b/cmd/rolesList.go index 5c745ec..4f4c214 100644 --- a/cmd/rolesList.go +++ b/cmd/rolesList.go @@ -28,8 +28,6 @@ func newRoleListFlagSet() *pflag.FlagSet { return flagSet } -var roleListRequiredFlags = []string{} - // listIndexCmd represents the listIndex command func newRoleListCmd() *cobra.Command { return &cobra.Command{ @@ -80,11 +78,4 @@ func init() { roleCmd.AddCommand(roleListCmd) roleListCmd.Flags().AddFlagSet(newRoleListFlagSet()) - - for _, flag := range roleListRequiredFlags { - err := roleListCmd.MarkFlagRequired(flag) - if err != nil { - panic(err) - } - } } diff --git a/cmd/userList.go b/cmd/userList.go index bafe42c..41088ef 100644 --- a/cmd/userList.go +++ b/cmd/userList.go @@ -30,8 +30,6 @@ func newUserListFlagSet() *pflag.FlagSet { return flagSet } -var userListRequiredFlags = []string{} - // listIndexCmd represents the listIndex command func newUserListCmd() *cobra.Command { return &cobra.Command{ @@ -86,11 +84,4 @@ func init() { userCmd.AddCommand(userListCmd) userListCmd.Flags().AddFlagSet(newUserListFlagSet()) - - for _, flag := range userListRequiredFlags { - err := userListCmd.MarkFlagRequired(flag) - if err != nil { - panic(err) - } - } } diff --git a/e2e_test.go b/e2e_test.go index 018e5c9..609f119 100644 --- a/e2e_test.go +++ b/e2e_test.go @@ -1019,10 +1019,10 @@ func (suite *CmdTestSuite) TestSuccessfulUsersNewPasswordCmd() { suite.SkipIfUserPassAuthDisabled() testCases := []struct { - name string // name of the test case - user string // username of the user - newPassword string // new password for the user - cmd string // command to be executed + name string + user string + newPassword string + cmd string }{ { name: "change password", @@ -1062,6 +1062,35 @@ func (suite *CmdTestSuite) TestSuccessfulUsersNewPasswordCmd() { } } +func (suite *CmdTestSuite) TestFailUsersNewPasswordCmd() { + // If the user DNE it will not fail. Only fails if auth is disabled. + if suite.AvsCreds != nil { + suite.T().Skip("authentication is enabled. skipping test") + } + + testCases := []struct { + name string + user string + newPassword string + cmd string + }{ + { + name: "change password with invalid user", + user: "DNE", + newPassword: "foo", + cmd: "users new-password --name DNE --new-password foo", + }, + } + + for _, tc := range testCases { + suite.Run(tc.name, func() { + _, stderr, err := suite.RunSuiteCmd(strings.Split(tc.cmd, " ")...) + suite.Assert().Error(err, "error: %s, stdout: %s stderr:%s", err, stderr, stderr) + suite.Assert().Contains(stderr, "server error") + }) + } +} + func (suite *CmdTestSuite) TestSuccessfulListUsersCmd() { suite.SkipIfUserPassAuthDisabled() @@ -1115,6 +1144,7 @@ func (suite *CmdTestSuite) TestSuccessfulQueryCmd() { suite.CleanUpIndexes(context.Background()) strIndexName := "query-str-index" intIndexName := "query-int-index" + boolIndexName := "query-bool-index" indexes := []*protos.IndexDefinition{ tests.NewIndexDefinitionBuilder(false, strIndexName, "test", 10, protos.VectorDistanceMetric_SQUARED_EUCLIDEAN, "float32-str", @@ -1122,6 +1152,9 @@ func (suite *CmdTestSuite) TestSuccessfulQueryCmd() { tests.NewIndexDefinitionBuilder(false, intIndexName, "test", 10, protos.VectorDistanceMetric_SQUARED_EUCLIDEAN, "float32-int", ).Build(), + tests.NewIndexDefinitionBuilder(false, + boolIndexName, "test", 10, protos.VectorDistanceMetric_SQUARED_EUCLIDEAN, "bool", + ).Build(), } for _, index := range indexes { @@ -1273,6 +1306,24 @@ func (suite *CmdTestSuite) TestSuccessfulQueryCmd() { "float32-int": getVectorFloat32(10, 9.0), }, }, + { + key: 10, + data: map[string]any{ + "bool": getVectorBool(10, 7.0), + }, + }, + { + key: 11, + data: map[string]any{ + "bool": getVectorBool(10, 8.0), + }, + }, + { + key: 12, + data: map[string]any{ + "bool": getVectorBool(10, 9.0), + }, + }, } for _, record := range records { @@ -1288,6 +1339,7 @@ func (suite *CmdTestSuite) TestSuccessfulQueryCmd() { suite.AvsClient.WaitForIndexCompletion(context.Background(), "test", strIndexName, 12*time.Second) suite.AvsClient.WaitForIndexCompletion(context.Background(), "test", intIndexName, 12*time.Second) + suite.AvsClient.WaitForIndexCompletion(context.Background(), "test", boolIndexName, 12*time.Second) testCases := []struct { name string @@ -1315,7 +1367,7 @@ float32-str\,\"[0.0\\,0.0\\,0.0\\,0.0\\,0.0\\,0.0\\,0.0\\,0.0\\,0.0\\,2.0]\"" `, }, { - name: "run query with custom vector", + name: "run query with custom float32 vector", records: records, cmd: fmt.Sprintf("query -i %s -n test --vector [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0] --no-color --format 1", strIndexName), expectedTable: `Query Results @@ -1337,6 +1389,35 @@ float32-str\,\"[0.0\\,0.0\\,0.0\\,0.0\\,0.0\\,0.0\\,0.0\\,0.0\\,0.0\\,3.0]\"" float32-str\,\"[0.0\\,0.0\\,0.0\\,0.0\\,0.0\\,0.0\\,0.0\\,0.0\\,0.0\\,4.0]\"" Hint: To increase the number of records returned, use the --max-results flag. Hint: To choose which record keys are displayed, use the --fields flag. By default only 5 are displayed. +`, + }, + { + name: "run query with custom bool vector", + records: records, + cmd: fmt.Sprintf("query -i %s -n test --vector [0,0,0,0,0,0,0,0,0,1] --no-color --format 1", boolIndexName), + expectedTable: `Query Results +,Namespace,Key,Distance,Generation,Data +1,test,10,8,0,"Key\,Value +bool\,\"[1\\,1\\,1\\,1\\,1\\,1\\,1\\,0\\,0\\,0]\"" +2,test,11,9,0,"Key\,Value +bool\,\"[1\\,1\\,1\\,1\\,1\\,1\\,1\\,1\\,0\\,0]\"" +3,test,12,10,0,"Key\,Value +bool\,\"[1\\,1\\,1\\,1\\,1\\,1\\,1\\,1\\,1\\,0]\"" +Hint: To increase the number of records returned, use the --max-results flag. +Hint: To choose which record keys are displayed, use the --fields flag. By default only 5 are displayed. +`, + }, { + name: "run query with using int key with bool vector", + records: records, + cmd: fmt.Sprintf("query -i %s -n test --key-int 10 --no-color --format 1", boolIndexName), + expectedTable: `Query Results +,Namespace,Key,Distance,Generation,Data +1,test,11,1,0,"Key\,Value +bool\,\"[1\\,1\\,1\\,1\\,1\\,1\\,1\\,1\\,0\\,0]\"" +2,test,12,2,0,"Key\,Value +bool\,\"[1\\,1\\,1\\,1\\,1\\,1\\,1\\,1\\,1\\,0]\"" +Hint: To increase the number of records returned, use the --max-results flag. +Hint: To choose which record keys are displayed, use the --fields flag. By default only 5 are displayed. `, }, { @@ -1469,6 +1550,11 @@ func (suite *CmdTestSuite) TestFailedQueryCmd() { cmd: fmt.Sprintf("query --namespace %s -i %s --key-int 1 --vector [0,1,1,1]", namespace, indexName), expectedErrStr: "Error: if any flags in the group [vector key-str key-int] are set none of the others can be; [key-int vector] were all set", }, + { + name: "query using key-int and vector together", + cmd: fmt.Sprintf("query --namespace %s -i %s --vector [0,1,1,1]", namespace, indexName), + expectedErrStr: "Error: Failed to get vector using vector: failed to receive all neighbors: rpc error: code = InvalidArgument desc = dimension mismatch, required 10, actual 4", + }, } for _, tc := range testCases {