From 083465d10c8fdeaffa89aa7daa93def3eca77df1 Mon Sep 17 00:00:00 2001 From: Victor Morales Date: Thu, 24 Jan 2019 17:46:43 -0800 Subject: Use a standard Go project layout This project wasn't following some Standard Go Project Layout guidelines(https://github.com/golang-standards/project-layout). This change pretends to organize the source code and following those guidelines. Change-Id: I61085ac20f28069cede013f83034bed06892d87c Signed-off-by: Victor Morales Issue-ID: MULTICLOUD-301 --- src/k8splugin/plugins/network/plugin.go | 16 +++++++++------- src/k8splugin/plugins/network/plugin_test.go | 25 +++++++++++++------------ 2 files changed, 22 insertions(+), 19 deletions(-) (limited to 'src/k8splugin/plugins/network') diff --git a/src/k8splugin/plugins/network/plugin.go b/src/k8splugin/plugins/network/plugin.go index d54fc429..fb163189 100644 --- a/src/k8splugin/plugins/network/plugin.go +++ b/src/k8splugin/plugins/network/plugin.go @@ -14,11 +14,13 @@ limitations under the License. package main import ( - pkgerrors "github.com/pkg/errors" - "k8s.io/client-go/kubernetes" - "k8splugin/krd" "k8splugin/plugins/network/v1" "regexp" + + utils "k8splugin/internal" + + pkgerrors "github.com/pkg/errors" + "k8s.io/client-go/kubernetes" ) func extractData(data string) (vnfID, cniType, networkName string) { @@ -34,9 +36,9 @@ func extractData(data string) (vnfID, cniType, networkName string) { } // Create an ONAP Network object -func Create(data *krd.ResourceData, client kubernetes.Interface) (string, error) { +func Create(data *utils.ResourceData, client kubernetes.Interface) (string, error) { network := &v1.OnapNetwork{} - if _, err := krd.DecodeYAML(data.YamlFilePath, network); err != nil { + if _, err := utils.DecodeYAML(data.YamlFilePath, network); err != nil { return "", pkgerrors.Wrap(err, "Decode network object error") } @@ -46,7 +48,7 @@ func Create(data *krd.ResourceData, client kubernetes.Interface) (string, error) } cniType := config["cnitype"].(string) - typePlugin, ok := krd.LoadedPlugins[cniType+"-network"] + typePlugin, ok := utils.LoadedPlugins[cniType+"-network"] if !ok { return "", pkgerrors.New("No plugin for resource " + cniType + " found") } @@ -72,7 +74,7 @@ func List(namespace string, kubeclient kubernetes.Interface) ([]string, error) { // Delete an existing Network func Delete(name string, namespace string, kubeclient kubernetes.Interface) error { _, cniType, networkName := extractData(name) - typePlugin, ok := krd.LoadedPlugins[cniType+"-network"] + typePlugin, ok := utils.LoadedPlugins[cniType+"-network"] if !ok { return pkgerrors.New("No plugin for resource " + cniType + " found") } diff --git a/src/k8splugin/plugins/network/plugin_test.go b/src/k8splugin/plugins/network/plugin_test.go index 325de31f..02391177 100644 --- a/src/k8splugin/plugins/network/plugin_test.go +++ b/src/k8splugin/plugins/network/plugin_test.go @@ -16,13 +16,14 @@ limitations under the License. package main import ( - pkgerrors "github.com/pkg/errors" - "k8splugin/krd" + utils "k8splugin/internal" "os" "plugin" "reflect" "strings" "testing" + + pkgerrors "github.com/pkg/errors" ) func LoadMockNetworkPlugins(krdLoadedPlugins *map[string]*plugin.Plugin, networkName, errMsg string) error { @@ -53,15 +54,15 @@ func LoadMockNetworkPlugins(krdLoadedPlugins *map[string]*plugin.Plugin, network func TestCreateNetwork(t *testing.T) { internalVNFID := "1" - oldkrdPluginData := krd.LoadedPlugins + oldkrdPluginData := utils.LoadedPlugins defer func() { - krd.LoadedPlugins = oldkrdPluginData + utils.LoadedPlugins = oldkrdPluginData }() testCases := []struct { label string - input *krd.ResourceData + input *utils.ResourceData mockError string mockOutput string expectedResult string @@ -69,14 +70,14 @@ func TestCreateNetwork(t *testing.T) { }{ { label: "Fail to decode a network object", - input: &krd.ResourceData{ + input: &utils.ResourceData{ YamlFilePath: "../../mock_files/mock_yamls/service.yaml", }, expectedError: "Fail to decode network's configuration: Invalid configuration value", }, { label: "Fail to create a network", - input: &krd.ResourceData{ + input: &utils.ResourceData{ YamlFilePath: "../../mock_files/mock_yamls/ovn4nfvk8s.yaml", }, mockError: "Internal error", @@ -84,7 +85,7 @@ func TestCreateNetwork(t *testing.T) { }, { label: "Successfully create a ovn4nfv network", - input: &krd.ResourceData{ + input: &utils.ResourceData{ VnfId: internalVNFID, YamlFilePath: "../../mock_files/mock_yamls/ovn4nfvk8s.yaml", }, @@ -95,7 +96,7 @@ func TestCreateNetwork(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { - err := LoadMockNetworkPlugins(&krd.LoadedPlugins, testCase.mockOutput, testCase.mockError) + err := LoadMockNetworkPlugins(&utils.LoadedPlugins, testCase.mockOutput, testCase.mockError) if err != nil { t.Fatalf("TestCreateNetwork returned an error (%s)", err) } @@ -121,10 +122,10 @@ func TestCreateNetwork(t *testing.T) { } func TestDeleteNetwork(t *testing.T) { - oldkrdPluginData := krd.LoadedPlugins + oldkrdPluginData := utils.LoadedPlugins defer func() { - krd.LoadedPlugins = oldkrdPluginData + utils.LoadedPlugins = oldkrdPluginData }() testCases := []struct { @@ -154,7 +155,7 @@ func TestDeleteNetwork(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.label, func(t *testing.T) { - err := LoadMockNetworkPlugins(&krd.LoadedPlugins, testCase.mockOutput, testCase.mockError) + err := LoadMockNetworkPlugins(&utils.LoadedPlugins, testCase.mockOutput, testCase.mockError) if err != nil { t.Fatalf("TestDeleteNetwork returned an error (%s)", err) } -- cgit 1.2.3-korg