Skip to content

Commit

Permalink
Merge pull request #4986 from rancher-sandbox/4985-locked-field-error…
Browse files Browse the repository at this point in the history
…s-cant-block

Add the --no-modal-dialogs flag to rdctl start.
  • Loading branch information
jandubois authored Jul 6, 2023
2 parents 0a233f1 + 764fd49 commit be0c7ae
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ Electron.app.whenReady().then(async() => {
k8smanager.noModalDialogs = noModalDialogs = TransientSettings.value.noModalDialogs;
}
} catch (err) {
noModalDialogs = TransientSettings.value.noModalDialogs;
if (err instanceof LockedFieldError || err instanceof DeploymentProfileError) {
// This will end up calling `showErrorDialog(<title>, <message>, fatal=true)`
// and the `fatal` part means we're expecting the app to shutdown.
Expand Down
12 changes: 12 additions & 0 deletions bats/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ cd bats
RD_LOCATION=dist ./bats-core/bin/bats ...
```

### RD_NO_MODAL_DIALOGS

By default, bats tests are run with the `--no-modal-dialogs` option so fatal errors are written to `background.log`,
rather than appearing in a blocking modal dialog box. If you *want* those dialog boxes, you can specify

```
cd bats
RD_NO_MODAL_DIALOGS=false ./bats-core/bin/bats ...
```

The default value for this environment variable is `true`.

## Writing BATS Tests

1. Add BATS test by creating files with `.bats` extension under `./bats/tests/FOLDER_NAME`
Expand Down
7 changes: 7 additions & 0 deletions bats/tests/helpers/defaults.bash
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ capturing_logs() {
is_true "$RD_CAPTURE_LOGS"
}

########################################################################
: "${RD_NO_MODAL_DIALOGS:=true}"

suppressing_modal_dialogs() {
is_true "$RD_NO_MODAL_DIALOGS"
}

########################################################################
: "${RD_TAKE_SCREENSHOTS:=false}"

Expand Down
7 changes: 7 additions & 0 deletions bats/tests/helpers/vm.bash
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,18 @@ EOF
for arg in "${args[@]}"; do
api_args+=("$(apify_arg "$arg")")
done
if suppressing_modal_dialogs; then
# Don't apify this option
api_args+=(--no-modal-dialogs)
fi

npm run dev -- "${api_args[@]}" "$@" &
else
# Detach `rdctl start` because on Windows the process may not exit until
# Rancher Desktop itself quits.
if suppressing_modal_dialogs; then
args+=(--no-modal-dialogs)
fi
RD_TEST=bats rdctl start "${args[@]}" "$@" &
fi
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/generateCliCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class Generator {
const usageParts = [usageNote];

if (rawEnums) {
usageParts.push(`(Allowed values: [${ rawEnums.join(', ' ) }])`);
usageParts.push(`(allowed values: [${ rawEnums.join(', ' ) }])`);
}

return usageParts.join(' ').trim();
Expand Down
6 changes: 3 additions & 3 deletions src/go/rdctl/cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ is subject to change without any advance notice.

func init() {
rootCmd.AddCommand(apiCmd)
apiCmd.Flags().StringVarP(&apiSettings.Method, "method", "X", "", "Method to use")
apiCmd.Flags().StringVarP(&apiSettings.InputFile, "input", "", "", "File containing JSON payload to upload (- for standard input)")
apiCmd.Flags().StringVarP(&apiSettings.Body, "body", "b", "", "JSON payload to upload")
apiCmd.Flags().StringVarP(&apiSettings.Method, "method", "X", "", "method to use")
apiCmd.Flags().StringVarP(&apiSettings.InputFile, "input", "", "", "file containing JSON payload to upload (- for standard input)")
apiCmd.Flags().StringVarP(&apiSettings.Body, "body", "b", "", "string containing JSON payload to upload")
}

func doAPICommand(cmd *cobra.Command, args []string) error {
Expand Down
7 changes: 6 additions & 1 deletion src/go/rdctl/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ If it's running, behaves the same as 'rdctl set ...'.
}

var applicationPath string
var noModalDialogs bool

func init() {
rootCmd.AddCommand(startCmd)
options.UpdateCommonStartAndSetCommands(startCmd)
startCmd.Flags().StringVarP(&applicationPath, "path", "p", "", "Path to main executable.")
startCmd.Flags().StringVarP(&applicationPath, "path", "p", "", "path to main executable")
startCmd.Flags().BoolVarP(&noModalDialogs, "no-modal-dialogs", "", false, "avoid displaying dialog boxes")
}

/**
Expand Down Expand Up @@ -88,6 +90,9 @@ func doStartCommand(cmd *cobra.Command) error {
return fmt.Errorf("failed to locate main Rancher Desktop executable: %w\nplease retry with the --path option", err)
}
}
if noModalDialogs {
commandLineArgs = append(commandLineArgs, "--no-modal-dialogs")
}
return launchApp(applicationPath, commandLineArgs)
}

Expand Down

0 comments on commit be0c7ae

Please sign in to comment.