-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release-18.0] VReplication: error on vtctldclient commands w/o table…
…t types (#14294) (#14298) Signed-off-by: Matt Lord <[email protected]> Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
5cf1bd8
commit fe27a3f
Showing
4 changed files
with
99 additions
and
4 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
go/cmd/vtctldclient/command/vreplication/common/utils_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
Copyright 2023 The Vitess Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package common | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func TestParseAndValidateCreateOptions(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
setFunc func(*cobra.Command) error | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "invalid tablet type", | ||
setFunc: func(cmd *cobra.Command) error { | ||
tabletTypesFlag := cmd.Flags().Lookup("tablet-types") | ||
err := tabletTypesFlag.Value.Set("invalid") | ||
tabletTypesFlag.Changed = true | ||
return err | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "no tablet types", | ||
setFunc: func(cmd *cobra.Command) error { | ||
tabletTypesFlag := cmd.Flags().Lookup("tablet-types") | ||
err := tabletTypesFlag.Value.Set("") | ||
tabletTypesFlag.Changed = true | ||
return err | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "valid tablet types", | ||
setFunc: func(cmd *cobra.Command) error { | ||
tabletTypesFlag := cmd.Flags().Lookup("tablet-types") | ||
err := tabletTypesFlag.Value.Set("rdonly,replica") | ||
tabletTypesFlag.Changed = true | ||
return err | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
cmd := &cobra.Command{} | ||
AddCommonCreateFlags(cmd) | ||
test := func() error { | ||
if tt.setFunc != nil { | ||
if err := tt.setFunc(cmd); err != nil { | ||
return err | ||
} | ||
} | ||
if err := ParseAndValidateCreateOptions(cmd); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
if err := test(); (err != nil) != tt.wantErr { | ||
t.Errorf("ParseAndValidateCreateOptions() error = %v, wantErr %t", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters