-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add --backend flag to skip interactive backend selection #329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3efba04
feat: add --backend flag to skip interactive backend selection
ryechezkel 0d28eb7
test: add backend flag test suite matching tenant-uuid pattern
ryechezkel 5a6e045
refactor: rename to --backend-name, skip validation, default incloud
ryechezkel d85cce1
fix: abort on empty backend selection
ryechezkel 414469b
refactor: simplify selectBackendName to early returns
ryechezkel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,102 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/spf13/viper" | ||
| "github.com/stretchr/testify/suite" | ||
| ) | ||
|
|
||
| type BackendFlagTestSuite struct { | ||
| suite.Suite | ||
| originalBackend string | ||
| } | ||
|
|
||
| func (suite *BackendFlagTestSuite) SetupTest() { | ||
| suite.originalBackend = viper.GetString(BACKEND_NAME_FLAG) | ||
| } | ||
|
|
||
| func (suite *BackendFlagTestSuite) TearDownTest() { | ||
| viper.Set(BACKEND_NAME_FLAG, suite.originalBackend) | ||
| } | ||
|
|
||
| func TestBackendFlagTestSuite(t *testing.T) { | ||
| suite.Run(t, &BackendFlagTestSuite{}) | ||
| } | ||
|
|
||
| func (suite *BackendFlagTestSuite) TestBackendFlagExists() { | ||
| flag := RootCmd.PersistentFlags().Lookup(BACKEND_NAME_FLAG) | ||
| suite.NotNil(flag, "backend flag should be registered") | ||
| suite.Equal("", flag.DefValue, "backend flag should have empty default value") | ||
| suite.Equal("backend name to use", flag.Usage, "backend flag should have correct usage description") | ||
| } | ||
|
|
||
| func (suite *BackendFlagTestSuite) TestBackendFlagConstant() { | ||
| suite.Equal("backend-name", BACKEND_NAME_FLAG) | ||
| } | ||
|
|
||
| func (suite *BackendFlagTestSuite) TestViperBindingForBackend() { | ||
| testBackend := "gcp-us-east1" | ||
| viper.Set(BACKEND_NAME_FLAG, testBackend) | ||
|
|
||
| result := viper.GetString(BACKEND_NAME_FLAG) | ||
| suite.Equal(testBackend, result) | ||
| } | ||
|
|
||
| func (suite *BackendFlagTestSuite) TestEmptyBackendFlag() { | ||
| viper.Set(BACKEND_NAME_FLAG, "") | ||
|
|
||
| result := viper.GetString(BACKEND_NAME_FLAG) | ||
| suite.Equal("", result) | ||
| } | ||
|
|
||
| func (suite *BackendFlagTestSuite) TestBackendFlagWithValidName() { | ||
| validBackend := "gcp-us-east1" | ||
| viper.Set(BACKEND_NAME_FLAG, validBackend) | ||
|
|
||
| result := viper.GetString(BACKEND_NAME_FLAG) | ||
| suite.Equal(validBackend, result) | ||
| } | ||
|
|
||
| func (suite *BackendFlagTestSuite) TestCommandsHaveAccessToBackendFlag() { | ||
| commands := []struct { | ||
| name string | ||
| cmd interface{} | ||
| }{ | ||
| {"IngestionKeyCmd", IngestionKeyCmd}, | ||
| {"getDatasourcesAPIKeyCmd", getDatasourcesAPIKeyCmd}, | ||
| {"DeployCmd", DeployCmd}, | ||
| } | ||
|
|
||
| for _, tc := range commands { | ||
| suite.Run(tc.name, func() { | ||
| flag := RootCmd.PersistentFlags().Lookup(BACKEND_NAME_FLAG) | ||
| suite.NotNil(flag, "Flag should be accessible to "+tc.name) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func (suite *BackendFlagTestSuite) TestBackendFlagPattern() { | ||
| suite.Run("flag not set - should be empty", func() { | ||
| viper.Set(BACKEND_NAME_FLAG, "") | ||
| backendName := viper.GetString(BACKEND_NAME_FLAG) | ||
|
|
||
| if backendName == "" { | ||
| suite.Empty(backendName) | ||
| } else { | ||
| suite.Fail("Expected empty backend name when flag not set") | ||
| } | ||
| }) | ||
|
|
||
| suite.Run("flag set - should use flag value", func() { | ||
| expectedBackend := "gcp-us-east1" | ||
| viper.Set(BACKEND_NAME_FLAG, expectedBackend) | ||
| backendName := viper.GetString(BACKEND_NAME_FLAG) | ||
|
|
||
| if backendName == "" { | ||
| suite.Fail("Should not be empty when flag is set") | ||
| } else { | ||
| suite.Equal(expectedBackend, backendName) | ||
| } | ||
| }) | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.