summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/app/client_test.go
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2019-03-28 12:53:13 -0700
committerKiran Kamineni <kiran.k.kamineni@intel.com>2019-04-03 15:31:31 -0700
commitf74ad24c6034294c1915f5778adb259dd65c9208 (patch)
tree03cf8ba86d1f966b9a342b325bd2fb36bf1dcc59 /src/k8splugin/internal/app/client_test.go
parente97d3fddc255b73f87a8b3dbd8fa505e34247504 (diff)
Refactor instance code
Issue-ID: MULTICLOUD-350 Change-Id: I2574d94e4ebada1e138913b2a03549dd90906d7b Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/internal/app/client_test.go')
-rw-r--r--src/k8splugin/internal/app/client_test.go92
1 files changed, 88 insertions, 4 deletions
diff --git a/src/k8splugin/internal/app/client_test.go b/src/k8splugin/internal/app/client_test.go
index 71892725..5999cfa0 100644
--- a/src/k8splugin/internal/app/client_test.go
+++ b/src/k8splugin/internal/app/client_test.go
@@ -14,21 +14,105 @@ limitations under the License.
package app
import (
+ "os"
+ "plugin"
"reflect"
"testing"
+
+ utils "k8splugin/internal"
+
+ pkgerrors "github.com/pkg/errors"
+ "k8s.io/client-go/kubernetes"
)
-func TestGetKubeClient(t *testing.T) {
+func LoadMockPlugins(krdLoadedPlugins map[string]*plugin.Plugin) error {
+ if _, err := os.Stat("../../mock_files/mock_plugins/mockplugin.so"); os.IsNotExist(err) {
+ return pkgerrors.New("mockplugin.so does not exist. Please compile mockplugin.go to generate")
+ }
+
+ mockPlugin, err := plugin.Open("../../mock_files/mock_plugins/mockplugin.so")
+ if err != nil {
+ return pkgerrors.Wrap(err, "Opening mock plugins")
+ }
+
+ krdLoadedPlugins["namespace"] = mockPlugin
+ krdLoadedPlugins["deployment"] = mockPlugin
+ krdLoadedPlugins["service"] = mockPlugin
+
+ return nil
+}
+
+func TestInit(t *testing.T) {
t.Run("Successfully create Kube Client", func(t *testing.T) {
- clientset, err := GetKubeClient("../../mock_files/mock_configs/mock_config")
+ kubeClient := kubernetesClient{}
+ err := kubeClient.init("../../mock_files/mock_configs/mock_config")
if err != nil {
t.Fatalf("TestGetKubeClient returned an error (%s)", err)
}
- if reflect.TypeOf(clientset).Name() != "Clientset" {
- t.Fatalf("TestGetKubeClient returned :\n result=%v\n expected=%v", clientset, "Clientset")
+ name := reflect.TypeOf(kubeClient.clientSet).Elem().Name()
+ if name != "Clientset" {
+ t.Fatalf("TestGetKubeClient returned :\n result=%v\n expected=%v", name, "Clientset")
}
})
}
+
+func TestCreateResources(t *testing.T) {
+ oldkrdPluginData := utils.LoadedPlugins
+
+ defer func() {
+ utils.LoadedPlugins = oldkrdPluginData
+ }()
+
+ err := LoadMockPlugins(utils.LoadedPlugins)
+ if err != nil {
+ t.Fatalf("LoadMockPlugins returned an error (%s)", err)
+ }
+
+ k8 := kubernetesClient{
+ clientSet: &kubernetes.Clientset{},
+ }
+
+ t.Run("Successfully delete resources", func(t *testing.T) {
+ data := map[string][]string{
+ "Deployment": []string{"../../mock_files/mock_yamls/deployment.yaml"},
+ "Service": []string{"../../mock_files/mock_yamls/service.yaml"},
+ }
+
+ _, err := k8.createResources(data, "testnamespace")
+ if err != nil {
+ t.Fatalf("TestCreateResources returned an error (%s)", err)
+ }
+ })
+}
+
+func TestDeleteResources(t *testing.T) {
+ oldkrdPluginData := utils.LoadedPlugins
+
+ defer func() {
+ utils.LoadedPlugins = oldkrdPluginData
+ }()
+
+ err := LoadMockPlugins(utils.LoadedPlugins)
+ if err != nil {
+ t.Fatalf("LoadMockPlugins returned an error (%s)", err)
+ }
+
+ k8 := kubernetesClient{
+ clientSet: &kubernetes.Clientset{},
+ }
+
+ t.Run("Successfully delete resources", func(t *testing.T) {
+ data := map[string][]string{
+ "Deployment": []string{"deployment-1", "deployment-2"},
+ "Service": []string{"service-1", "service-2"},
+ }
+
+ err := k8.deleteResources(data, "test")
+ if err != nil {
+ t.Fatalf("TestCreateVNF returned an error (%s)", err)
+ }
+ })
+}