diff --git a/.github/merge_request_template/Default.md b/.github/merge_request_template/Default.md index 49c4a369ee..d49cae2414 100644 --- a/.github/merge_request_template/Default.md +++ b/.github/merge_request_template/Default.md @@ -12,10 +12,8 @@ ## PR Author Check List -* [ ] All commit messages adhere to the project [standard](https://github.com/openshift/rosa/blob/master/CONTRIBUTING.md) - +* [ ] All commit messages adhere to the project [standard](https://github.com/openshift/rosa/blob/master/CONTRIBUTING.md) +* [ ] All code aligns with the [Style Guide](../../CONTRIBUTING.md#style-guide) * [ ] All commits are squashed into a single commit `git rebase -i HEAD~` - * [ ] All code changes have unit test coverage - * [ ] All changes have been tested locally and the steps documented in the `How to Test?` section diff --git a/.gitignore b/.gitignore index 5ab65cc310..94f3e27c93 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ .idea/ .vscode/ -docs/ +/docs /rosa /rosa-darwin-amd64 /rosa-darwin-amd64.sha256 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0b7506e01f..ae61db94ab 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -83,15 +83,36 @@ configured in https://github.com/openshift/release repo. `.golangciversion` file is read by the `lint` job commands there: https://github.com/openshift/release/blob/master/ci-operator/config/openshift/rosa/openshift-rosa-master.yaml -## Contributing and Error Handling in Cobra +# Style Guide -1. If you are contributing code, please ensure that you are handling errors - properly. Please use `Run: run` instead of `RunE: runE` when writing commands, - in order to stop the **usage info** being printed when an error is returned. +## Adding a New Command + +### Add your Command to expected CLI Structure + +We automatically test the structure of the ROSA CLI to ensure commands and command flags are not accidentally added or removed. +When you first create a new command, the test suite will fail because of this. -## GitHub Workflows +You need to add your command to the following file [command_structure](cmd/rosa/structure_test/command_structure.yml) in the correct +location within the command tree in order for this test to pass. -This repository also uses GitHub actions which are configured at `./github/workflows` +You additionally need to create a directory under the [command_args](cmd/rosa/structure_test/command_args) sub-directory +and create a file called `command_args.yml`. This file should contain a simple yaml list of the `flags` supported by your command. +For example, a command with flag `foo`, `bar`, `bob` would have the following `command_args.yml`: + +```yaml +- name: foo +- name: bar +- name: bob +``` + +## Error Handling in Commands + +If you are contributing code, please ensure that you are handling errors properly. You should +not call `os.Exit()` in your Command (there is a significant amount of this in our code which we +are working to remove) + +Please use `Run: run` instead of `RunE: runE` when writing commands, + in order to stop the **usage info** being printed when an error is returned. ## Version-gating a feature diff --git a/cmd/rosa/main_test.go b/cmd/rosa/main_test.go index 354fe76a09..461e0bb19e 100644 --- a/cmd/rosa/main_test.go +++ b/cmd/rosa/main_test.go @@ -1,12 +1,16 @@ package main import ( - "fmt" + "os" + "path/filepath" + "strings" "testing" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/spf13/cobra" + + . "github.com/openshift/rosa/pkg/test" ) func TestCommandStructure(t *testing.T) { @@ -14,26 +18,84 @@ func TestCommandStructure(t *testing.T) { RunSpecs(t, "rosa command structure") } +const ( + structureTestDirectory = "./structure_test" +) + var _ = Describe("ROSA Commands", func() { It("Have all basic fields defined correctly", func() { assertCommand(root) }) + + It("Are correctly registered in the command structure", func() { + /* + Validates the command structure of the CLI at build time. New commands should be + added to command_structure.yml in order for this test to pass. + */ + structureVerifier := NewStructureVerifier(structureTestDirectory, root) + structureVerifier.AssertCommandStructure() + }) + + It("Have all command flags correctly registered", func() { + /* + Validates all command flags are in command_args.yml for each command. New flags should + be added to the correct command_args.yml file. + */ + assertCommandArgs(root) + }) + + XIt("Re-generates the command_arg directory structure and files", func() { + /* + This test can be used to regenerate the structure_test/command_args directory and files. + It should remain skipped for CI. + */ + generateCommandArgsFiles(root) + }) }) +func assertCommandArgs(command *cobra.Command) { + if len(command.Commands()) == 0 { + verifier := NewArgVerifier(structureTestDirectory, command) + verifier.AssertCommandArgs() + } else { + for _, c := range command.Commands() { + assertCommandArgs(c) + } + } +} + +func generateCommandArgsFiles(command *cobra.Command) { + cmdPath := filepath.Join(strings.Split(command.CommandPath(), " ")...) + dirPath := filepath.Join(structureTestDirectory, CommandArgDirectoryName, cmdPath) + _, err := os.Stat(dirPath) + if os.IsNotExist(err) { + Expect(os.MkdirAll(dirPath, 0600)).To(Succeed()) + } + + if len(command.Commands()) != 0 { + for _, c := range command.Commands() { + generateCommandArgsFiles(c) + } + } else { + generator := NewArgGenerator(filepath.Join(dirPath, CommandArgFileName), command) + generator.GenerateArgsFile() + } +} + func assertCommand(command *cobra.Command) { - Expect(command.Use).NotTo(BeNil(), fmt.Sprintf("Use cannot be nil on command '%s'", command.CommandPath())) + Expect(command.Use).NotTo(BeNil(), "Use cannot be nil on command '%s'", command.CommandPath()) Expect(command.Short).NotTo( - BeNil(), fmt.Sprintf("Short description is not set on command '%s'", command.CommandPath())) + BeNil(), "Short description is not set on command '%s'", command.CommandPath()) Expect(command.Long).NotTo( - BeNil(), fmt.Sprintf("Long description is not set on command '%s'", command.CommandPath())) + BeNil(), "Long description is not set on command '%s'", command.CommandPath()) Expect(command.Example).NotTo( - BeNil(), fmt.Sprintf("Example is not set on command '%s'", command.CommandPath())) + BeNil(), "Example is not set on command '%s'", command.CommandPath()) Expect(command.Args).NotTo( - BeNil(), fmt.Sprintf("command.Args function is not set on command '%s'", command.CommandPath())) + BeNil(), "command.Args function is not set on command '%s'", command.CommandPath()) if len(command.Commands()) == 0 { Expect(command.Run).NotTo( - BeNil(), fmt.Sprintf("The run function is not defined on command '%s'", command.CommandPath())) + BeNil(), "The run function is not defined on command '%s'", command.CommandPath()) } else { for _, c := range command.Commands() { assertCommand(c) diff --git a/cmd/rosa/structure_test/command_args/rosa/attach/policy/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/attach/policy/command_args.yml new file mode 100644 index 0000000000..691baa90b8 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/attach/policy/command_args.yml @@ -0,0 +1,3 @@ +- name: mode +- name: policy-arns +- name: role-name diff --git a/cmd/rosa/structure_test/command_args/rosa/completion/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/completion/command_args.yml new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/completion/command_args.yml @@ -0,0 +1 @@ +[] diff --git a/cmd/rosa/structure_test/command_args/rosa/config/get/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/config/get/command_args.yml new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/config/get/command_args.yml @@ -0,0 +1 @@ +[] diff --git a/cmd/rosa/structure_test/command_args/rosa/config/set/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/config/set/command_args.yml new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/config/set/command_args.yml @@ -0,0 +1 @@ +[] diff --git a/cmd/rosa/structure_test/command_args/rosa/create/account-roles/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/create/account-roles/command_args.yml new file mode 100644 index 0000000000..ac0cf68917 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/create/account-roles/command_args.yml @@ -0,0 +1,15 @@ +- name: channel-group +- name: classic +- name: force-policy-creation +- name: hosted-cp +- name: interactive +- name: managed-policies +- name: mode +- name: mp +- name: path +- name: permissions-boundary +- name: prefix +- name: profile +- name: region +- name: version +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/create/admin/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/create/admin/command_args.yml new file mode 100644 index 0000000000..6b97b6244d --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/create/admin/command_args.yml @@ -0,0 +1,6 @@ +- name: cluster +- name: output +- name: password +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/create/autoscaler/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/create/autoscaler/command_args.yml new file mode 100644 index 0000000000..b63f61c9e7 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/create/autoscaler/command_args.yml @@ -0,0 +1,25 @@ +- name: cluster +- name: interactive +- name: balance-similar-node-groups +- name: skip-nodes-with-local-storage +- name: log-verbosity +- name: max-pod-grace-period +- name: pod-priority-threshold +- name: ignore-daemonsets-utilization +- name: max-node-provision-time +- name: balancing-ignored-labels +- name: max-nodes-total +- name: min-cores +- name: max-cores +- name: min-memory +- name: max-memory +- name: gpu-limit +- name: scale-down-enabled +- name: scale-down-unneeded-time +- name: scale-down-utilization-threshold +- name: scale-down-delay-after-add +- name: scale-down-delay-after-delete +- name: scale-down-delay-after-failure +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/create/break-glass-credential/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/create/break-glass-credential/command_args.yml new file mode 100644 index 0000000000..db1ec1f415 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/create/break-glass-credential/command_args.yml @@ -0,0 +1,7 @@ +- name: cluster +- name: expiration +- name: interactive +- name: profile +- name: region +- name: username +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/create/cluster/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/create/cluster/command_args.yml new file mode 100644 index 0000000000..220beae5aa --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/create/cluster/command_args.yml @@ -0,0 +1,102 @@ +- name: name +- name: cluster-name +- name: domain-prefix +- name: sts +- name: non-sts +- name: mint-mode +- name: role-arn +- name: external-id +- name: support-role-arn +- name: controlplane-iam-role-arn +- name: master-iam-role +- name: worker-iam-role-arn +- name: operator-iam-roles +- name: operator-roles-prefix +- name: oidc-config-id +- name: classic-oidc-config +- name: external-auth-providers-enabled +- name: tags +- name: multi-az +- name: region +- name: version +- name: channel-group +- name: flavour +- name: etcd-encryption +- name: fips +- name: http-proxy +- name: https-proxy +- name: no-proxy +- name: additional-trust-bundle-file +- name: additional-allowed-principals +- name: enable-customer-managed-key +- name: kms-key-arn +- name: etcd-encryption-kms-arn +- name: expiration-time +- name: expiration +- name: private-link +- name: ec2-metadata-http-tokens +- name: subnet-ids +- name: availability-zones +- name: compute-machine-type +- name: compute-nodes +- name: replicas +- name: enable-autoscaling +- name: autoscaler-balance-similar-node-groups +- name: autoscaler-skip-nodes-with-local-storage +- name: autoscaler-log-verbosity +- name: autoscaler-max-pod-grace-period +- name: autoscaler-pod-priority-threshold +- name: autoscaler-ignore-daemonsets-utilization +- name: autoscaler-max-node-provision-time +- name: autoscaler-balancing-ignored-labels +- name: autoscaler-max-nodes-total +- name: autoscaler-min-cores +- name: autoscaler-max-cores +- name: autoscaler-min-memory +- name: autoscaler-max-memory +- name: autoscaler-gpu-limit +- name: autoscaler-scale-down-enabled +- name: autoscaler-scale-down-unneeded-time +- name: autoscaler-scale-down-utilization-threshold +- name: autoscaler-scale-down-delay-after-add +- name: autoscaler-scale-down-delay-after-delete +- name: autoscaler-scale-down-delay-after-failure +- name: min-replicas +- name: max-replicas +- name: worker-mp-labels +- name: network-type +- name: machine-cidr +- name: service-cidr +- name: pod-cidr +- name: host-prefix +- name: private +- name: disable-scp-checks +- name: disable-workload-monitoring +- name: watch +- name: dry-run +- name: fake-cluster +- name: properties +- name: use-local-credentials +- name: permissions-boundary +- name: hosted-cp +- name: worker-disk-size +- name: billing-account +- name: create-admin-user +- name: no-cni +- name: cluster-admin-user +- name: cluster-admin-password +- name: audit-log-arn +- name: default-ingress-route-selector +- name: default-ingress-excluded-namespaces +- name: default-ingress-wildcard-policy +- name: default-ingress-namespace-ownership-policy +- name: private-hosted-zone-id +- name: shared-vpc-role-arn +- name: base-domain +- name: additional-compute-security-group-ids +- name: additional-infra-security-group-ids +- name: additional-control-plane-security-group-ids +- name: mode +- name: interactive +- name: output +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/create/dns-domain/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/create/dns-domain/command_args.yml new file mode 100644 index 0000000000..04d77516ed --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/create/dns-domain/command_args.yml @@ -0,0 +1,3 @@ +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/create/external-auth-provider/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/create/external-auth-provider/command_args.yml new file mode 100644 index 0000000000..550c8e4441 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/create/external-auth-provider/command_args.yml @@ -0,0 +1,14 @@ +- name: claim-mapping-groups-claim +- name: claim-mapping-username-claim +- name: claim-validation-rule +- name: cluster +- name: console-client-id +- name: console-client-secret +- name: interactive +- name: issuer-audiences +- name: issuer-ca-file +- name: issuer-url +- name: name +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/create/idp/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/create/idp/command_args.yml new file mode 100644 index 0000000000..63c3a76d8f --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/create/idp/command_args.yml @@ -0,0 +1,34 @@ +- name: cluster +- name: type +- name: name +- name: mapping-method +- name: client-id +- name: client-secret +- name: ca +- name: hostname +- name: organizations +- name: teams +- name: host-url +- name: hosted-domain +- name: url +- name: insecure +- name: bind-dn +- name: bind-password +- name: id-attributes +- name: username-attributes +- name: name-attributes +- name: email-attributes +- name: issuer-url +- name: email-claims +- name: name-claims +- name: username-claims +- name: groups-claims +- name: extra-scopes +- name: username +- name: password +- name: users +- name: from-file +- name: interactive +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/create/kubeletconfig/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/create/kubeletconfig/command_args.yml new file mode 100644 index 0000000000..1907b472d8 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/create/kubeletconfig/command_args.yml @@ -0,0 +1,7 @@ +- name: pod-pids-limit +- name: name +- name: cluster +- name: interactive +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/create/machinepool/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/create/machinepool/command_args.yml new file mode 100644 index 0000000000..92b1698f26 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/create/machinepool/command_args.yml @@ -0,0 +1,27 @@ +- name: additional-security-group-ids +- name: autorepair +- name: availability-zone +- name: cluster +- name: disk-size +- name: enable-autoscaling +- name: instance-type +- name: interactive +- name: kubelet-configs +- name: labels +- name: max-replicas +- name: max-surge +- name: max-unavailable +- name: min-replicas +- name: multi-availability-zone +- name: name +- name: node-drain-grace-period +- name: output +- name: replicas +- name: spot-max-price +- name: subnet +- name: tags +- name: taints +- name: tuning-configs +- name: use-spot-instances +- name: version +- name: ec2-metadata-http-tokens diff --git a/cmd/rosa/structure_test/command_args/rosa/create/managed-service/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/create/managed-service/command_args.yml new file mode 100644 index 0000000000..2ca1c06c51 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/create/managed-service/command_args.yml @@ -0,0 +1,10 @@ +- name: type +- name: name +- name: subnet-ids +- name: private-link +- name: machine-cidr +- name: service-cidr +- name: pod-cidr +- name: host-prefix +- name: fake-cluster +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/create/ocm-role/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/create/ocm-role/command_args.yml new file mode 100644 index 0000000000..d6c5d49319 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/create/ocm-role/command_args.yml @@ -0,0 +1,11 @@ +- name: admin +- name: interactive +- name: managed-policies +- name: mode +- name: mp +- name: path +- name: permissions-boundary +- name: prefix +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/create/oidc-config/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/create/oidc-config/command_args.yml new file mode 100644 index 0000000000..5914350a6b --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/create/oidc-config/command_args.yml @@ -0,0 +1,9 @@ +- name: interactive +- name: managed +- name: mode +- name: output +- name: prefix +- name: raw-files +- name: region +- name: role-arn +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/create/oidc-provider/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/create/oidc-provider/command_args.yml new file mode 100644 index 0000000000..0c4a36dbdd --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/create/oidc-provider/command_args.yml @@ -0,0 +1,7 @@ +- name: cluster +- name: interactive +- name: mode +- name: oidc-config-id +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/create/operator-roles/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/create/operator-roles/command_args.yml new file mode 100644 index 0000000000..0ff466b50f --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/create/operator-roles/command_args.yml @@ -0,0 +1,14 @@ +- name: channel-group +- name: cluster +- name: force-policy-creation +- name: hosted-cp +- name: interactive +- name: mode +- name: oidc-config-id +- name: permissions-boundary +- name: prefix +- name: profile +- name: region +- name: role-arn +- name: shared-vpc-role-arn +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/create/tuning-configs/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/create/tuning-configs/command_args.yml new file mode 100644 index 0000000000..be2f9f9681 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/create/tuning-configs/command_args.yml @@ -0,0 +1,7 @@ +- name: cluster +- name: interactive +- name: name +- name: profile +- name: region +- name: spec-path +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/create/user-role/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/create/user-role/command_args.yml new file mode 100644 index 0000000000..aeb2a7e72a --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/create/user-role/command_args.yml @@ -0,0 +1,8 @@ +- name: interactive +- name: mode +- name: path +- name: permissions-boundary +- name: prefix +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/delete/account-roles/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/delete/account-roles/command_args.yml new file mode 100644 index 0000000000..e2077fed03 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/delete/account-roles/command_args.yml @@ -0,0 +1,7 @@ +- name: classic +- name: hosted-cp +- name: mode +- name: prefix +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/delete/admin/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/delete/admin/command_args.yml new file mode 100644 index 0000000000..a7374822d3 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/delete/admin/command_args.yml @@ -0,0 +1,4 @@ +- name: cluster +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/delete/autoscaler/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/delete/autoscaler/command_args.yml new file mode 100644 index 0000000000..a7374822d3 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/delete/autoscaler/command_args.yml @@ -0,0 +1,4 @@ +- name: cluster +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/delete/cluster/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/delete/cluster/command_args.yml new file mode 100644 index 0000000000..ac00ea4476 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/delete/cluster/command_args.yml @@ -0,0 +1,6 @@ +- name: cluster +- name: best-effort +- name: watch +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/delete/dns-domain/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/delete/dns-domain/command_args.yml new file mode 100644 index 0000000000..04d77516ed --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/delete/dns-domain/command_args.yml @@ -0,0 +1,3 @@ +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/delete/external-auth-provider/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/delete/external-auth-provider/command_args.yml new file mode 100644 index 0000000000..a7374822d3 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/delete/external-auth-provider/command_args.yml @@ -0,0 +1,4 @@ +- name: cluster +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/delete/idp/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/delete/idp/command_args.yml new file mode 100644 index 0000000000..a7374822d3 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/delete/idp/command_args.yml @@ -0,0 +1,4 @@ +- name: cluster +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/delete/ingress/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/delete/ingress/command_args.yml new file mode 100644 index 0000000000..666ecda0a6 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/delete/ingress/command_args.yml @@ -0,0 +1 @@ +- name: cluster diff --git a/cmd/rosa/structure_test/command_args/rosa/delete/kubeletconfig/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/delete/kubeletconfig/command_args.yml new file mode 100644 index 0000000000..7d72fadf7c --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/delete/kubeletconfig/command_args.yml @@ -0,0 +1,5 @@ +- name: cluster +- name: "yes" +- name: name +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/delete/machinepool/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/delete/machinepool/command_args.yml new file mode 100644 index 0000000000..b2739a8f2e --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/delete/machinepool/command_args.yml @@ -0,0 +1,5 @@ +- name: cluster +- name: machinepool +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/delete/managed-service/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/delete/managed-service/command_args.yml new file mode 100644 index 0000000000..839c823989 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/delete/managed-service/command_args.yml @@ -0,0 +1,4 @@ +- name: id +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/delete/ocm-role/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/delete/ocm-role/command_args.yml new file mode 100644 index 0000000000..c38d8dde5d --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/delete/ocm-role/command_args.yml @@ -0,0 +1,6 @@ +- name: interactive +- name: mode +- name: profile +- name: region +- name: role-arn +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/delete/oidc-config/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/delete/oidc-config/command_args.yml new file mode 100644 index 0000000000..552e4a5a5b --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/delete/oidc-config/command_args.yml @@ -0,0 +1,4 @@ +- name: interactive +- name: mode +- name: oidc-config-id +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/delete/oidc-provider/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/delete/oidc-provider/command_args.yml new file mode 100644 index 0000000000..ff9ac5b63f --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/delete/oidc-provider/command_args.yml @@ -0,0 +1,6 @@ +- name: cluster +- name: mode +- name: oidc-config-id +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/delete/operator-roles/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/delete/operator-roles/command_args.yml new file mode 100644 index 0000000000..e8572f64ce --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/delete/operator-roles/command_args.yml @@ -0,0 +1,6 @@ +- name: cluster +- name: mode +- name: prefix +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/delete/tuning-configs/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/delete/tuning-configs/command_args.yml new file mode 100644 index 0000000000..a7374822d3 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/delete/tuning-configs/command_args.yml @@ -0,0 +1,4 @@ +- name: cluster +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/delete/upgrade/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/delete/upgrade/command_args.yml new file mode 100644 index 0000000000..73a5adc74c --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/delete/upgrade/command_args.yml @@ -0,0 +1,5 @@ +- name: cluster +- name: machinepool +- name: "yes" +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/delete/user-role/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/delete/user-role/command_args.yml new file mode 100644 index 0000000000..c38d8dde5d --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/delete/user-role/command_args.yml @@ -0,0 +1,6 @@ +- name: interactive +- name: mode +- name: profile +- name: region +- name: role-arn +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/describe/addon-installation/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/describe/addon-installation/command_args.yml new file mode 100644 index 0000000000..c49ca5b6b2 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/describe/addon-installation/command_args.yml @@ -0,0 +1,4 @@ +- name: addon +- name: cluster +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/describe/addon/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/describe/addon/command_args.yml new file mode 100644 index 0000000000..5f15db9074 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/describe/addon/command_args.yml @@ -0,0 +1,2 @@ +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/describe/admin/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/describe/admin/command_args.yml new file mode 100644 index 0000000000..342b613595 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/describe/admin/command_args.yml @@ -0,0 +1,3 @@ +- name: cluster +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/describe/autoscaler/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/describe/autoscaler/command_args.yml new file mode 100644 index 0000000000..802bb434ed --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/describe/autoscaler/command_args.yml @@ -0,0 +1,2 @@ +- name: cluster +- name: output diff --git a/cmd/rosa/structure_test/command_args/rosa/describe/break-glass-credential/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/describe/break-glass-credential/command_args.yml new file mode 100644 index 0000000000..f134e49295 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/describe/break-glass-credential/command_args.yml @@ -0,0 +1,6 @@ +- name: cluster +- name: output +- name: id +- name: kubeconfig +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/describe/cluster/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/describe/cluster/command_args.yml new file mode 100644 index 0000000000..c0e8ec8612 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/describe/cluster/command_args.yml @@ -0,0 +1,5 @@ +- name: cluster +- name: get-role-policy-bindings +- name: output +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/describe/external-auth-provider/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/describe/external-auth-provider/command_args.yml new file mode 100644 index 0000000000..c60887a9f8 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/describe/external-auth-provider/command_args.yml @@ -0,0 +1,5 @@ +- name: cluster +- name: output +- name: name +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/describe/ingress/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/describe/ingress/command_args.yml new file mode 100644 index 0000000000..bbdc73e244 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/describe/ingress/command_args.yml @@ -0,0 +1,5 @@ +- name: cluster +- name: ingress +- name: output +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/describe/kubeletconfig/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/describe/kubeletconfig/command_args.yml new file mode 100644 index 0000000000..c60887a9f8 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/describe/kubeletconfig/command_args.yml @@ -0,0 +1,5 @@ +- name: cluster +- name: output +- name: name +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/describe/machinepool/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/describe/machinepool/command_args.yml new file mode 100644 index 0000000000..780b0b47b5 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/describe/machinepool/command_args.yml @@ -0,0 +1,5 @@ +- name: cluster +- name: machinepool +- name: output +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/describe/managed-service/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/describe/managed-service/command_args.yml new file mode 100644 index 0000000000..2c6741c589 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/describe/managed-service/command_args.yml @@ -0,0 +1,3 @@ +- name: id +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/describe/tuning-configs/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/describe/tuning-configs/command_args.yml new file mode 100644 index 0000000000..4f9c473396 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/describe/tuning-configs/command_args.yml @@ -0,0 +1,4 @@ +- name: cluster +- name: output +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/describe/upgrade/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/describe/upgrade/command_args.yml new file mode 100644 index 0000000000..73a5adc74c --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/describe/upgrade/command_args.yml @@ -0,0 +1,5 @@ +- name: cluster +- name: machinepool +- name: "yes" +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/detach/policy/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/detach/policy/command_args.yml new file mode 100644 index 0000000000..691baa90b8 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/detach/policy/command_args.yml @@ -0,0 +1,3 @@ +- name: mode +- name: policy-arns +- name: role-name diff --git a/cmd/rosa/structure_test/command_args/rosa/docs/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/docs/command_args.yml new file mode 100644 index 0000000000..870e55bb61 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/docs/command_args.yml @@ -0,0 +1,2 @@ +- name: dir +- name: format diff --git a/cmd/rosa/structure_test/command_args/rosa/download/openshift-client/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/download/openshift-client/command_args.yml new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/download/openshift-client/command_args.yml @@ -0,0 +1 @@ +[] diff --git a/cmd/rosa/structure_test/command_args/rosa/download/rosa-client/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/download/rosa-client/command_args.yml new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/download/rosa-client/command_args.yml @@ -0,0 +1 @@ +[] diff --git a/cmd/rosa/structure_test/command_args/rosa/edit/addon/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/edit/addon/command_args.yml new file mode 100644 index 0000000000..ff7d6bcfc4 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/edit/addon/command_args.yml @@ -0,0 +1,5 @@ +- name: cluster +- name: interactive +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/edit/autoscaler/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/edit/autoscaler/command_args.yml new file mode 100644 index 0000000000..b63f61c9e7 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/edit/autoscaler/command_args.yml @@ -0,0 +1,25 @@ +- name: cluster +- name: interactive +- name: balance-similar-node-groups +- name: skip-nodes-with-local-storage +- name: log-verbosity +- name: max-pod-grace-period +- name: pod-priority-threshold +- name: ignore-daemonsets-utilization +- name: max-node-provision-time +- name: balancing-ignored-labels +- name: max-nodes-total +- name: min-cores +- name: max-cores +- name: min-memory +- name: max-memory +- name: gpu-limit +- name: scale-down-enabled +- name: scale-down-unneeded-time +- name: scale-down-utilization-threshold +- name: scale-down-delay-after-add +- name: scale-down-delay-after-delete +- name: scale-down-delay-after-failure +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/edit/cluster/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/edit/cluster/command_args.yml new file mode 100644 index 0000000000..a1f260991f --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/edit/cluster/command_args.yml @@ -0,0 +1,16 @@ +- name: cluster +- name: "yes" +- name: expiration-time +- name: expiration +- name: enable-delete-protection +- name: private +- name: disable-workload-monitoring +- name: http-proxy +- name: https-proxy +- name: no-proxy +- name: additional-trust-bundle-file +- name: audit-log-arn +- name: additional-allowed-principals +- name: interactive +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/edit/ingress/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/edit/ingress/command_args.yml new file mode 100644 index 0000000000..3ffe1decdb --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/edit/ingress/command_args.yml @@ -0,0 +1,13 @@ +- name: cluster +- name: component-routes +- name: excluded-namespaces +- name: interactive +- name: label-match +- name: lb-type +- name: namespace-ownership-policy +- name: private +- name: profile +- name: region +- name: route-selector +- name: wildcard-policy +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/edit/kubeletconfig/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/edit/kubeletconfig/command_args.yml new file mode 100644 index 0000000000..4fe870bf4a --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/edit/kubeletconfig/command_args.yml @@ -0,0 +1,7 @@ +- name: cluster +- name: interactive +- name: pod-pids-limit +- name: name +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/edit/machinepool/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/edit/machinepool/command_args.yml new file mode 100644 index 0000000000..03e6284caa --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/edit/machinepool/command_args.yml @@ -0,0 +1,19 @@ +- name: autorepair +- name: cluster +- name: enable-autoscaling +- name: interactive +- name: kubelet-configs +- name: labels +- name: machinepool +- name: max-replicas +- name: max-surge +- name: max-unavailable +- name: min-replicas +- name: node-drain-grace-period +- name: output +- name: profile +- name: region +- name: replicas +- name: taints +- name: tuning-configs +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/edit/managed-service/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/edit/managed-service/command_args.yml new file mode 100644 index 0000000000..143a5e6ca4 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/edit/managed-service/command_args.yml @@ -0,0 +1,5 @@ +- name: id +- name: interactive +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/edit/tuning-configs/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/edit/tuning-configs/command_args.yml new file mode 100644 index 0000000000..e4dd94954e --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/edit/tuning-configs/command_args.yml @@ -0,0 +1,6 @@ +- name: cluster +- name: interactive +- name: profile +- name: region +- name: spec-path +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/grant/user/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/grant/user/command_args.yml new file mode 100644 index 0000000000..d5599d0ceb --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/grant/user/command_args.yml @@ -0,0 +1,4 @@ +- name: cluster +- name: profile +- name: region +- name: user diff --git a/cmd/rosa/structure_test/command_args/rosa/hibernate/cluster/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/hibernate/cluster/command_args.yml new file mode 100644 index 0000000000..9c226f081c --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/hibernate/cluster/command_args.yml @@ -0,0 +1,2 @@ +- name: cluster +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/init/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/init/command_args.yml new file mode 100644 index 0000000000..c26a183cf2 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/init/command_args.yml @@ -0,0 +1,19 @@ +- name: delete-stack +- name: delete +- name: disable-scp-checks +- name: use-local-credentials +- name: admin +- name: client-id +- name: client-secret +- name: govcloud +- name: insecure +- name: region +- name: rh-region +- name: scope +- name: token +- name: token-url +- name: url +- name: use-auth-code +- name: use-device-code +- name: profile +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/install/addon/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/install/addon/command_args.yml new file mode 100644 index 0000000000..e41d8f4222 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/install/addon/command_args.yml @@ -0,0 +1,7 @@ +- name: billing-model +- name: billing-model-account-id +- name: cluster +- name: interactive +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/link/ocm-role/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/link/ocm-role/command_args.yml new file mode 100644 index 0000000000..6d14cac7ab --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/link/ocm-role/command_args.yml @@ -0,0 +1,6 @@ +- name: interactive +- name: organization-id +- name: profile +- name: region +- name: role-arn +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/link/user-role/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/link/user-role/command_args.yml new file mode 100644 index 0000000000..5da2caa1ed --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/link/user-role/command_args.yml @@ -0,0 +1,6 @@ +- name: account-id +- name: interactive +- name: profile +- name: region +- name: role-arn +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/list/account-roles/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/account-roles/command_args.yml new file mode 100644 index 0000000000..8e3a64c545 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/account-roles/command_args.yml @@ -0,0 +1,4 @@ +- name: version +- name: output +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/list/addons/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/addons/command_args.yml new file mode 100644 index 0000000000..4f9c473396 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/addons/command_args.yml @@ -0,0 +1,4 @@ +- name: cluster +- name: output +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/list/break-glass-credentials/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/break-glass-credentials/command_args.yml new file mode 100644 index 0000000000..4f9c473396 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/break-glass-credentials/command_args.yml @@ -0,0 +1,4 @@ +- name: cluster +- name: output +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/list/clusters/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/clusters/command_args.yml new file mode 100644 index 0000000000..0f997f24ca --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/clusters/command_args.yml @@ -0,0 +1,5 @@ +- name: output +- name: all +- name: account-role-arn +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/list/dns-domain/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/dns-domain/command_args.yml new file mode 100644 index 0000000000..374fbba7e8 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/dns-domain/command_args.yml @@ -0,0 +1,4 @@ +- name: all +- name: output +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/list/external-auth-providers/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/external-auth-providers/command_args.yml new file mode 100644 index 0000000000..4f9c473396 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/external-auth-providers/command_args.yml @@ -0,0 +1,4 @@ +- name: cluster +- name: output +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/list/gates/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/gates/command_args.yml new file mode 100644 index 0000000000..b84588d44c --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/gates/command_args.yml @@ -0,0 +1,6 @@ +- name: cluster +- name: gate +- name: output +- name: profile +- name: region +- name: version diff --git a/cmd/rosa/structure_test/command_args/rosa/list/idps/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/idps/command_args.yml new file mode 100644 index 0000000000..4f9c473396 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/idps/command_args.yml @@ -0,0 +1,4 @@ +- name: cluster +- name: output +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/list/ingresses/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/ingresses/command_args.yml new file mode 100644 index 0000000000..4f9c473396 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/ingresses/command_args.yml @@ -0,0 +1,4 @@ +- name: cluster +- name: output +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/list/instance-types/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/instance-types/command_args.yml new file mode 100644 index 0000000000..0b25c15552 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/instance-types/command_args.yml @@ -0,0 +1,6 @@ +- name: external-id +- name: hosted-cp +- name: output +- name: region +- name: role-arn +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/list/kubeletconfigs/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/kubeletconfigs/command_args.yml new file mode 100644 index 0000000000..4f9c473396 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/kubeletconfigs/command_args.yml @@ -0,0 +1,4 @@ +- name: cluster +- name: output +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/list/machinepools/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/machinepools/command_args.yml new file mode 100644 index 0000000000..4f9c473396 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/machinepools/command_args.yml @@ -0,0 +1,4 @@ +- name: cluster +- name: output +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/list/managed-services/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/managed-services/command_args.yml new file mode 100644 index 0000000000..39943b9c86 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/managed-services/command_args.yml @@ -0,0 +1,3 @@ +- name: output +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/list/ocm-roles/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/ocm-roles/command_args.yml new file mode 100644 index 0000000000..39943b9c86 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/ocm-roles/command_args.yml @@ -0,0 +1,3 @@ +- name: output +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/list/oidc-config/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/oidc-config/command_args.yml new file mode 100644 index 0000000000..39943b9c86 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/oidc-config/command_args.yml @@ -0,0 +1,3 @@ +- name: output +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/list/oidc-providers/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/oidc-providers/command_args.yml new file mode 100644 index 0000000000..908cc50765 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/oidc-providers/command_args.yml @@ -0,0 +1,5 @@ +- name: output +- name: cluster +- name: oidc-config-id +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/list/operator-roles/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/operator-roles/command_args.yml new file mode 100644 index 0000000000..aeb2bc7375 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/operator-roles/command_args.yml @@ -0,0 +1,7 @@ +- name: version +- name: prefix +- name: interactive +- name: cluster +- name: output +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/list/regions/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/regions/command_args.yml new file mode 100644 index 0000000000..c1ce33860a --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/regions/command_args.yml @@ -0,0 +1,7 @@ +- name: external-id +- name: hosted-cp +- name: multi-az +- name: output +- name: profile +- name: region +- name: role-arn diff --git a/cmd/rosa/structure_test/command_args/rosa/list/rh-regions/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/rh-regions/command_args.yml new file mode 100644 index 0000000000..04b05fa819 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/rh-regions/command_args.yml @@ -0,0 +1,3 @@ +- name: discovery-url +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/list/tuning-configs/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/tuning-configs/command_args.yml new file mode 100644 index 0000000000..4f9c473396 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/tuning-configs/command_args.yml @@ -0,0 +1,4 @@ +- name: cluster +- name: output +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/list/upgrades/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/upgrades/command_args.yml new file mode 100644 index 0000000000..7d93b48ab7 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/upgrades/command_args.yml @@ -0,0 +1,6 @@ +- name: cluster +- name: machinepool +- name: "yes" +- name: output +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/list/user-roles/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/user-roles/command_args.yml new file mode 100644 index 0000000000..39943b9c86 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/user-roles/command_args.yml @@ -0,0 +1,3 @@ +- name: output +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/list/users/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/users/command_args.yml new file mode 100644 index 0000000000..4f9c473396 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/users/command_args.yml @@ -0,0 +1,4 @@ +- name: cluster +- name: output +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/list/versions/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/list/versions/command_args.yml new file mode 100644 index 0000000000..df7c836116 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/list/versions/command_args.yml @@ -0,0 +1,5 @@ +- name: channel-group +- name: hosted-cp +- name: output +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/login/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/login/command_args.yml new file mode 100644 index 0000000000..c46a9a2acb --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/login/command_args.yml @@ -0,0 +1,13 @@ +- name: admin +- name: client-id +- name: client-secret +- name: govcloud +- name: insecure +- name: region +- name: rh-region +- name: scope +- name: token +- name: token-url +- name: url +- name: use-auth-code +- name: use-device-code diff --git a/cmd/rosa/structure_test/command_args/rosa/logout/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/logout/command_args.yml new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/logout/command_args.yml @@ -0,0 +1 @@ +[] diff --git a/cmd/rosa/structure_test/command_args/rosa/logs/install/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/logs/install/command_args.yml new file mode 100644 index 0000000000..efb318c548 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/logs/install/command_args.yml @@ -0,0 +1,5 @@ +- name: cluster +- name: profile +- name: region +- name: tail +- name: watch diff --git a/cmd/rosa/structure_test/command_args/rosa/logs/uninstall/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/logs/uninstall/command_args.yml new file mode 100644 index 0000000000..efb318c548 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/logs/uninstall/command_args.yml @@ -0,0 +1,5 @@ +- name: cluster +- name: profile +- name: region +- name: tail +- name: watch diff --git a/cmd/rosa/structure_test/command_args/rosa/register/oidc-config/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/register/oidc-config/command_args.yml new file mode 100644 index 0000000000..a16222f90c --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/register/oidc-config/command_args.yml @@ -0,0 +1,9 @@ +- name: interactive +- name: issuer-url +- name: mode +- name: output +- name: profile +- name: region +- name: role-arn +- name: secret-arn +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/resume/cluster/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/resume/cluster/command_args.yml new file mode 100644 index 0000000000..9c226f081c --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/resume/cluster/command_args.yml @@ -0,0 +1,2 @@ +- name: cluster +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/revoke/break-glass-credentials/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/revoke/break-glass-credentials/command_args.yml new file mode 100644 index 0000000000..a7374822d3 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/revoke/break-glass-credentials/command_args.yml @@ -0,0 +1,4 @@ +- name: cluster +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/revoke/user/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/revoke/user/command_args.yml new file mode 100644 index 0000000000..5e62c09172 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/revoke/user/command_args.yml @@ -0,0 +1,5 @@ +- name: cluster +- name: profile +- name: region +- name: user +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/token/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/token/command_args.yml new file mode 100644 index 0000000000..865e70c82a --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/token/command_args.yml @@ -0,0 +1,5 @@ +- name: generate +- name: header +- name: payload +- name: refresh +- name: signature diff --git a/cmd/rosa/structure_test/command_args/rosa/uninstall/addon/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/uninstall/addon/command_args.yml new file mode 100644 index 0000000000..a7374822d3 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/uninstall/addon/command_args.yml @@ -0,0 +1,4 @@ +- name: cluster +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/unlink/ocm-role/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/unlink/ocm-role/command_args.yml new file mode 100644 index 0000000000..a12b36230c --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/unlink/ocm-role/command_args.yml @@ -0,0 +1,5 @@ +- name: interactive +- name: organization-id +- name: profile +- name: role-arn +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/unlink/user-role/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/unlink/user-role/command_args.yml new file mode 100644 index 0000000000..1cc0dacdd8 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/unlink/user-role/command_args.yml @@ -0,0 +1,5 @@ +- name: account-id +- name: interactive +- name: profile +- name: role-arn +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/upgrade/account-roles/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/upgrade/account-roles/command_args.yml new file mode 100644 index 0000000000..86de2004bc --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/upgrade/account-roles/command_args.yml @@ -0,0 +1,9 @@ +- name: channel-group +- name: hosted-cp +- name: interactive +- name: mode +- name: prefix +- name: profile +- name: region +- name: version +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/upgrade/cluster/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/upgrade/cluster/command_args.yml new file mode 100644 index 0000000000..ac7acb5f3e --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/upgrade/cluster/command_args.yml @@ -0,0 +1,13 @@ +- name: cluster +- name: mode +- name: version +- name: schedule-date +- name: schedule-time +- name: schedule +- name: allow-minor-version-updates +- name: node-drain-grace-period +- name: control-plane +- name: "yes" +- name: interactive +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/upgrade/machinepool/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/upgrade/machinepool/command_args.yml new file mode 100644 index 0000000000..a96c868a02 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/upgrade/machinepool/command_args.yml @@ -0,0 +1,10 @@ +- name: cluster +- name: version +- name: schedule-date +- name: schedule-time +- name: schedule +- name: allow-minor-version-updates +- name: "yes" +- name: interactive +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/upgrade/operator-roles/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/upgrade/operator-roles/command_args.yml new file mode 100644 index 0000000000..052292ae97 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/upgrade/operator-roles/command_args.yml @@ -0,0 +1,7 @@ +- name: cluster +- name: interactive +- name: mode +- name: profile +- name: region +- name: version +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/upgrade/roles/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/upgrade/roles/command_args.yml new file mode 100644 index 0000000000..d8a449294b --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/upgrade/roles/command_args.yml @@ -0,0 +1,9 @@ +- name: channel-group +- name: cluster +- name: cluster-version +- name: interactive +- name: mode +- name: policy-version +- name: profile +- name: region +- name: "yes" diff --git a/cmd/rosa/structure_test/command_args/rosa/verify/network/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/verify/network/command_args.yml new file mode 100644 index 0000000000..138a242d19 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/verify/network/command_args.yml @@ -0,0 +1,9 @@ +- name: cluster +- name: hosted-cp +- name: output +- name: region +- name: role-arn +- name: status-only +- name: subnet-ids +- name: tags +- name: watch diff --git a/cmd/rosa/structure_test/command_args/rosa/verify/openshift-client/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/verify/openshift-client/command_args.yml new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/verify/openshift-client/command_args.yml @@ -0,0 +1 @@ +[] diff --git a/cmd/rosa/structure_test/command_args/rosa/verify/permissions/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/verify/permissions/command_args.yml new file mode 100644 index 0000000000..5f15db9074 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/verify/permissions/command_args.yml @@ -0,0 +1,2 @@ +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/verify/quota/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/verify/quota/command_args.yml new file mode 100644 index 0000000000..5f15db9074 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/verify/quota/command_args.yml @@ -0,0 +1,2 @@ +- name: profile +- name: region diff --git a/cmd/rosa/structure_test/command_args/rosa/verify/rosa-client/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/verify/rosa-client/command_args.yml new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/verify/rosa-client/command_args.yml @@ -0,0 +1 @@ +[] diff --git a/cmd/rosa/structure_test/command_args/rosa/version/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/version/command_args.yml new file mode 100644 index 0000000000..efd6f56aaa --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/version/command_args.yml @@ -0,0 +1,2 @@ +- name: client +- name: verbose diff --git a/cmd/rosa/structure_test/command_args/rosa/whoami/command_args.yml b/cmd/rosa/structure_test/command_args/rosa/whoami/command_args.yml new file mode 100644 index 0000000000..4c3cc607eb --- /dev/null +++ b/cmd/rosa/structure_test/command_args/rosa/whoami/command_args.yml @@ -0,0 +1 @@ +- name: output diff --git a/cmd/rosa/structure_test/command_structure.yml b/cmd/rosa/structure_test/command_structure.yml new file mode 100755 index 0000000000..b5fe0f3d60 --- /dev/null +++ b/cmd/rosa/structure_test/command_structure.yml @@ -0,0 +1,167 @@ +# +# Defines the structure of commands supported by ROSA CLI. Used to verify that CLI structure is correctly assembled +# at build time as part of our unit testing. +# +# New commands should be added in the correct location. +# +name: rosa +children: +- name: completion +- name: config + children: + - name: get + - name: set +- name: create + children: + - name: account-roles + - name: admin + - name: autoscaler + - name: break-glass-credential + - name: cluster + - name: dns-domain + - name: idp + - name: external-auth-provider + - name: kubeletconfig + - name: machinepool + - name: ocm-role + - name: oidc-config + - name: oidc-provider + - name: operator-roles + - name: managed-service + - name: tuning-configs + - name: user-role +- name: delete + children: + - name: account-roles + - name: admin + - name: autoscaler + - name: cluster + - name: dns-domain + - name: external-auth-provider + - name: idp + - name: ingress + - name: kubeletconfig + - name: machinepool + - name: ocm-role + - name: oidc-config + - name: oidc-provider + - name: operator-roles + - name: managed-service + - name: tuning-configs + - name: upgrade + - name: user-role +- name: describe + children: + - name: addon + - name: admin + - name: autoscaler + - name: break-glass-credential + - name: cluster + - name: external-auth-provider + - name: ingress + - name: addon-installation + - name: kubeletconfig + - name: machinepool + - name: managed-service + - name: tuning-configs + - name: upgrade +- name: detach + children: + - name: policy +- name: docs +- name: download + children: + - name: openshift-client + - name: rosa-client +- name: edit + children: + - name: addon + - name: autoscaler + - name: cluster + - name: ingress + - name: kubeletconfig + - name: machinepool + - name: managed-service + - name: tuning-configs +- name: grant + children: + - name: user +- name: help + generated: true +- name: hibernate + children: + - name: cluster +- name: init +- name: install + children: + - name: addon +- name: link + children: + - name: ocm-role + - name: user-role +- name: list + children: + - name: account-roles + - name: addons + - name: break-glass-credentials + - name: clusters + - name: dns-domain + - name: external-auth-providers + - name: gates + - name: idps + - name: ingresses + - name: instance-types + - name: kubeletconfigs + - name: machinepools + - name: ocm-roles + - name: oidc-config + - name: oidc-providers + - name: operator-roles + - name: regions + - name: rh-regions + - name: managed-services + - name: tuning-configs + - name: upgrades + - name: users + - name: user-roles + - name: versions +- name: login +- name: logout +- name: logs + children: + - name: install + - name: uninstall +- name: register + children: + - name: oidc-config +- name: resume + children: + - name: cluster +- name: revoke + children: + - name: break-glass-credentials + - name: user +- name: token +- name: uninstall + children: + - name: addon +- name: unlink + children: + - name: ocm-role + - name: user-role +- name: upgrade + children: + - name: account-roles + - name: cluster + - name: machinepool + - name: operator-roles + - name: roles +- name: verify + children: + - name: network + - name: openshift-client + - name: permissions + - name: quota + - name: rosa-client +- name: version +- name: whoami \ No newline at end of file diff --git a/pkg/test/arg_generator.go b/pkg/test/arg_generator.go new file mode 100644 index 0000000000..fffdb6728b --- /dev/null +++ b/pkg/test/arg_generator.go @@ -0,0 +1,35 @@ +package test + +import ( + "os" + + "gopkg.in/yaml.v2" + + . "github.com/onsi/gomega" + "github.com/spf13/cobra" + "github.com/spf13/pflag" +) + +type ArgGenerator struct { + file string + command *cobra.Command +} + +func (a *ArgGenerator) GenerateArgsFile() { + var args []*rosaCommandArg + + a.command.Flags().VisitAll(func(flag *pflag.Flag) { + args = append(args, &rosaCommandArg{Name: flag.Name}) + }) + + output, err := yaml.Marshal(args) + Expect(err).NotTo(HaveOccurred()) + Expect(os.WriteFile(a.file, output, 0600)).To(Succeed()) +} + +func NewArgGenerator(argFile string, command *cobra.Command) *ArgGenerator { + return &ArgGenerator{ + file: argFile, + command: command, + } +} diff --git a/pkg/test/arg_verifier.go b/pkg/test/arg_verifier.go new file mode 100644 index 0000000000..ab0750f7b3 --- /dev/null +++ b/pkg/test/arg_verifier.go @@ -0,0 +1,69 @@ +package test + +import ( + "os" + "path/filepath" + "strings" + + "gopkg.in/yaml.v2" + + . "github.com/onsi/gomega" + "github.com/spf13/cobra" + "github.com/spf13/pflag" +) + +type rosaCommandArg struct { + Name string `json:"name"` +} + +type ArgVerifier struct { + Args map[string]*rosaCommandArg + Command *cobra.Command +} + +const ( + CommandArgFileName = "command_args.yml" + CommandArgDirectoryName = "command_args" +) + +func (a *ArgVerifier) AssertCommandArgs() { + for k := range a.Args { + flag := a.Command.Flags().Lookup(k) + Expect(flag).NotTo( + BeNil(), + "Flag with name '%s' does not exist on command '%s'. Have you removed a flag?", + k, a.Command.CommandPath()) + } + + a.Command.Flags().VisitAll(func(flag *pflag.Flag) { + Expect(a.Args[flag.Name]).NotTo( + BeNil(), + "Unexpected flag '%s' on command '%s'. Have you added a new flag?", + flag.Name, a.Command.CommandPath()) + }) +} + +func NewArgVerifier(commandStructureDir string, command *cobra.Command) *ArgVerifier { + _, err := os.Stat(filepath.Join(commandStructureDir, CommandArgDirectoryName)) + Expect(err).NotTo(HaveOccurred()) + + contents, err := os.ReadFile(GetCommandArgsFile(commandStructureDir, command)) + Expect(err).NotTo(HaveOccurred(), "Failed to open arg file '%s'", commandStructureDir) + + var args []*rosaCommandArg + err = yaml.Unmarshal(contents, &args) + Expect(err).NotTo(HaveOccurred(), + "Failed to unmarshall arg file '%s' into YAML", commandStructureDir) + + argMap := make(map[string]*rosaCommandArg) + for _, arg := range args { + argMap[arg.Name] = arg + } + + return &ArgVerifier{Args: argMap, Command: command} +} + +func GetCommandArgsFile(commandStructureDir string, command *cobra.Command) string { + commandDir := filepath.Join(strings.Split(command.CommandPath(), " ")...) + return filepath.Join(commandStructureDir, CommandArgDirectoryName, commandDir, CommandArgFileName) +} diff --git a/pkg/test/structure_verifier.go b/pkg/test/structure_verifier.go new file mode 100644 index 0000000000..61994da932 --- /dev/null +++ b/pkg/test/structure_verifier.go @@ -0,0 +1,74 @@ +package test + +import ( + "os" + "path/filepath" + + "gopkg.in/yaml.v2" + + . "github.com/onsi/gomega" + "github.com/spf13/cobra" +) + +const ( + commandStructureFileName = "command_structure.yml" +) + +type StructureVerifier struct { + command *cobra.Command + rosaCommand *rosaCommand +} + +type rosaCommand struct { + Name string `json:"name"` + Children []*rosaCommand `json:"children,omitempty"` + Generated bool `json:"generated,omitempty"` +} + +func (c *rosaCommand) ChildCount() int { + return len(c.Children) +} + +func (s *StructureVerifier) toChildrenMap(cmd *cobra.Command) map[string]*cobra.Command { + childrenMap := make(map[string]*cobra.Command) + for _, c := range cmd.Commands() { + childrenMap[c.Name()] = c + } + return childrenMap +} + +func (s *StructureVerifier) AssertCommandStructure() { + s.assertCommand(s.rosaCommand, s.command) +} + +func (s *StructureVerifier) assertCommand(rosaCommand *rosaCommand, command *cobra.Command) { + Expect(command).NotTo(BeNil(), + "Command with name '%s' does not exist in cobra setup for ROSA", rosaCommand.Name) + Expect(rosaCommand.Name).To(Equal(command.Name())) + Expect(rosaCommand.ChildCount()). + To(Equal(len(command.Commands())), + "Unexpected child command on command '%s'", command.CommandPath()) + if rosaCommand.ChildCount() != 0 { + childrenMap := s.toChildrenMap(command) + for _, rc := range rosaCommand.Children { + if !rc.Generated { + cc := childrenMap[rc.Name] + s.assertCommand(rc, cc) + } + } + } +} + +func NewStructureVerifier(commandStructureDirectory string, rootCommand *cobra.Command) *StructureVerifier { + contents, err := os.ReadFile(filepath.Join(commandStructureDirectory, commandStructureFileName)) + Expect(err).NotTo(HaveOccurred()) + + var cmd rosaCommand + + err = yaml.Unmarshal(contents, &cmd) + Expect(err).NotTo(HaveOccurred()) + return &StructureVerifier{ + command: rootCommand, + rosaCommand: &cmd, + } +}