diff options
author | Victor Morales <victor.morales@intel.com> | 2019-01-24 17:46:43 -0800 |
---|---|---|
committer | Victor Morales <victor.morales@intel.com> | 2019-01-25 16:52:38 -0800 |
commit | 083465d10c8fdeaffa89aa7daa93def3eca77df1 (patch) | |
tree | 23135a724a1628e986f9c6748b82f275763cdf10 /src/k8splugin/plugins/network | |
parent | 5c4e91705457dc4bdb5526e6f5210fa879ab659d (diff) |
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 <victor.morales@intel.com>
Issue-ID: MULTICLOUD-301
Diffstat (limited to 'src/k8splugin/plugins/network')
-rw-r--r-- | src/k8splugin/plugins/network/plugin.go | 16 | ||||
-rw-r--r-- | src/k8splugin/plugins/network/plugin_test.go | 25 |
2 files changed, 22 insertions, 19 deletions
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) } |