Files
nvke/cli/internal/controller/clusters/clusters_test.go
Davanum SrinivasandClaude Fable 5.1 668bc38a9b feat(cli)!: rename nkectl to nvkectl, keeping the old names for one release (#1456)
The binary, its directory, its config directory and its environment
variables take the new name. For one release the previous names still
work: every NVKECTL_* setting is also read under its NKECTL_* name with a
deprecation warning (the NKECTL_CWE_* names of the generation before are
no longer read), a config file left under nkectl/ is read and copied to
nvkectl/ once, and releases publish both nvkectl-<os>-<arch> and
nkectl-<os>-<arch>, to GitHub and to S3 under the existing prefix.

The e2e helper package, the e2e test, the smoke and fetch scripts and
the bootstrap e2e workflow follow the binary; the fetch script accepts a
release that carries only the old asset name. The CLI's own documents
and the two installation documents that print the download URLs change
with it.

Kept on purpose: the NVCR repository name until an nvkectl repository
exists in the NGC org, the S3 prefix the publishing role's policy names,
and the prose in the other documents.

BREAKING CHANGE: the CLI is installed and invoked as nvkectl. The
previous binary name, environment variable names and config directory
are honoured for one release, as described above.

Closes #1455

Signed-off-by: Davanum Srinivas <dsrinivas@nvidia.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-10 17:04:03 -04:00

55 lines
2.0 KiB
Go

// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package clusters
import (
"testing"
"github.com/spf13/cobra"
)
// withParent registers cmd under a throwaway parent so cobra resolves names and
// aliases exactly as it does at runtime, then calls parent with args.
func withParent(cmd *cobra.Command, args []string) error {
parent := &cobra.Command{Use: "nvkectl"}
parent.AddCommand(cmd)
parent.SetArgs(args)
return parent.Execute()
}
// TestCmdAliases verifies that "cluster" and "clusters" are interchangeable
// for get, create, patch, and delete.
func TestCmdAliases(t *testing.T) {
validSpec := writeSpec(t, `
name: my-cluster
controlPlaneKubernetesVersion: "1.30.0"
cniPlugin: calico
etcdEncrypted: false
`)
tests := []struct {
label string
newCmd func() *cobra.Command
args []string
}{
{"get clusters", func() *cobra.Command { return NewGetCmd(clientFnErr) }, []string{"clusters"}},
{"get cluster", func() *cobra.Command { return NewGetCmd(clientFnErr) }, []string{"cluster"}},
{"create clusters", func() *cobra.Command { return NewCreateCmd(clientFnErr) }, []string{"clusters", "-f", validSpec}},
{"create cluster", func() *cobra.Command { return NewCreateCmd(clientFnErr) }, []string{"cluster", "-f", validSpec}},
{"patch clusters", func() *cobra.Command { return NewPatchCmd(clientFnErr) }, []string{"clusters", "my-cluster", "--patch", "teleportEnabled: true"}},
{"patch cluster", func() *cobra.Command { return NewPatchCmd(clientFnErr) }, []string{"cluster", "my-cluster", "--patch", "teleportEnabled: true"}},
{"delete clusters", func() *cobra.Command { return NewDeleteCmd(clientFnErr) }, []string{"clusters", "my-cluster"}},
{"delete cluster", func() *cobra.Command { return NewDeleteCmd(clientFnErr) }, []string{"cluster", "my-cluster"}},
}
for _, tt := range tests {
t.Run(tt.label, func(t *testing.T) {
err := withParent(tt.newCmd(), tt.args)
if !isNotConfigured(err) {
t.Errorf("expected no-site error, got: %v", err)
}
})
}
}