-
Notifications
You must be signed in to change notification settings - Fork 21
/
plugins_compatibility_helper.go
74 lines (66 loc) · 3.08 KB
/
plugins_compatibility_helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2023 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// Package plugincompatibility provides plugins compatibility E2E test cases
package plugincompatibility
import (
"fmt"
"strings"
"github.com/onsi/gomega"
"github.com/vmware-tanzu/tanzu-cli/test/e2e/framework"
"github.com/vmware-tanzu/tanzu-plugin-runtime/log"
)
// PluginsForCompatibilityTesting search for test-plugin-'s from the test central repository and returns all test-plugin-'s
func PluginsForCompatibilityTesting(tf *framework.Framework) []*framework.PluginInfo {
list, _, _, err := tf.PluginCmd.SearchPlugins("")
gomega.Expect(err).To(gomega.BeNil(), "should not occur any error while searching for plugins")
testPlugins := make([]*framework.PluginInfo, 0)
for _, plugin := range list {
if strings.HasPrefix(plugin.Name, framework.TestPluginsPrefix) {
testPlugins = append(testPlugins, plugin)
}
}
return testPlugins
}
// IsAllPluginsInstalled takes list of plugins and checks if all plugins are installed
func IsAllPluginsInstalled(tf *framework.Framework, plugins []*framework.PluginInfo) bool {
pluginListOutput, _, _, err := tf.PluginCmd.ListPlugins()
gomega.Expect(err).To(gomega.BeNil(), "should not occur any error while listing plugins")
pluginMap := framework.PluginListToSet(plugins)
for _, pluginInfo := range pluginListOutput {
key := fmt.Sprintf(framework.PluginKey, pluginInfo.Name, pluginInfo.Target, pluginInfo.Version)
_, ok := pluginMap[key]
if ok && pluginInfo.Status == framework.Installed {
delete(pluginMap, key)
}
}
return len(pluginMap) == 0
}
// IsAllPluginsUnInstalled takes list of plugins and checks if all plugins are uninstalled
func IsAllPluginsUnInstalled(tf *framework.Framework, plugins []*framework.PluginInfo) bool {
pluginListOutput, _, _, err := tf.PluginCmd.ListPlugins()
gomega.Expect(err).To(gomega.BeNil(), "should not occur any error while listing plugins")
pluginMap := framework.PluginListToSet(plugins)
for _, pluginInfo := range pluginListOutput {
key := fmt.Sprintf(framework.PluginKey, pluginInfo.Name, pluginInfo.Target, pluginInfo.Version)
_, ok := pluginMap[key]
if ok && pluginInfo.Status == framework.Installed {
delete(pluginMap, key)
log.Errorf(" %s plugin is installed", pluginInfo.Name)
}
}
return len(pluginMap) == len(plugins)
}
// UninstallPlugins lists plugins and uninstalls provided plugins if any plugins are installed
func UninstallPlugins(tf *framework.Framework, plugins []*framework.PluginInfo) {
pluginListOutput, _, _, err := tf.PluginCmd.ListPlugins()
gomega.Expect(err).To(gomega.BeNil(), "should not occur any error while listing plugins")
pluginMap := framework.PluginListToSet(plugins)
for _, pluginInfo := range pluginListOutput {
key := fmt.Sprintf(framework.PluginKey, pluginInfo.Name, pluginInfo.Target, pluginInfo.Version)
_, ok := pluginMap[key]
if ok && pluginInfo.Status == framework.Installed {
err := tf.PluginCmd.UninstallPlugin(pluginInfo.Name, pluginInfo.Target)
gomega.Expect(err).To(gomega.BeNil(), fmt.Sprintf("error while uninstalling plugin: %s", pluginInfo.Name))
}
}
}