-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(slides): normalize presentation flag aliases #2032
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
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
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,68 @@ | ||
| // Copyright (c) 2026 Lark Technologies Pte. Ltd. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package slides | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func TestWithPresentationFlagAliases(t *testing.T) { | ||
| for _, alias := range presentationFlagAliases { | ||
| t.Run(alias, func(t *testing.T) { | ||
| cmd := &cobra.Command{Use: "test"} | ||
| cmd.Flags().String("presentation", "", "presentation reference") | ||
| withPresentationFlagAliases(nil)(cmd) | ||
|
|
||
| if err := cmd.Flags().Parse([]string{"--" + alias, "presABC"}); err != nil { | ||
| t.Fatalf("--%s should resolve to --presentation: %v", alias, err) | ||
| } | ||
| got, err := cmd.Flags().GetString("presentation") | ||
| if err != nil { | ||
| t.Fatalf("read --presentation: %v", err) | ||
| } | ||
| if got != "presABC" { | ||
| t.Fatalf("--%s set --presentation to %q, want presABC", alias, got) | ||
| } | ||
| if usage := cmd.Flags().FlagUsages(); strings.Contains(usage, "--"+alias) { | ||
| t.Fatalf("hidden compatibility alias --%s leaked into help:\n%s", alias, usage) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestShortcutsAttachPresentationFlagAliases(t *testing.T) { | ||
| count := 0 | ||
| for _, shortcut := range Shortcuts() { | ||
| if !hasPresentationFlag(shortcut.Flags) { | ||
| continue | ||
| } | ||
| count++ | ||
| if shortcut.PostMount == nil { | ||
| t.Errorf("%s has --presentation but no compatibility normalizer", shortcut.Command) | ||
| continue | ||
| } | ||
|
|
||
| cmd := &cobra.Command{Use: shortcut.Command} | ||
| cmd.Flags().String("presentation", "", "presentation reference") | ||
| shortcut.PostMount(cmd) | ||
| if err := cmd.Flags().Parse([]string{"--token", "presABC"}); err != nil { | ||
| t.Errorf("%s did not normalize --token: %v", shortcut.Command, err) | ||
| continue | ||
| } | ||
| got, err := cmd.Flags().GetString("presentation") | ||
| if err != nil { | ||
| t.Errorf("%s could not read --presentation: %v", shortcut.Command, err) | ||
| continue | ||
| } | ||
| if got != "presABC" { | ||
| t.Errorf("%s normalized --token to %q, want presABC", shortcut.Command, got) | ||
| } | ||
| } | ||
| if count == 0 { | ||
| t.Fatal("expected at least one slides shortcut with --presentation") | ||
| } | ||
| } |
51 changes: 51 additions & 0 deletions
51
tests/cli_e2e/slides/slides_presentation_alias_dryrun_test.go
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,51 @@ | ||
| // Copyright (c) 2026 Lark Technologies Pte. Ltd. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package slides | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
| "time" | ||
|
|
||
| clie2e "github.com/larksuite/cli/tests/cli_e2e" | ||
| "github.com/stretchr/testify/require" | ||
| "github.com/tidwall/gjson" | ||
| ) | ||
|
|
||
| func TestSlidesPresentationAliasesDryRunE2E(t *testing.T) { | ||
| setSlidesDryRunEnv(t) | ||
|
|
||
| ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
| t.Cleanup(cancel) | ||
|
|
||
| aliases := []string{ | ||
| "presentation-id", | ||
| "presentation-token", | ||
| "token", | ||
| "presentation_id", | ||
| "xml-presentation-id", | ||
| "url", | ||
| } | ||
| for _, alias := range aliases { | ||
| t.Run(alias, func(t *testing.T) { | ||
| result, err := clie2e.RunCmd(ctx, clie2e.Request{ | ||
| Args: []string{ | ||
| "slides", "+xml-get", | ||
| "--" + alias, "presAliasDryRun", | ||
| "--dry-run", | ||
| }, | ||
| DefaultAs: "bot", | ||
| }) | ||
| require.NoError(t, err) | ||
| result.AssertExitCode(t, 0) | ||
|
|
||
| require.Equal(t, "GET", gjson.Get(result.Stdout, "data.api.0.method").String(), result.Stdout) | ||
| require.Equal(t, | ||
| "/open-apis/slides_ai/v1/xml_presentations/presAliasDryRun", | ||
| gjson.Get(result.Stdout, "data.api.0.url").String(), | ||
| result.Stdout, | ||
| ) | ||
| }) | ||
| } | ||
|
fangshuyu-768 marked this conversation as resolved.
|
||
| } | ||
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.