-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chandra Pamuluri
committed
Apr 25, 2023
1 parent
67cffd7
commit 4a79f01
Showing
9 changed files
with
544 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...plugin_sync/plugin_sync_lifecycle_test.go → ...ync/k8s/plugin_sync_k8s_lifecycle_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"/v1alpha1/system/binaries/plugins": "/plugins" | ||
} |
137 changes: 137 additions & 0 deletions
137
test/e2e/plugin_sync/tmc/plugin_sync_tmc_lifecycle_suite_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// Copyright 2023 VMware, Inc. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// pluginsynce2etmc provides plugin sync command specific E2E test cases | ||
package pluginsynce2etmc | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/vmware-tanzu/tanzu-cli/test/e2e/framework" | ||
helper "github.com/vmware-tanzu/tanzu-cli/test/e2e/plugin_lifecycle" | ||
) | ||
|
||
func TestPluginSyncLifecycle(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Plugin-Sync-TMC-Lifecycle E2E Test Suite") | ||
} | ||
|
||
var ( | ||
tf *framework.Framework | ||
e2eTestLocalCentralRepoURL string | ||
pluginsSearchList []*framework.PluginInfo | ||
pluginGroups []*framework.PluginGroup | ||
pluginGroupToPluginListMap map[string][]*framework.PluginInfo | ||
routesFilePath, serverFilePath, tmcConfigDir string | ||
) | ||
|
||
const routesMapping = "{\"/v1alpha1/system/binaries/plugins\": \"/pluginsInfo\"}" | ||
const routesFile = "routes.json" | ||
const serverFile = "server.json" | ||
const CRDFilePath = "../framework/config/cli.tanzu.vmware.com_cliplugins.yaml" | ||
const numberOfPluginsToInstall = 3 | ||
const startRestAPIMockServerCMD = "docker run --init --rm -d -p 80:80 --name %s -v %s:/data/ clue/json-server %s --routes %s" | ||
const stopRestAPIMockServerCMD = "docker container stop %s" | ||
const restAPIMockContainerName = "restAPIMockServer" | ||
const ContextNamePrefix = "tmc-sync-" | ||
const mockServerEndpoint = "http://localhost:80" | ||
|
||
// BeforeSuite initializes and set up the environment to execute the plugin life cycle and plugin group life cycle end-to-end test cases | ||
var _ = BeforeSuite(func() { | ||
tf = framework.NewFramework() | ||
|
||
// remove this | ||
os.Setenv(framework.TanzuAPIToken, "8bczHt0X4G5rPoVzFnkgM8p5s7YE5FngQ9sqCqc6UrQWBTGMyPP_Jsu6k7xATffV") | ||
os.Setenv(framework.TanzuCliE2ETestLocalCentralRepositoryURL, "localhost:9876/tanzu-cli/plugins/central:small") | ||
os.Setenv("TANZU_CLI_PLUGIN_DISCOVERY_IMAGE_SIGNATURE_VERIFICATION_SKIP_LIST", "localhost:9876/tanzu-cli/plugins/central:small") | ||
|
||
// check E2E test central repo URL (TANZU_CLI_E2E_TEST_LOCAL_CENTRAL_REPO_URL) | ||
e2eTestLocalCentralRepoURL = os.Getenv(framework.TanzuCliE2ETestLocalCentralRepositoryURL) | ||
Expect(e2eTestLocalCentralRepoURL).NotTo(BeEmpty(), fmt.Sprintf("environment variable %s should set with local central repository URL", framework.TanzuCliE2ETestLocalCentralRepositoryURL)) | ||
// set E2E test central repo URL to TANZU_CLI_PRE_RELEASE_REPO_IMAGE | ||
os.Setenv(framework.CentralRepositoryPreReleaseRepoImage, e2eTestLocalCentralRepoURL) | ||
// check | ||
Expect(os.Getenv(framework.TanzuAPIToken)).NotTo(BeEmpty(), fmt.Sprintf("environment variable %s should set with TMC API Token", framework.TanzuAPIToken)) | ||
|
||
pwd, err := os.Getwd() | ||
Expect(err).To(BeNil(), "should not get any error for getting working directory") | ||
tmcConfigDir = filepath.Join(pwd, "config") | ||
routesFilePath = filepath.Join(tmcConfigDir, routesFile) | ||
serverFilePath = filepath.Join(tmcConfigDir, serverFile) | ||
|
||
/* | ||
tmcConfigDir = filepath.Join(framework.FullPathForTempDir, "tmc") | ||
_ = framework.CreateDir(tmcConfigDir) | ||
*/ | ||
|
||
// search plugin groups and make sure there plugin groups available | ||
pluginGroups = helper.SearchAllPluginGroups(tf) | ||
|
||
// check all required plugin groups (framework.PluginGroupsForLifeCycleTests) need for life cycle test are available in plugin group search output | ||
Expect(framework.IsAllPluginGroupsExists(pluginGroups, framework.PluginGroupsForLifeCycleTests)).Should(BeTrue(), "all required plugin groups for life cycle tests should exists in plugin group search output") | ||
|
||
// search plugins and make sure there are plugins available | ||
pluginsSearchList = helper.SearchAllPlugins(tf) | ||
Expect(len(pluginsSearchList)).Should(BeNumerically(">", 0)) | ||
|
||
// check all required plugins (framework.PluginsForLifeCycleTests) for plugin life cycle e2e are available in plugin search output | ||
framework.CheckAllPluginsExists(pluginsSearchList, framework.PluginsForLifeCycleTests) | ||
|
||
pluginGroupToPluginListMap = framework.MapPluginsToPluginGroups(pluginsSearchList, framework.PluginGroupsForLifeCycleTests) | ||
for pluginGroupLatest := range framework.PluginGroupsLatestToOldVersions { | ||
framework.CopyPluginsBetweenPluginGroupsAndUpdatePluginsVersion(pluginGroupToPluginListMap, pluginGroupLatest, framework.PluginGroupsLatestToOldVersions[pluginGroupLatest], strings.Split(framework.PluginGroupsLatestToOldVersions[pluginGroupLatest], "/")[1]) | ||
} | ||
|
||
// check for every plugin group (in framework.PluginGroupsForLifeCycleTests) there should be plugins available | ||
for pg := range pluginGroupToPluginListMap { | ||
Expect(len(pluginGroupToPluginListMap[pg])).Should(BeNumerically(">", 0), "there should be at least one plugin available for each plugin group in plugin group life cycle list") | ||
} | ||
}) | ||
|
||
// AfterSuite deletes the temp directory created during test cases execution | ||
var _ = AfterSuite(func() { | ||
err := os.RemoveAll(framework.FullPathForTempDir) // delete an entire directory | ||
Expect(err).To(BeNil(), "should not get any error while deleting temp directory") | ||
}) | ||
|
||
func ApplyConfigOnKindCluster(tf *framework.Framework, clusterInfo *framework.ClusterInfo, confFilePaths []string) { | ||
for _, pluginCRFilePaths := range confFilePaths { | ||
err := tf.KindCluster.ApplyConfig(clusterInfo.ClusterKubeContext, pluginCRFilePaths) | ||
Expect(err).To(BeNil(), "should not get any error for config apply") | ||
} | ||
} | ||
|
||
func WriteToFileInJSONFormat(crd framework.TMCPluginsCRD, filePath string) error { | ||
content, err := json.Marshal(crd) | ||
if err != nil { | ||
return err | ||
} | ||
err = ioutil.WriteFile(filePath, content, 0644) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func StartRESTAPIMockServer(tf *framework.Framework, configPath, serverFileName, routesFileName, containerName string) error { | ||
err := StopRestAPIMockServer(tf, containerName) | ||
//const startRestAPIMockServerCMD = "docker run --init --rm -d -p 80:80 --name %s -v %s:/data/ clue/json-server %s --routes %s" | ||
cmd := fmt.Sprintf(startRestAPIMockServerCMD, containerName, configPath, serverFileName, routesFileName) | ||
_, _, err = tf.Exec.Exec(cmd) | ||
return err | ||
} | ||
|
||
func StopRestAPIMockServer(tf *framework.Framework, containerName string) error { | ||
cmd := fmt.Sprintf(stopRestAPIMockServerCMD, containerName) | ||
_, _, err := tf.Exec.Exec(cmd) | ||
return err | ||
} |
Oops, something went wrong.