Repository navigation
aitools: test that deprecated experimental aliases mirror stable commands #7826
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
4 commits
Select commit
Hold shift + click to select a range
36112ed
aitools: test that deprecated experimental aliases mirror stable comm…
anton-107 bb41534
aitools: move alias tests to the aitools_test package
anton-107 e5d98a4
Merge branch 'main'
anton-107 ef06027
aitools: compare inherited flags and share alias names in alias tests
anton-107 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,94 @@ | ||
| package aitools_test | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "slices" | ||
| "testing" | ||
|
|
||
| aitoolscmd "github.com/databricks/cli/cmd/aitools" | ||
| "github.com/databricks/cli/cmd/root" | ||
| aitools "github.com/databricks/cli/experimental/aitools/cmd" | ||
| "github.com/spf13/cobra" | ||
| "github.com/spf13/pflag" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func subcommand(t *testing.T, parent *cobra.Command, name string) *cobra.Command { | ||
| t.Helper() | ||
| for _, c := range parent.Commands() { | ||
| if c.Name() == name { | ||
| return c | ||
| } | ||
| } | ||
| require.FailNowf(t, "missing subcommand", "%q has no %q subcommand", parent.CommandPath(), name) | ||
| return nil | ||
| } | ||
|
|
||
| // aliasNames lists the deprecated `databricks experimental aitools <name>` | ||
| // aliases of `databricks aitools <name>`. | ||
| var aliasNames = []string{"install", "update", "uninstall", "list", "version"} | ||
|
|
||
| // newExperimentalAitoolsCmd builds the experimental aitools group under an | ||
| // `experimental` parent, so command paths in failures read "experimental aitools". | ||
| func newExperimentalAitoolsCmd() *cobra.Command { | ||
| cmd := aitools.NewAitoolsCmd() | ||
| parent := &cobra.Command{Use: "experimental"} | ||
| parent.AddCommand(cmd) | ||
| return cmd | ||
| } | ||
|
|
||
| // flagSummary lists the local and inherited flags of a command with their | ||
| // name, shorthand, type, defaults, visibility, deprecation and usage. | ||
| func flagSummary(cmd *cobra.Command) []string { | ||
| var out []string | ||
| add := func(kind string) func(f *pflag.Flag) { | ||
| return func(f *pflag.Flag) { | ||
| out = append(out, fmt.Sprintf("%s --%s -%s %s default=%q noopt=%q hidden=%t deprecated=%q: %s", | ||
| kind, f.Name, f.Shorthand, f.Value.Type(), f.DefValue, f.NoOptDefVal, f.Hidden, f.Deprecated, f.Usage)) | ||
| } | ||
| } | ||
| cmd.LocalFlags().VisitAll(add("local")) | ||
| cmd.InheritedFlags().VisitAll(add("inherited")) | ||
| slices.Sort(out) | ||
| return out | ||
| } | ||
|
|
||
| func TestExperimentalAitoolsSubcommands(t *testing.T) { | ||
| cmd := newExperimentalAitoolsCmd() | ||
| assert.True(t, cmd.Hidden) | ||
|
|
||
| var names []string | ||
| for _, c := range cmd.Commands() { | ||
| names = append(names, c.Name()) | ||
| } | ||
| slices.Sort(names) | ||
| expected := append(slices.Clone(aliasNames), "skills", "tools") | ||
| slices.Sort(expected) | ||
| assert.Equal(t, expected, names) | ||
| } | ||
|
|
||
| // TestDeprecatedAliasesMirrorStableCommands checks that each deprecated | ||
| // `databricks experimental aitools <name>` alias stays a hidden copy of | ||
| // `databricks aitools <name>` with a notice that points to the new path. | ||
| func TestDeprecatedAliasesMirrorStableCommands(t *testing.T) { | ||
| stable := root.NewCommand(t.Context(), aitoolscmd.Spec) | ||
| experimental := newExperimentalAitoolsCmd() | ||
|
|
||
| for _, name := range aliasNames { | ||
| t.Run(name, func(t *testing.T) { | ||
| s := subcommand(t, stable, name) | ||
| a := subcommand(t, experimental, name) | ||
|
|
||
| assert.True(t, a.Hidden) | ||
| assert.Equal(t, fmt.Sprintf(`use "databricks aitools %s" instead.`, name), a.Deprecated) | ||
| assert.False(t, s.Hidden) | ||
| assert.Empty(t, s.Deprecated) | ||
|
|
||
| assert.Equal(t, s.Use, a.Use) | ||
| assert.Equal(t, s.Short, a.Short) | ||
| assert.Equal(t, s.Long, a.Long) | ||
| assert.Equal(t, flagSummary(s), flagSummary(a)) | ||
| }) | ||
| } | ||
| } | ||
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.