Skip to content

Commit

Permalink
change
Browse files Browse the repository at this point in the history
  • Loading branch information
Chandra Pamuluri committed May 5, 2023
1 parent f37ff13 commit 4cef2fd
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 19 deletions.
15 changes: 10 additions & 5 deletions test/e2e/coexistence/cli_coexistence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/framework/config_lifecycle_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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...)
}
1 change: 1 addition & 0 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/framework/framework_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/framework/output_handling.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
26 changes: 16 additions & 10 deletions test/e2e/plugin_sync/k8s/plugin_sync_k8s_lifecycle_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
13 changes: 10 additions & 3 deletions test/e2e/plugin_sync/k8s/plugin_sync_k8s_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
})

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 4cef2fd

Please sign in to comment.