From 4cef2fd583963d2c4e00d8b158b9602fcf47ef19 Mon Sep 17 00:00:00 2001 From: Chandra Pamuluri Date: Thu, 4 May 2023 17:23:01 -0500 Subject: [PATCH] change --- test/e2e/coexistence/cli_coexistence_test.go | 15 +++++++---- .../framework/config_lifecycle_operations.go | 7 +++++ test/e2e/framework/framework.go | 1 + test/e2e/framework/framework_helper.go | 2 +- test/e2e/framework/output_handling.go | 7 +++++ .../plugin_sync_k8s_lifecycle_suite_test.go | 26 ++++++++++++------- .../k8s/plugin_sync_k8s_lifecycle_test.go | 13 +++++++--- 7 files changed, 52 insertions(+), 19 deletions(-) diff --git a/test/e2e/coexistence/cli_coexistence_test.go b/test/e2e/coexistence/cli_coexistence_test.go index 80a2d72f6..5708e07f5 100644 --- a/test/e2e/coexistence/cli_coexistence_test.go +++ b/test/e2e/coexistence/cli_coexistence_test.go @@ -100,7 +100,8 @@ var _ = ginkgo.Describe("CLI Coexistence Tests", func() { gomega.Expect(err).To(gomega.BeNil(), "should not get any error for plugin source update") ginkgo.By("Search plugins and make sure there are plugins available using new Tanzu CLI") - pluginsSearchList := pluginlifecyclee2e.SearchAllPlugins(tf, framework.WithTanzuCommandPrefix(framework.TzPrefix)) + pluginsSearchList, err := pluginlifecyclee2e.SearchAllPlugins(tf, framework.WithTanzuCommandPrefix(framework.TzPrefix)) + gomega.Expect(err).To(gomega.BeNil(), framework.NoErrorForPluginSearch) gomega.Expect(len(pluginsSearchList)).Should(gomega.BeNumerically(">", 0)) ginkgo.By("Installing few plugins using new Tanzu CLI") @@ -175,7 +176,8 @@ var _ = ginkgo.Describe("CLI Coexistence Tests", func() { gomega.Expect(err).To(gomega.BeNil(), "should not get any error for plugin source update") ginkgo.By("Search plugins and make sure there are plugins available using new Tanzu CLI") - pluginsSearchList := pluginlifecyclee2e.SearchAllPlugins(tf) + pluginsSearchList, err := pluginlifecyclee2e.SearchAllPlugins(tf) + gomega.Expect(err).To(gomega.BeNil(), framework.NoErrorForPluginSearch) gomega.Expect(len(pluginsSearchList)).Should(gomega.BeNumerically(">", 0)) ginkgo.By("Installing few plugins using new Tanzu CLI") @@ -245,7 +247,8 @@ var _ = ginkgo.Describe("CLI Coexistence Tests", func() { gomega.Expect(err).To(gomega.BeNil(), "should not get any error for plugin source update") ginkgo.By("Search plugins and make sure there are plugins available using new Tanzu CLI") - pluginsSearchList := pluginlifecyclee2e.SearchAllPlugins(tf) + pluginsSearchList, err := pluginlifecyclee2e.SearchAllPlugins(tf) + gomega.Expect(err).To(gomega.BeNil(), framework.NoErrorForPluginSearch) gomega.Expect(len(pluginsSearchList)).Should(gomega.BeNumerically(">", 0)) ginkgo.By("Install few plugins using new Tanzu CLI") @@ -325,7 +328,8 @@ var _ = ginkgo.Describe("CLI Coexistence Tests", func() { gomega.Expect(err).To(gomega.BeNil(), "should not get any error for plugin source update") ginkgo.By("search plugins and make sure there are plugins available") - pluginsSearchList := pluginlifecyclee2e.SearchAllPlugins(tf, framework.WithTanzuCommandPrefix(framework.TzPrefix)) + pluginsSearchList, err := pluginlifecyclee2e.SearchAllPlugins(tf, framework.WithTanzuCommandPrefix(framework.TzPrefix)) + gomega.Expect(err).To(gomega.BeNil(), framework.NoErrorForPluginSearch) gomega.Expect(len(pluginsSearchList)).Should(gomega.BeNumerically(">", 0)) ginkgo.By("Install few plugins using new Tanzu CLI") @@ -405,7 +409,8 @@ var _ = ginkgo.Describe("CLI Coexistence Tests", func() { gomega.Expect(err).To(gomega.BeNil(), "should not get any error for plugin source update") ginkgo.By("search plugins and make sure there are plugins available using new Tanzu CLI") - pluginsSearchList := pluginlifecyclee2e.SearchAllPlugins(tf) + pluginsSearchList, err := pluginlifecyclee2e.SearchAllPlugins(tf) + gomega.Expect(err).To(gomega.BeNil(), framework.NoErrorForPluginSearch) gomega.Expect(len(pluginsSearchList)).Should(gomega.BeNumerically(">", 0)) ginkgo.By("Install few plugins using new Tanzu CLI") diff --git a/test/e2e/framework/config_lifecycle_operations.go b/test/e2e/framework/config_lifecycle_operations.go index 9315ac976..1ba3426c9 100644 --- a/test/e2e/framework/config_lifecycle_operations.go +++ b/test/e2e/framework/config_lifecycle_operations.go @@ -52,6 +52,9 @@ type ConfigCertOps interface { // ConfigCertDelete deletes cert config for a host, and returns error info ConfigCertDelete(host string, opts ...E2EOption) error + + // ConfigCertList list cert + ConfigCertList(opts ...E2EOption) ([]*CertDetails, error) } type ConfigCmdOps interface { @@ -187,3 +190,7 @@ func (co *configOps) ConfigCertDelete(host string, opts ...E2EOption) error { _, _, err := co.cmdExe.TanzuCmdExec(certDeleteCmd, opts...) return err } + +func (co *configOps) ConfigCertList(opts ...E2EOption) ([]*CertDetails, error) { + return ExecuteCmdAndBuildJSONOutput[CertDetails](co.cmdExe, ConfigCertList, opts...) +} diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index 045349718..42c7787f4 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -29,6 +29,7 @@ const ( ConfigServerDelete = "%s config server delete %s -y" ConfigCertAdd = "%s config cert add --host %s --ca-certificate %s --skip-cert-verify %s --insecure %s" ConfigCertDelete = "%s config cert delete %s" + ConfigCertList = "%s config cert list -o json" // Plugin commands UpdatePluginSource = "%s plugin source update %s --uri %s" diff --git a/test/e2e/framework/framework_helper.go b/test/e2e/framework/framework_helper.go index fbbdac3be..07956178f 100644 --- a/test/e2e/framework/framework_helper.go +++ b/test/e2e/framework/framework_helper.go @@ -106,7 +106,7 @@ func GetHomeDir() string { } // ExecuteCmdAndBuildJSONOutput is generic function to execute given command and build JSON output and return -func ExecuteCmdAndBuildJSONOutput[T PluginInfo | PluginSearch | PluginGroup | PluginSourceInfo | types.ClientConfig | Server | ContextListInfo](cmdExe CmdOps, cmd string, opts ...E2EOption) ([]*T, error) { +func ExecuteCmdAndBuildJSONOutput[T PluginInfo | PluginSearch | PluginGroup | PluginSourceInfo | types.ClientConfig | Server | ContextListInfo | CertDetails](cmdExe CmdOps, cmd string, opts ...E2EOption) ([]*T, error) { out, stdErr, err := cmdExe.TanzuCmdExec(cmd, opts...) if err != nil { diff --git a/test/e2e/framework/output_handling.go b/test/e2e/framework/output_handling.go index 6d7a9566a..4fd95747f 100644 --- a/test/e2e/framework/output_handling.go +++ b/test/e2e/framework/output_handling.go @@ -87,3 +87,10 @@ type TMCPluginsMockRequestResponseMapping struct { } `json:"headers"` } `json:"response"` } + +type CertDetails struct { + CaCertificate string `json:"ca-certificate"` + Host string `json:"host"` + Insecure string `json:"insecure"` + SkipCertVerification string `json:"skip-cert-verification"` +} diff --git a/test/e2e/plugin_sync/k8s/plugin_sync_k8s_lifecycle_suite_test.go b/test/e2e/plugin_sync/k8s/plugin_sync_k8s_lifecycle_suite_test.go index 303818389..2198b07b1 100644 --- a/test/e2e/plugin_sync/k8s/plugin_sync_k8s_lifecycle_suite_test.go +++ b/test/e2e/plugin_sync/k8s/plugin_sync_k8s_lifecycle_suite_test.go @@ -23,12 +23,14 @@ func TestPluginSyncLifecycle(t *testing.T) { } var ( - tf *framework.Framework - e2eTestLocalCentralRepoURL string - pluginsSearchList []*framework.PluginInfo - pluginGroups []*framework.PluginGroup - pluginGroupToPluginListMap map[string][]*framework.PluginInfo - usePluginsFromPluginGroup string + tf *framework.Framework + e2eTestLocalCentralRepoURL string + pluginsSearchList []*framework.PluginInfo + pluginGroups []*framework.PluginGroup + pluginGroupToPluginListMap map[string][]*framework.PluginInfo + usePluginsFromPluginGroup string + e2eTestLocalCentralRepoPluginHost string + e2eTestLocalCentralRepoCACertPath string ) const numberOfPluginsToInstall = 3 @@ -45,16 +47,20 @@ var _ = BeforeSuite(func() { _, err := tf.PluginCmd.UpdatePluginDiscoverySource(&framework.DiscoveryOptions{Name: "default", SourceType: framework.SourceType, URI: e2eTestLocalCentralRepoURL}) Expect(err).To(BeNil(), "should not get any error for plugin source update") - e2eTestLocalCentralRepoPluginHost := os.Getenv(framework.TanzuCliE2ETestLocalCentralRepositoryHost) + e2eTestLocalCentralRepoPluginHost = os.Getenv(framework.TanzuCliE2ETestLocalCentralRepositoryHost) Expect(e2eTestLocalCentralRepoPluginHost).NotTo(BeEmpty(), fmt.Sprintf("environment variable %s should set with local central repository host", framework.TanzuCliE2ETestLocalCentralRepositoryHost)) - e2eTestLocalCentralRepoCACertPath := os.Getenv(framework.TanzuCliE2ETestLocalCentralRepositoryCACertPath) + e2eTestLocalCentralRepoCACertPath = os.Getenv(framework.TanzuCliE2ETestLocalCentralRepositoryCACertPath) Expect(e2eTestLocalCentralRepoCACertPath).NotTo(BeEmpty(), fmt.Sprintf("environment variable %s should set with local central repository CA cert path", framework.TanzuCliE2ETestLocalCentralRepositoryCACertPath)) - // set up the CA cert fort local central repository + // set up the CA cert for local central repository _ = tf.Config.ConfigCertDelete(e2eTestLocalCentralRepoPluginHost) _, err = tf.Config.ConfigCertAdd(&framework.CertAddOptions{Host: e2eTestLocalCentralRepoPluginHost, CACertificatePath: e2eTestLocalCentralRepoCACertPath, SkipCertVerify: "false", Insecure: "false"}) - Expect(err).To(BeNil()) + Expect(err).To(BeNil(), "should not be any error for cert add") + // list and validate the cert added + list, err := tf.Config.ConfigCertList() + Expect(err).To(BeNil(), "should not be any error for cert list") + Expect(len(list)).To(Equal(1), "should not be any error for cert list") // set up the local central repository discovery image public key path e2eTestLocalCentralRepoPluginDiscoveryImageSignaturePublicKeyPath := os.Getenv(framework.TanzuCliE2ETestLocalCentralRepositoryPluginDiscoveryImageSignaturePublicKeyPath) diff --git a/test/e2e/plugin_sync/k8s/plugin_sync_k8s_lifecycle_test.go b/test/e2e/plugin_sync/k8s/plugin_sync_k8s_lifecycle_test.go index 55d6f3d99..f58a756cb 100644 --- a/test/e2e/plugin_sync/k8s/plugin_sync_k8s_lifecycle_test.go +++ b/test/e2e/plugin_sync/k8s/plugin_sync_k8s_lifecycle_test.go @@ -28,6 +28,13 @@ var _ = f.CLICoreDescribe("[Tests:E2E][Feature:Plugin-sync-lifecycle]", func() { // update plugin discovery source err = f.UpdatePluginDiscoverySource(tf, e2eTestLocalCentralRepoURL) Expect(err).To(BeNil(), "should not get any error for plugin source update") + + // Add Cert + _, err = tf.Config.ConfigCertAdd(&f.CertAddOptions{Host: e2eTestLocalCentralRepoPluginHost, CACertificatePath: e2eTestLocalCentralRepoCACertPath, SkipCertVerify: "false", Insecure: "false"}) + Expect(err).To(BeNil(), "should not be any error for cert add") + list, err := tf.Config.ConfigCertList() + Expect(err).To(BeNil(), "should not be any error for cert list") + Expect(len(list)).To(Equal(1), "should not be any error for cert list") }) }) @@ -108,9 +115,8 @@ var _ = f.CLICoreDescribe("[Tests:E2E][Feature:Plugin-sync-lifecycle]", func() { // Test case: c. create context and make sure context has created It("create context with kubeconfig and context", func() { - By("create context with kubeconfig and context") contextName = f.ContextPrefixK8s + f.RandomString(4) - err := tf.ContextCmd.CreateContextWithKubeconfig(contextName, clusterInfo.KubeConfigPath, clusterInfo.ClusterKubeContext) + err = tf.ContextCmd.CreateContextWithKubeconfig(contextName, clusterInfo.KubeConfigPath, clusterInfo.ClusterKubeContext) Expect(err).To(BeNil(), "context should create without any error") active, err := tf.ContextCmd.GetActiveContext(string(types.TargetK8s)) Expect(err).To(BeNil(), "there should be a active context") @@ -217,8 +223,9 @@ var _ = f.CLICoreDescribe("[Tests:E2E][Feature:Plugin-sync-lifecycle]", func() { // Test case: e. run plugin sync and validate the plugin list It("run plugin sync and validate err response in plugin sync, validate plugin list output", func() { + // sync should fail with error as there is a plugin which does not exists in repository with the given random version _, err = tf.PluginCmd.Sync() - Expect(err.Error()).To(ContainSubstring(fmt.Sprintf(f.UnableToFindPluginForTarget, pluginsWithIncorrectVer[0].Name, pluginsWithIncorrectVer[0].Target))) + Expect(err.Error()).To(ContainSubstring(fmt.Sprintf(f.UnableToFindPluginWithVersionForTarget, pluginsWithIncorrectVer[0].Name, pluginsWithIncorrectVer[0].Version, pluginsWithIncorrectVer[0].Target))) pluginsList, err = tf.PluginCmd.ListPluginsForGivenContext(contextName, true) Expect(err).To(BeNil(), "should not get any error for plugin list")