-
Notifications
You must be signed in to change notification settings - Fork 31
feat(config): consistent CLI behaviour and e2e test coverage #801
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
Open
natalie-o-perret
wants to merge
11
commits into
master
Choose a base branch
from
natalieperret/sc-167884/feature-request-cli-consistent-behaviour
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+476
−81
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
177a7df
feat: add PTY infrastructure for testscript and fix config bugs
natalie-o-perret 89ba7cf
feat(config): consistent CLI behaviour and e2e test coverage
natalie-o-perret c4634ed
fix(config): replace AskQuestion with promptui.Prompt to fix PTY hang
natalie-o-perret bc05308
cmd/root: replace custom contains helper with slices.Contains
natalie-o-perret f48d6dd
refactor(tests): rename integration→integ, fix e2e module name and PT…
natalie-o-perret c106e11
fix(tests/e2e): simplify runInPTY - revert goroutine complexity
natalie-o-perret 056ec9c
test(e2e): replace fixed PTY keystroke sleep with output-settle wait
natalie-o-perret d8287bf
fix(config): replace promptui.Prompt in askSetDefault with plain bufi…
natalie-o-perret 6f82f2a
fix(tests/e2e): increase PTY keystroke delay to 300ms to fix CI flaki…
natalie-o-perret edeb7fb
docs(changelog): update unreleased section
natalie-o-perret c51ae1d
Merge branch 'master' into natalieperret/sc-167884/feature-request-cl…
natalie-o-perret 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
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| module github.com/exoscale/cli/internal/integ | ||
| module github.com/exoscale/cli/internal/e2e | ||
|
|
||
| go 1.23 | ||
|
|
||
|
|
||
10 changes: 10 additions & 0 deletions
10
tests/e2e/scenarios/without-api/config/add/add_cancel_during_secret.txtar
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,10 @@ | ||
| # Test cancelling during secret key prompt | ||
| # User enters API key but cancels at secret prompt | ||
|
|
||
| # Attempt to add account and cancel at secret prompt | ||
| ! execpty --stdin=inputs exo config add | ||
| stderr 'Error: Operation Cancelled' | ||
|
|
||
| -- inputs -- | ||
| EXOtest123 | ||
| @ctrl+c |
14 changes: 14 additions & 0 deletions
14
tests/e2e/scenarios/without-api/config/add/add_cancel_during_zone.txtar
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,14 @@ | ||
| # Test cancelling during zone selection | ||
| # User enters all credentials but cancels at zone selection | ||
|
|
||
| # Attempt to add account and cancel at zone selection | ||
| # Wait for zone menu to appear (let API call fail first), then cancel | ||
| ! execpty --stdin=inputs exo config add | ||
| stderr 'Error: Operation Cancelled' | ||
|
|
||
| -- inputs -- | ||
| EXOtest123 | ||
| secretTest456 | ||
| TestAccount | ||
| @down | ||
| @ctrl+c |
9 changes: 9 additions & 0 deletions
9
tests/e2e/scenarios/without-api/config/add/add_cancel_with_ctrl_d.txtar
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,9 @@ | ||
| # Test cancelling with Ctrl+D (EOF) during API key prompt | ||
| # Ctrl+D sends EOF signal which should be handled like Ctrl+C | ||
|
|
||
| # Attempt to add account and cancel with Ctrl+D | ||
| ! execpty --stdin=inputs exo config add | ||
| stderr 'Error: Operation Cancelled' | ||
|
|
||
| -- inputs -- | ||
| @ctrl+d |
39 changes: 39 additions & 0 deletions
39
tests/e2e/scenarios/without-api/config/add/add_interactive_duplicate_name.txtar
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,39 @@ | ||
| # Test: Interactive config add with duplicate name handling | ||
| # Tests that the CLI properly rejects duplicate account names and re-prompts. | ||
|
|
||
| # Create initial config with one account | ||
| mkdir -p .config/exoscale | ||
| cp initial-config.toml .config/exoscale/exoscale.toml | ||
|
|
||
| # Try to add account with duplicate name, then provide unique name | ||
| execpty --stdin=inputs exo config add | ||
| stdout 'Name \[ExistingAccount\] already exist' | ||
| stdout 'UniqueAccount' | ||
|
|
||
| # Verify the new account was added with the corrected name | ||
| exec exo config list | ||
| stdout 'ExistingAccount' | ||
| stdout 'UniqueAccount' | ||
|
|
||
| # Verify UniqueAccount was created properly | ||
| exec exo config show UniqueAccount | ||
| stdout 'UniqueAccount' | ||
| stdout 'EXOunique999' | ||
|
|
||
| -- inputs -- | ||
| EXOunique999 | ||
| secretUnique999 | ||
| ExistingAccount | ||
| UniqueAccount | ||
| @enter | ||
| n | ||
|
|
||
| -- initial-config.toml -- | ||
| defaultAccount = "ExistingAccount" | ||
|
|
||
| [[accounts]] | ||
| account = "ExistingAccount" | ||
| defaultZone = "ch-gva-2" | ||
| key = "EXOexisting456" | ||
| name = "ExistingAccount" | ||
| secret = "secretExisting456" |
28 changes: 28 additions & 0 deletions
28
tests/e2e/scenarios/without-api/config/add/add_interactive_empty_validation.txtar
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,28 @@ | ||
| # Test: Interactive config add with empty value validation | ||
| # Tests that API Key, Secret Key, and Name cannot be left empty. | ||
| # The CLI should re-prompt when empty values are submitted. | ||
|
|
||
| # Create empty config directory (simulating first-time setup) | ||
| mkdir -p .config/exoscale | ||
|
|
||
| # Run interactive config add, attempting to submit empty values first | ||
| execpty --stdin=inputs exo config add | ||
| stdout 'API Key cannot be empty' | ||
| stdout 'Secret Key cannot be empty' | ||
| stdout 'Name cannot be empty' | ||
| stdout '\[TestAccount\] as default account \(first account\)' | ||
|
|
||
| # Verify config file was created with correct content | ||
| exec exo config show | ||
| stdout 'TestAccount' | ||
| stdout 'EXOvalid123' | ||
|
|
||
| -- inputs -- | ||
| @enter | ||
| EXOvalid123 | ||
| @enter | ||
| validSecret456 | ||
| @enter | ||
| TestAccount | ||
| @down | ||
| @enter |
36 changes: 36 additions & 0 deletions
36
tests/e2e/scenarios/without-api/config/add/add_interactive_make_new_default.txtar
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,36 @@ | ||
| # Test: Interactive config add making new account the default | ||
| # Tests adding a second account and choosing to make it the new default. | ||
|
|
||
| # Create initial config with one account | ||
| mkdir -p .config/exoscale | ||
| cp initial-config.toml .config/exoscale/exoscale.toml | ||
|
|
||
| # Add second account and make it default (answer 'y' to prompt) | ||
| execpty --stdin=inputs exo config add | ||
| stdout 'Set \[NewDefault\] as default account' | ||
|
|
||
| # Verify both accounts exist | ||
| exec exo config list | ||
| stdout 'FirstAccount' | ||
| stdout 'NewDefault' | ||
|
|
||
| # Verify new account is now default | ||
| stdout 'NewDefault\*' | ||
| ! stdout 'FirstAccount\*' | ||
|
|
||
| -- inputs -- | ||
| EXOnewdefault789 | ||
| secretNew789 | ||
| NewDefault | ||
| @enter | ||
| y | ||
|
|
||
| -- initial-config.toml -- | ||
| defaultAccount = "FirstAccount" | ||
|
|
||
| [[accounts]] | ||
| account = "FirstAccount" | ||
| defaultZone = "ch-gva-2" | ||
| key = "EXOfirst123" | ||
| name = "FirstAccount" | ||
| secret = "secretFirst123" |
41 changes: 41 additions & 0 deletions
41
tests/e2e/scenarios/without-api/config/add/add_interactive_second_account.txtar
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,41 @@ | ||
| # Test: Interactive config add for second account (with default prompt) | ||
| # Tests adding a second account and being prompted whether to make it the new default. | ||
|
|
||
| # Create initial config with one account | ||
| mkdir -p .config/exoscale | ||
| cp initial-config.toml .config/exoscale/exoscale.toml | ||
|
|
||
| # Add second account interactively and decline to make it default | ||
| execpty --stdin=inputs exo config add | ||
| ! stdout 'No Exoscale CLI configuration found' | ||
|
|
||
| # Verify both accounts exist | ||
| exec exo config list | ||
| stdout 'FirstAccount' | ||
| stdout 'SecondAccount' | ||
|
|
||
| # Verify first account is still default (we answered 'n' to the prompt) | ||
| stdout 'FirstAccount\*' | ||
| ! stdout 'SecondAccount\*' | ||
|
|
||
| # Verify second account was added | ||
| exec exo config show SecondAccount | ||
| stdout 'SecondAccount' | ||
| stdout 'EXOsecond456' | ||
|
|
||
| -- inputs -- | ||
| EXOsecond456 | ||
| secretSecond456 | ||
| SecondAccount | ||
| @enter | ||
| n | ||
|
|
||
| -- initial-config.toml -- | ||
| defaultAccount = "FirstAccount" | ||
|
|
||
| [[accounts]] | ||
| account = "FirstAccount" | ||
| defaultZone = "ch-gva-2" | ||
| key = "EXOfirst123" | ||
| name = "FirstAccount" | ||
| secret = "secretFirst123" |
29 changes: 29 additions & 0 deletions
29
tests/e2e/scenarios/without-api/config/add/add_interactive_zone_navigation.txtar
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,29 @@ | ||
| # Test: Interactive config add with zone selection navigation | ||
| # Tests navigating the zone selection menu with arrow keys. | ||
|
|
||
| # Create empty config directory | ||
| mkdir -p .config/exoscale | ||
|
|
||
| # Add account and navigate down to select ch-dk-2 (second zone in typical list) | ||
| # Typical zone order: at-vie-1, at-vie-2, bg-sof-1, ch-dk-2, ch-gva-2... | ||
| execpty --stdin=inputs exo config add | ||
| stdout 'TestZoneNav' | ||
| stdout 'as default account \(first account\)' | ||
|
|
||
| # Verify the account was created | ||
| exec exo config show | ||
| stdout 'TestZoneNav' | ||
| stdout 'EXOzonetest111' | ||
|
|
||
| # Note: We can't easily verify the selected zone in non-API mode | ||
| # as the zone list requires API access. In real scenarios with API, | ||
| # this test would verify the defaultZone field in the config. | ||
|
|
||
| -- inputs -- | ||
| EXOzonetest111 | ||
| secretZone111 | ||
| TestZoneNav | ||
| @down | ||
| @down | ||
| @down | ||
| @enter |
42 changes: 42 additions & 0 deletions
42
tests/e2e/scenarios/without-api/config/commands_require_default_or_flag.txtar
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,42 @@ | ||
| # Test: Commands require default account or --use-account flag | ||
| # When config exists but no default account is set, most commands should fail | ||
| # with a helpful error message, unless --use-account flag is provided. | ||
|
|
||
| # Create config with account but NO defaultAccount field | ||
| mkdir -p .config/exoscale | ||
| cp test-config.toml .config/exoscale/exoscale.toml | ||
|
|
||
| # Config management commands work (they don't require default) | ||
| exec exo config list | ||
| stdout 'Exoscale-Test' | ||
|
|
||
| # Config show without account name or default should fail with helpful message | ||
| ! exec exo config show | ||
| stderr 'default account not defined' | ||
|
|
||
| # Non-config commands require default account | ||
| ! exec exo compute instance list | ||
| stderr 'default account not defined' | ||
| stderr 'Set a default account with: exo config set <account-name>' | ||
| stderr 'Available accounts: Exoscale-Test' | ||
|
|
||
| # Workaround 1: --use-account flag bypasses the default account requirement | ||
| exec exo --use-account Exoscale-Test config show | ||
| stdout 'Exoscale-Test' | ||
| stdout 'EXOtest123' | ||
|
|
||
| # Workaround 2: Set a default account | ||
| exec exo config set Exoscale-Test | ||
| stdout 'Default profile set to \[Exoscale-Test\]' | ||
|
|
||
| # Now commands work without flag | ||
| exec exo config show | ||
| stdout 'Exoscale-Test' | ||
|
|
||
| # Config file without defaultAccount field | ||
| -- test-config.toml -- | ||
| [[accounts]] | ||
| name = "Exoscale-Test" | ||
| key = "EXOtest123" | ||
| secret = "testsecret123" | ||
| defaultZone = "ch-gva-2" |
24 changes: 24 additions & 0 deletions
24
tests/e2e/scenarios/without-api/config/config_cancel_during_menu.txtar
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,24 @@ | ||
| # Test cancelling at config menu selection | ||
| # User has existing config, opens menu, then cancels | ||
|
|
||
| # Create existing config with one account | ||
| env HOME=$WORK | ||
| mkdir $HOME/.config/exoscale | ||
| cp test-config.toml $HOME/.config/exoscale/exoscale.toml | ||
|
|
||
| # Open config menu and cancel | ||
| ! execpty --stdin=inputs exo config | ||
| stderr 'Error: Operation Cancelled' | ||
|
|
||
| -- test-config.toml -- | ||
| defaultaccount = "test" | ||
|
|
||
| [[accounts]] | ||
| name = "test" | ||
| key = "EXOtest123" | ||
| secret = "secretTest456" | ||
| defaultzone = "ch-gva-2" | ||
|
|
||
| -- inputs -- | ||
| @down | ||
| @ctrl+c |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.Fatal may do the same behavior, except if you want this specific exitcode. If 130 is a known exit code, we may have constants somewhere to understand those exitcodes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, you're right 💭 lemme think this through.
I had some idea to have a consistent behaviour across the cli 🤔