From 6e30956fbcc65464b7463cef956fe429c4a37cbe Mon Sep 17 00:00:00 2001 From: Prem Kumar Kalle Date: Sun, 1 Oct 2023 19:02:27 -0700 Subject: [PATCH] Rename UCP names with TAE(Tanzu Application Engine) - Rename all the instances of UCP names and context Type with TAE(Tanzu Application Engine) Signed-off-by: Prem Kumar Kalle --- config/contexts.go | 2 +- config/contexts_test.go | 42 ++++++------- config/types/clientconfig.go | 9 +-- config/types/clientconfig_helper.go | 7 ++- fakes/config/kubeconfig-1.yaml | 12 ++-- .../internal/kubeconfig/kubeconfig.go | 0 .../internal/kubeconfig/kubeconfig_test.go | 20 +++---- {ucp => tae}/internal/kubeconfig/types.go | 2 +- ucp/ucp.go => tae/tae.go | 42 ++++++------- ucp/ucp_test.go => tae/tae_test.go | 59 +++++++++---------- 10 files changed, 98 insertions(+), 97 deletions(-) rename {ucp => tae}/internal/kubeconfig/kubeconfig.go (100%) rename {ucp => tae}/internal/kubeconfig/kubeconfig_test.go (88%) rename {ucp => tae}/internal/kubeconfig/types.go (99%) rename ucp/ucp.go => tae/tae.go (84%) rename ucp/ucp_test.go => tae/tae_test.go (81%) diff --git a/config/contexts.go b/config/contexts.go index 970374892..5ec7c438b 100644 --- a/config/contexts.go +++ b/config/contexts.go @@ -241,7 +241,7 @@ func EndpointFromContext(s *configtypes.Context) (endpoint string, err error) { return s.ClusterOpts.Endpoint, nil case configtypes.TargetTMC: return s.GlobalOpts.Endpoint, nil - case configtypes.TargetUCP: + case configtypes.TargetTAE: return s.ClusterOpts.Endpoint, nil default: return endpoint, fmt.Errorf("unknown server type %q", s.Target) diff --git a/config/contexts_test.go b/config/contexts_test.go index 7e18c3eaa..5f6cee749 100644 --- a/config/contexts_test.go +++ b/config/contexts_test.go @@ -462,8 +462,8 @@ func setupForGetContext(t *testing.T) { }, }, { - Name: "test-ucp", - Target: configtypes.TargetUCP, + Name: "test-tae", + Target: configtypes.TargetTAE, GlobalOpts: &configtypes.GlobalServer{ Endpoint: "test-endpoint", }, @@ -477,7 +477,7 @@ func setupForGetContext(t *testing.T) { CurrentContext: map[configtypes.Target]string{ configtypes.TargetK8s: "test-mc-2", configtypes.TargetTMC: "test-tmc", - configtypes.TargetUCP: "test-ucp", + configtypes.TargetTAE: "test-tae", }, } func() { @@ -508,8 +508,8 @@ func TestGetContext(t *testing.T) { ctxName: "test-tmc", }, { - name: "success ucp", - ctxName: "test-ucp", + name: "success tae", + ctxName: "test-tae", }, { name: "failure", @@ -554,8 +554,8 @@ func TestContextExists(t *testing.T) { ok: true, }, { - name: "success ucp", - ctxName: "test-ucp", + name: "success tae", + ctxName: "test-tae", ok: true, }, { @@ -681,10 +681,10 @@ func TestSetContext(t *testing.T) { }, }, { - name: "success ucp current", + name: "success tae current", ctx: &configtypes.Context{ - Name: "test-ucp1", - Target: configtypes.TargetUCP, + Name: "test-tae1", + Target: configtypes.TargetTAE, GlobalOpts: &configtypes.GlobalServer{ Endpoint: "test-endpoint", }, @@ -700,10 +700,10 @@ func TestSetContext(t *testing.T) { current: true, }, { - name: "success ucp not_current", + name: "success tae not_current", ctx: &configtypes.Context{ - Name: "test-ucp2", - Target: configtypes.TargetUCP, + Name: "test-tae2", + Target: configtypes.TargetTAE, GlobalOpts: &configtypes.GlobalServer{ Endpoint: "test-endpoint", }, @@ -761,9 +761,9 @@ func TestRemoveContext(t *testing.T) { target: configtypes.TargetTMC, }, { - name: "success ucp", - ctxName: "test-ucp", - target: configtypes.TargetUCP, + name: "success tae", + ctxName: "test-tae", + target: configtypes.TargetTAE, }, { name: "failure", @@ -820,9 +820,9 @@ func TestSetCurrentContext(t *testing.T) { currServer: "test-mc", }, { - name: "success ucp", - ctxName: "test-ucp", - target: configtypes.TargetUCP, + name: "success tae", + ctxName: "test-tae", + target: configtypes.TargetTAE, }, { name: "success tmc after setting k8s", @@ -869,13 +869,13 @@ func TestSetCurrentContext(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "test-mc", currentContextMap[configtypes.TargetK8s].Name) assert.Equal(t, "test-tmc", currentContextMap[configtypes.TargetTMC].Name) - assert.Equal(t, "test-ucp", currentContextMap[configtypes.TargetUCP].Name) + assert.Equal(t, "test-tae", currentContextMap[configtypes.TargetTAE].Name) currentContextsList, err := GetAllCurrentContextsList() assert.NoError(t, err) assert.Contains(t, currentContextsList, "test-mc") assert.Contains(t, currentContextsList, "test-tmc") - assert.Contains(t, currentContextsList, "test-ucp") + assert.Contains(t, currentContextsList, "test-tae") } func TestRemoveCurrentContext(t *testing.T) { diff --git a/config/types/clientconfig.go b/config/types/clientconfig.go index ed19d30fa..8b21791db 100644 --- a/config/types/clientconfig.go +++ b/config/types/clientconfig.go @@ -30,15 +30,16 @@ const ( // TargetUnknown specifies that the target is not currently known TargetUnknown Target = "" - // TargetUCP is a used to indicate the type of Context used to interact with a - // Unified Control Plane endpoint + // TargetTAE is a used to indicate the type of Context used to interact with a + // Tanzu Application Engine endpoint // Note!! Experimental, please expect changes - TargetUCP Target = "ucp" + TargetTAE Target = "application-engine" + targetTAE Target = "tae" ) var ( // SupportedTargets is a list of all supported Target - SupportedTargets = []Target{TargetK8s, TargetTMC, TargetUCP} + SupportedTargets = []Target{TargetK8s, TargetTMC, TargetTAE} ) const ( diff --git a/config/types/clientconfig_helper.go b/config/types/clientconfig_helper.go index 65d03d601..c712087c5 100644 --- a/config/types/clientconfig_helper.go +++ b/config/types/clientconfig_helper.go @@ -9,10 +9,10 @@ func StringToTarget(target string) Target { return TargetK8s } else if target == string(targetTMC) || target == string(TargetTMC) { return TargetTMC + } else if target == string(targetTAE) || target == string(TargetTAE) { + return TargetTAE } else if target == string(TargetGlobal) { return TargetGlobal - } else if target == string(TargetUCP) { - return TargetUCP } else if target == string(TargetUnknown) { return TargetUnknown } @@ -27,7 +27,8 @@ func IsValidTarget(target string, allowGlobal, allowUnknown bool) bool { target == string(TargetK8s) || target == string(targetTMC) || target == string(TargetTMC) || - target == string(TargetUCP) || + target == string(targetTAE) || + target == string(TargetTAE) || (allowGlobal && target == string(TargetGlobal)) || (allowUnknown && target == string(TargetUnknown)) } diff --git a/fakes/config/kubeconfig-1.yaml b/fakes/config/kubeconfig-1.yaml index 85e5e442e..d29018cf1 100644 --- a/fakes/config/kubeconfig-1.yaml +++ b/fakes/config/kubeconfig-1.yaml @@ -15,7 +15,7 @@ clusters: - cluster: insecure-skip-tls-verify: true server: https://api.tanzu.cloud.vmware.com:443/org/fake-org-id - name: tanzu-cli-myucp/current + name: tanzu-cli-mytae/current contexts: - context: cluster: bar-cluster @@ -28,9 +28,9 @@ contexts: user: blue-user name: foo-context - context: - cluster: tanzu-cli-myucp/current - user: tanzu-cli-myucp-user - name: tanzu-cli-myucp + cluster: tanzu-cli-mytae/current + user: tanzu-cli-mytae-user + name: tanzu-cli-mytae users: - name: blue-user user: @@ -39,13 +39,13 @@ users: user: client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM4akNDQWRxZ0F3SUJBZ0lJQ24vUDZ1S1pWWTR3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB5TURBeE1qVXdPRFV4TVRCYUZ3MHlNVEF4TWpRd09EVXhNVEphTURReApGekFWQmdOVkJBb1REbk41YzNSbGJUcHRZWE4wWlhKek1Sa3dGd1lEVlFRREV4QnJkV0psY201bGRHVnpMV0ZrCmJXbHVNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZ0tDQVFFQXJuUmc4dklXQlBWQUJWTFUKNGNFckd4bE5XZVJHR2x0OW0wVElsUStNUytSZU9GNUhROW5pQlRSQWMwVWpsUk1EdzR3aEREVXV3Y2NsazFCNApoa3l2YUx5elZyeW9jOWV5NHU0SVZ0MFR4ZU85VUI5bXZHMkF6TlVnY0FkRkp4cWdKbSt2OXo0RzMyU0EwUEc1CjhxZWtBRzVLYU1RQlJEVm5pNXZBajJ5c0hpdHhkbGdJdEZkc1dzNUgwM3FIUjVNQU5jT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2wvZ2JLTk9FZG9FR0tYWEVBaFJTYkc3SHpHeVkveDJVSUFocCtuUytFS21wdVF6WQp4UUdqOU5QSlY3WGJqQkg4MmtDcmhtRUx0bG9QOGdQVlhxUGhXTHFzemNUOE1xUFRCYUcxS21IaTRrb3FZb2hhCldJS0pnTFErOEFCTjBOUEJYUTl4NVJVSHVPejhJaUcveVBxcXM4VUNnWUE3WFVqc3BGTkw3dCt5MENhZDVXK3AKUGdBeTd3ZXRlRHNybjFybjFZM25jdlhidlJJblZ6NWJjbnpUTmZDTWlKOG5KWk81TDNqZTdMSHhlMU9YNERQdgozWU9PZGtycStZOG1JSHk0am52VExRditCOG40L1h6V21GeDNkcjRVY0FiS2g3Nm5PZXlydFg3NXBtSmtXV1FkCmhZMk90dWREYWR5NWFPbU9qQTJEN3dLQmdGQ1UwN3RwTU1GUTIvei9kN3NWZHdpZDFSeFdveUxZUXhVQ2dsZVkKajJJdFI1S3Z3aEZib040azF1QlVKeTRLdlZwL2Z4QjRjNW9hTDZCeS9PQUM2ekgxZkd1WUNmTFRtVWhTRmI0aApFUC9WQjVEWENKbjB2N1poMEwvNjE1UVJXTjU5d3BJQ0Q0OHpKTm91QTNzWmU1YVJFSVNVNDRDbE0rVituNjluCmZERlJBb0dBUDZ1NGxrSjg0amRjTVROVTdYeW16ZkMwSkd5aFRNcWQ2YnV4NG9FQlViSFhoOW1DaVRMSmFaV1YKN0F5NkxTV21lRGIrWEFrS0tQL2UwQVMrWElKV2p6MDI5SFdDaXM0T3NZV3VqeksrVjVaVUVkQlJNUEN0QUo4ZApCaDBvRTliSUdIOVB0RTFIdTh6NGpGaG5WUmVqdmdhMzRQdG9QV3JNL01sZnQzLy9Lazg9Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg== - - name: tanzu-cli-myucp-user + - name: tanzu-cli-mytae-user user: exec: apiVersion: client.authentication.k8s.io/v1beta1 args: - context - get-token - - myucp + - mytae command: tanzu env: [] diff --git a/ucp/internal/kubeconfig/kubeconfig.go b/tae/internal/kubeconfig/kubeconfig.go similarity index 100% rename from ucp/internal/kubeconfig/kubeconfig.go rename to tae/internal/kubeconfig/kubeconfig.go diff --git a/ucp/internal/kubeconfig/kubeconfig_test.go b/tae/internal/kubeconfig/kubeconfig_test.go similarity index 88% rename from ucp/internal/kubeconfig/kubeconfig_test.go rename to tae/internal/kubeconfig/kubeconfig_test.go index a8e7729d9..0c9d6d62f 100644 --- a/ucp/internal/kubeconfig/kubeconfig_test.go +++ b/tae/internal/kubeconfig/kubeconfig_test.go @@ -21,33 +21,33 @@ func copyFile(t *testing.T, sourceFile, destFile string) { } func TestReadAndMinifyKubeConfig(t *testing.T) { - expectedMyucpKubeconfig := ` + expectedMytaeKubeconfig := ` kind: Config apiVersion: v1 preferences: {} clusters: - - name: tanzu-cli-myucp/current + - name: tanzu-cli-mytae/current cluster: server: https://api.tanzu.cloud.vmware.com:443/org/fake-org-id insecure-skip-tls-verify: true users: - - name: tanzu-cli-myucp-user + - name: tanzu-cli-mytae-user user: exec: command: tanzu args: - context - get-token - - myucp + - mytae env: [] apiVersion: client.authentication.k8s.io/v1beta1 provideClusterInfo: false contexts: - - name: tanzu-cli-myucp + - name: tanzu-cli-mytae context: - cluster: tanzu-cli-myucp/current - user: tanzu-cli-myucp-user -current-context: tanzu-cli-myucp + cluster: tanzu-cli-mytae/current + user: tanzu-cli-mytae-user +current-context: tanzu-cli-mytae ` expectedFooContextKubeconfig := ` @@ -97,10 +97,10 @@ current-context: foo-context assert.Equal(t, minifiedKubeconfig, wantKubeConfig) // Test reading and minifying the kubeconfig having ExecConfig as user(AuthInfo) - minifiedKubeconfig, err = MinifyKubeConfig(config, "tanzu-cli-myucp") + minifiedKubeconfig, err = MinifyKubeConfig(config, "tanzu-cli-mytae") assert.NoError(t, err) wantKubeConfig = &Config{} - err = yaml.Unmarshal([]byte(expectedMyucpKubeconfig), wantKubeConfig) + err = yaml.Unmarshal([]byte(expectedMytaeKubeconfig), wantKubeConfig) assert.NoError(t, err) assert.Equal(t, minifiedKubeconfig, wantKubeConfig) } diff --git a/ucp/internal/kubeconfig/types.go b/tae/internal/kubeconfig/types.go similarity index 99% rename from ucp/internal/kubeconfig/types.go rename to tae/internal/kubeconfig/types.go index 4f081c96d..83c50bdf7 100644 --- a/ucp/internal/kubeconfig/types.go +++ b/tae/internal/kubeconfig/types.go @@ -3,7 +3,7 @@ package kubeconfig -// Note-IMPORTANT!! The below types are copied from the client-go library and modified a bit(removed fields like extensions not necessary for UCP kubeconfig) +// Note-IMPORTANT!! The below types are copied from the client-go library and modified a bit(removed fields like extensions not necessary for TAE kubeconfig) // to provide kubeconfig access functionality without copying the k8s.io/client-go library which would bring in the other kubernetes dependencies // and would impose dependency constraints on the plugin developers using the tanzu-plugin-runtime library diff --git a/ucp/ucp.go b/tae/tae.go similarity index 84% rename from ucp/ucp.go rename to tae/tae.go index 1e4fa5129..8a0c77ee1 100644 --- a/ucp/ucp.go +++ b/tae/tae.go @@ -1,8 +1,8 @@ // Copyright 2023 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Package ucp provides APIs specific to ucp -package ucp +// Package tae provides APIs specific to Tanzu Application Engine(TAE) +package tae import ( "bytes" @@ -16,14 +16,14 @@ import ( "github.com/vmware-tanzu/tanzu-plugin-runtime/config" configtypes "github.com/vmware-tanzu/tanzu-plugin-runtime/config/types" - "github.com/vmware-tanzu/tanzu-plugin-runtime/ucp/internal/kubeconfig" + "github.com/vmware-tanzu/tanzu-plugin-runtime/tae/internal/kubeconfig" ) // keys to Context's AdditionalMetadata map const ( - OrgIDKey = "ucpOrgID" - ProjectNameKey = "ucpProjectName" - SpaceNameKey = "ucpSpaceName" + OrgIDKey = "taeOrgID" + ProjectNameKey = "taeProjectName" + SpaceNameKey = "taeSpaceName" ) const ( @@ -91,20 +91,20 @@ func runCommand(commandPath string, args []string, opts *cmdOptions) (bytes.Buff return stdout, stderr, command.Run() } -// GetKubeconfigForContext returns the kubeconfig for any arbitrary UCP resource in the UCP object hierarchy -// referred by the UCP context +// GetKubeconfigForContext returns the kubeconfig for any arbitrary TAE resource in the TAE object hierarchy +// referred by the TAE context // Pre-reqs: project and space names should be valid // // Notes: -// If projectName and spaceName is empty string the kubeconfig generated would be pointing to UCP org +// If projectName and spaceName is empty string the kubeconfig generated would be pointing to TAE org // // ex: kubeconfig's cluster.server URL : https://endpoint/org/orgid // -// If projectName is valid projectName and spaceName is empty string the kubeconfig generated would be pointing to UCP project +// If projectName is valid projectName and spaceName is empty string the kubeconfig generated would be pointing to TAE project // // ex: kubeconfig's cluster.server URL : https://endpoint/org/orgid/project/ // -// similarly if both project and space names are valid names the kubeconfig generated would be pointing to UCP space +// similarly if both project and space names are valid names the kubeconfig generated would be pointing to TAE space // // ex: kubeconfig's cluster.server URL: https://endpoint/org/orgid/project//space/ func GetKubeconfigForContext(contextName, projectName, spaceName string) ([]byte, error) { @@ -112,13 +112,13 @@ func GetKubeconfigForContext(contextName, projectName, spaceName string) ([]byte if err != nil { return nil, err } - if ctx.Target != configtypes.TargetUCP { - return nil, errors.Errorf("context must be of type: %s", configtypes.TargetUCP) + if ctx.Target != configtypes.TargetTAE { + return nil, errors.Errorf("context must be of type: %s", configtypes.TargetTAE) } kc, err := kubeconfig.ReadKubeConfig(ctx.ClusterOpts.Path) if err != nil { - return nil, errors.Wrap(err, "failed to read the UCP context kubeconfig") + return nil, errors.Wrap(err, "failed to read the TAE context kubeconfig") } kc, err = kubeconfig.MinifyKubeConfig(kc, ctx.ClusterOpts.Context) @@ -154,8 +154,8 @@ func updateKubeconfigServerURL(kc *kubeconfig.Config, cliContext *configtypes.Co cluster.Cluster.Server = prepareClusterServerURL(cliContext, projectName, spaceName) } -// SetUCPContextActiveResource sets the active UCP resource for the given context and also updates -// the kubeconfig referrenced by the UCP context +// SetTAEContextActiveResource sets the active TAE resource for the given context and also updates +// the kubeconfig referrenced by the TAE context // // Pre-reqs: project and space names should be valid // @@ -163,9 +163,9 @@ func updateKubeconfigServerURL(kc *kubeconfig.Config, cliContext *configtypes.Co // - a space as active resource, both project and space names are required // - a project as active resource, only project name is required (space should be empty string) // - org as active resource, both project and space names should be empty strings -func SetUCPContextActiveResource(contextName, projectName, spaceName string, opts ...CommandOptions) error { +func SetTAEContextActiveResource(contextName, projectName, spaceName string, opts ...CommandOptions) error { // For now, the implementation expects env var TANZU_BIN to be set and - // pointing to the core CLI binary used to invoke setting the active UCP resource. + // pointing to the core CLI binary used to invoke setting the active TAE resource. options := &cmdOptions{} for _, opt := range opts { @@ -178,12 +178,12 @@ func SetUCPContextActiveResource(contextName, projectName, spaceName string, opt } altCommandArgs := []string{customCommandName} - args := []string{"context", "update", "ucp-active-resource", contextName, "--project", projectName, "--space", spaceName} + args := []string{"context", "update", "tae-active-resource", contextName, "--project", projectName, "--space", spaceName} altCommandArgs = append(altCommandArgs, args...) - // Check if there is an alternate means to set the active UCP context active resource - // operation, if not fall back to `context update ucp-active-resource` + // Check if there is an alternate means to set the active TAE context active resource + // operation, if not fall back to `context update tae-active-resource` stdoutOutput, _, err := runCommand(cliPath, altCommandArgs, &cmdOptions{outWriter: io.Discard, errWriter: io.Discard}) if err == nil { args = strings.Fields(stdoutOutput.String()) diff --git a/ucp/ucp_test.go b/tae/tae_test.go similarity index 81% rename from ucp/ucp_test.go rename to tae/tae_test.go index 96f209f78..1b1213528 100644 --- a/ucp/ucp_test.go +++ b/tae/tae_test.go @@ -1,7 +1,7 @@ // Copyright 2023 VMware, Inc. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -package ucp +package tae import ( "bytes" @@ -16,7 +16,7 @@ import ( "github.com/vmware-tanzu/tanzu-plugin-runtime/config" configtypes "github.com/vmware-tanzu/tanzu-plugin-runtime/config/types" - "github.com/vmware-tanzu/tanzu-plugin-runtime/ucp/internal/kubeconfig" + "github.com/vmware-tanzu/tanzu-plugin-runtime/tae/internal/kubeconfig" ) const ConfigFilePermissions = 0o600 @@ -126,8 +126,8 @@ func setupForGetContext(t *testing.T) { }, }, { - Name: "test-ucp", - Target: configtypes.TargetUCP, + Name: "test-tae", + Target: configtypes.TargetTAE, GlobalOpts: &configtypes.GlobalServer{ Endpoint: "test-endpoint", }, @@ -144,7 +144,7 @@ func setupForGetContext(t *testing.T) { CurrentContext: map[configtypes.Target]string{ configtypes.TargetK8s: "test-mc-2", configtypes.TargetTMC: "test-tmc", - configtypes.TargetUCP: "test-ucp", + configtypes.TargetTAE: "test-tae", }, } func() { @@ -167,40 +167,40 @@ func TestGetKubeconfigForContext(t *testing.T) { _ = os.RemoveAll(kubeconfigFilePath.Name()) }() - c, err := config.GetContext("test-ucp") + c, err := config.GetContext("test-tae") assert.NoError(t, err) c.ClusterOpts.Path = kubeconfigFilePath.Name() - c.ClusterOpts.Context = "tanzu-cli-myucp" + c.ClusterOpts.Context = "tanzu-cli-mytae" err = config.SetContext(c, false) assert.NoError(t, err) - // Test getting the kubeconfig for an arbitrary UCP resource + // Test getting the kubeconfig for an arbitrary TAE resource kubeconfigBytes, err := GetKubeconfigForContext(c.Name, "project1", "space1") assert.NoError(t, err) - c, err = config.GetContext("test-ucp") + c, err = config.GetContext("test-tae") assert.NoError(t, err) var kc kubeconfig.Config err = yaml.Unmarshal(kubeconfigBytes, &kc) assert.NoError(t, err) - cluster := kubeconfig.GetCluster(&kc, "tanzu-cli-myucp/current") + cluster := kubeconfig.GetCluster(&kc, "tanzu-cli-mytae/current") assert.Equal(t, cluster.Cluster.Server, c.ClusterOpts.Endpoint+"/project/project1/space/space1") - // Test getting the kubeconfig for an arbitrary UCP resource + // Test getting the kubeconfig for an arbitrary TAE resource kubeconfigBytes, err = GetKubeconfigForContext(c.Name, "project2", "") assert.NoError(t, err) - c, err = config.GetContext("test-ucp") + c, err = config.GetContext("test-tae") assert.NoError(t, err) err = yaml.Unmarshal(kubeconfigBytes, &kc) assert.NoError(t, err) - cluster = kubeconfig.GetCluster(&kc, "tanzu-cli-myucp/current") + cluster = kubeconfig.GetCluster(&kc, "tanzu-cli-mytae/current") assert.Equal(t, cluster.Cluster.Server, c.ClusterOpts.Endpoint+"/project/project2") - // Test getting the kubeconfig for an arbitrary UCP resource for non UCP context - nonUCPCtx, err := config.GetContext("test-mc") + // Test getting the kubeconfig for an arbitrary TAE resource for non TAE context + nonTAECtx, err := config.GetContext("test-mc") assert.NoError(t, err) - _, err = GetKubeconfigForContext(nonUCPCtx.Name, "project2", "") + _, err = GetKubeconfigForContext(nonTAECtx.Name, "project2", "") assert.Error(t, err) - assert.ErrorContains(t, err, "context must be of type: ucp") + assert.ErrorContains(t, err, "context must be of type: application-engine") } func setupFakeCLI(dir string, exitStatus string, newCommandExitStatus string, enableCustomCommand bool) (string, error) { @@ -224,7 +224,7 @@ func setupFakeCLI(dir string, exitStatus string, newCommandExitStatus string, en return filePath, nil } -func TestSetUCPContextActiveResource(t *testing.T) { +func TestSetTAEContextActiveResource(t *testing.T) { tests := []struct { test string exitStatus string @@ -234,35 +234,35 @@ func TestSetUCPContextActiveResource(t *testing.T) { enableCustomCommand bool }{ { - test: "with no alternate command and ucp active resource update successfully", + test: "with no alternate command and tae active resource update successfully", exitStatus: "0", - expectedOutput: "context update ucp-active-resource test-context --project projectA --space spaceA succeeded\n", + expectedOutput: "context update tae-active-resource test-context --project projectA --space spaceA succeeded\n", expectedFailure: false, }, { - test: "with no alternate command and ucp active resource update unsuccessfully", + test: "with no alternate command and tae active resource update unsuccessfully", exitStatus: "1", - expectedOutput: "context update ucp-active-resource test-context --project projectA --space spaceA failed\n", + expectedOutput: "context update tae-active-resource test-context --project projectA --space spaceA failed\n", expectedFailure: true, }, { - test: "with alternate command and ucp active resource update successfully", + test: "with alternate command and tae active resource update successfully", newCommandExitStatus: "0", - expectedOutput: "newcommand update ucp-active-resource test-context --project projectA --space spaceA succeeded\n", + expectedOutput: "newcommand update tae-active-resource test-context --project projectA --space spaceA succeeded\n", expectedFailure: false, enableCustomCommand: true, }, { - test: "with alternate command and ucp active resource update unsuccessfully", + test: "with alternate command and tae active resource update unsuccessfully", newCommandExitStatus: "1", - expectedOutput: "newcommand update ucp-active-resource test-context --project projectA --space spaceA failed\n", + expectedOutput: "newcommand update tae-active-resource test-context --project projectA --space spaceA failed\n", expectedFailure: true, enableCustomCommand: true, }, } for _, spec := range tests { - dir, err := os.MkdirTemp("", "tanzu-set-ucp-active-resource-api") + dir, err := os.MkdirTemp("", "tanzu-set-tae-active-resource-api") assert.Nil(t, err) defer os.RemoveAll(dir) t.Run(spec.test, func(t *testing.T) { @@ -289,9 +289,8 @@ func TestSetUCPContextActiveResource(t *testing.T) { os.Setenv("TANZU_BIN", cliPath) // Test-1: - // - verify correct combinedOutput string returned as part of the output // - verify correct string gets printed to default stdout and stderr - err = SetUCPContextActiveResource("test-context", "projectA", "spaceA") + err = SetTAEContextActiveResource("test-context", "projectA", "spaceA") w.Close() stdoutRecieved := <-c @@ -306,7 +305,7 @@ func TestSetUCPContextActiveResource(t *testing.T) { // Test-2: when external stdout and stderr are provided with WithStdout, WithStderr options, // verify correct string gets printed to provided custom stdout/stderr var combinedOutputBuff bytes.Buffer - err = SetUCPContextActiveResource("test-context", "projectA", "spaceA", WithOutputWriter(&combinedOutputBuff), WithErrorWriter(&combinedOutputBuff)) + err = SetTAEContextActiveResource("test-context", "projectA", "spaceA", WithOutputWriter(&combinedOutputBuff), WithErrorWriter(&combinedOutputBuff)) if spec.expectedFailure { assert.NotNil(err) } else {