diff options
author | Igor D.C <igor.duarte.cardoso@intel.com> | 2020-07-29 01:37:15 +0000 |
---|---|---|
committer | Igor D.C <igor.duarte.cardoso@intel.com> | 2020-08-05 23:03:58 +0000 |
commit | 11dda8300d3872f9414e7fff0402fd6fcbf6d537 (patch) | |
tree | 623f1df58e6964c19eedae9cbd983a0971be26ee /src/dcm/pkg/module/logicalcloud_test.go | |
parent | 2300429de7a5b316172c549456f91a68cba89f83 (diff) |
DCM - fix code formatting via vscode (II)
Part two of fixing code format/syntax with Visual Studio Code.
Furthermore, also switched line endings from CRLF to LF (all test
files seemed to be ending this way, unlike the other Go files).
Issue-ID: MULTICLOUD-1143
Signed-off-by: Igor D.C <igor.duarte.cardoso@intel.com>
Change-Id: Iaae868c780a42ea82ca1208e3cbdc3ec6ffd1f97
Diffstat (limited to 'src/dcm/pkg/module/logicalcloud_test.go')
-rw-r--r-- | src/dcm/pkg/module/logicalcloud_test.go | 313 |
1 files changed, 156 insertions, 157 deletions
diff --git a/src/dcm/pkg/module/logicalcloud_test.go b/src/dcm/pkg/module/logicalcloud_test.go index 882cc292..fb205753 100644 --- a/src/dcm/pkg/module/logicalcloud_test.go +++ b/src/dcm/pkg/module/logicalcloud_test.go @@ -1,157 +1,156 @@ -package module
-
-import (
- "fmt"
- "testing"
-
- "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/db"
- "github.com/stretchr/testify/mock"
- "github.com/pkg/errors"
-
-)
-
-type mockValues struct {
- mock.Mock
-}
-
-func (m *mockValues) DBInsert(name string, key db.Key, query interface {}, meta string, c interface {}) error{
- fmt.Println("Mocked Insert operation in Mongo")
- args := m.Called(name, key, nil, meta, c)
-
- return args.Error(0)
-}
-
-func (m *mockValues) DBFind(name string, key db.Key, meta string) ([][]byte, error) {
- fmt.Println("Mocked Mongo DB Find Operation")
- args := m.Called(name, key, meta)
-
- return args.Get(0).([][]byte), args.Error(1)
-}
-
-func (m *mockValues) DBUnmarshal(value []byte, out interface{}) error {
- fmt.Println("Mocked Mongo DB Unmarshal Operation")
- args := m.Called(value)
-
- return args.Error(0)
-}
-
-func (m *mockValues) DBRemove(name string, key db.Key) error {
- fmt.Println("Mocked Mongo DB Remove operation")
- args := m.Called(name, key)
-
- return args.Error(0)
-}
-
-func (m *mockValues) CheckProject(project string) error {
- fmt.Println("Mocked Check Project exists")
- args := m.Called(project)
-
- return args.Error(0)
-}
-
-func (m *mockValues) CheckLogicalCloud(project, logicalCloud string) error {
- fmt.Println("Mocked Check Logical Cloud exists")
- args := m.Called(project, logicalCloud)
-
- return args.Error(0)
-}
-
-func TestCreateLogicalCloud(t *testing.T) {
-
- mData := MetaDataList{
- LogicalCloudName: "test_asdf",
- }
-
- lc := LogicalCloud {
- MetaData: mData,
- }
- data1 := [][]byte{}
-
- key := LogicalCloudKey{
- Project: "test_project",
- LogicalCloudName: "test_asdf",
- }
- myMocks := new(mockValues)
- // just to get an error value
- err1 := errors.New("math: square root of negative number")
-
- myMocks.On("CheckProject", "test_project").Return(nil)
- myMocks.On("DBInsert", "test_dcm", key, nil, "test_meta", lc).Return(nil)
- myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, err1)
-
- lcClient := LogicalCloudClient{"test_dcm", "test_meta", myMocks}
- _, err := lcClient.Create("test_project", lc)
- if err != nil {
- t.Errorf("Some error occured!")
- }
-}
-
-func TestGetLogicalCloud(t *testing.T) {
- key := LogicalCloudKey{
- Project: "test_project",
- LogicalCloudName: "test_asdf",
- }
-
- data1 := [][]byte{
- []byte("abc"),
- }
-
- data2 := []byte("abc")
-
- myMocks := new(mockValues)
-
- myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, nil)
- myMocks.On("DBUnmarshal", data2).Return(nil)
- lcClient := LogicalCloudClient{"test_dcm", "test_meta", myMocks}
- _, err := lcClient.Get("test_project", "test_asdf")
- if err != nil {
- t.Errorf("Some error occured!")
- }
-}
-
-func TestDeleteLogicalCloud(t *testing.T) {
-
- key := LogicalCloudKey{
- Project: "test_project",
- LogicalCloudName: "test_asdf",
- }
-
- myMocks := new(mockValues)
-
- myMocks.On("DBRemove", "test_dcm", key).Return(nil)
-
- lcClient := LogicalCloudClient{"test_dcm", "test_meta", myMocks}
- err := lcClient.Delete("test_project", "test_asdf")
- if err != nil {
- t.Errorf("Some error occured!")
- }
-
-}
-
-func TestUpdateLogicalCloud(t *testing.T) {
- key := LogicalCloudKey{
- Project: "test_project",
- LogicalCloudName: "test_asdf",
- }
- mData := MetaDataList{
- LogicalCloudName: "test_asdf",
- }
- lc := LogicalCloud{
- MetaData: mData,
- }
- data1 := [][]byte{
- []byte("abc"),
- }
- data2 := []byte("abc")
-
- myMocks := new(mockValues)
-
- myMocks.On("DBInsert", "test_dcm", key, nil, "test_meta", lc).Return(nil)
- myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, nil)
- myMocks.On("DBUnmarshal", data2).Return(nil)
- lcClient := LogicalCloudClient{"test_dcm", "test_meta", myMocks}
- _, err := lcClient.Update("test_project", "test_asdf", lc)
- if err != nil {
- t.Errorf("Some error occured!")
- }
-}
+package module + +import ( + "fmt" + "testing" + + "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/db" + "github.com/pkg/errors" + "github.com/stretchr/testify/mock" +) + +type mockValues struct { + mock.Mock +} + +func (m *mockValues) DBInsert(name string, key db.Key, query interface{}, meta string, c interface{}) error { + fmt.Println("Mocked Insert operation in Mongo") + args := m.Called(name, key, nil, meta, c) + + return args.Error(0) +} + +func (m *mockValues) DBFind(name string, key db.Key, meta string) ([][]byte, error) { + fmt.Println("Mocked Mongo DB Find Operation") + args := m.Called(name, key, meta) + + return args.Get(0).([][]byte), args.Error(1) +} + +func (m *mockValues) DBUnmarshal(value []byte, out interface{}) error { + fmt.Println("Mocked Mongo DB Unmarshal Operation") + args := m.Called(value) + + return args.Error(0) +} + +func (m *mockValues) DBRemove(name string, key db.Key) error { + fmt.Println("Mocked Mongo DB Remove operation") + args := m.Called(name, key) + + return args.Error(0) +} + +func (m *mockValues) CheckProject(project string) error { + fmt.Println("Mocked Check Project exists") + args := m.Called(project) + + return args.Error(0) +} + +func (m *mockValues) CheckLogicalCloud(project, logicalCloud string) error { + fmt.Println("Mocked Check Logical Cloud exists") + args := m.Called(project, logicalCloud) + + return args.Error(0) +} + +func TestCreateLogicalCloud(t *testing.T) { + + mData := MetaDataList{ + LogicalCloudName: "test_asdf", + } + + lc := LogicalCloud{ + MetaData: mData, + } + data1 := [][]byte{} + + key := LogicalCloudKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + } + myMocks := new(mockValues) + // just to get an error value + err1 := errors.New("math: square root of negative number") + + myMocks.On("CheckProject", "test_project").Return(nil) + myMocks.On("DBInsert", "test_dcm", key, nil, "test_meta", lc).Return(nil) + myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, err1) + + lcClient := LogicalCloudClient{"test_dcm", "test_meta", myMocks} + _, err := lcClient.Create("test_project", lc) + if err != nil { + t.Errorf("Some error occured!") + } +} + +func TestGetLogicalCloud(t *testing.T) { + key := LogicalCloudKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + } + + data1 := [][]byte{ + []byte("abc"), + } + + data2 := []byte("abc") + + myMocks := new(mockValues) + + myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, nil) + myMocks.On("DBUnmarshal", data2).Return(nil) + lcClient := LogicalCloudClient{"test_dcm", "test_meta", myMocks} + _, err := lcClient.Get("test_project", "test_asdf") + if err != nil { + t.Errorf("Some error occured!") + } +} + +func TestDeleteLogicalCloud(t *testing.T) { + + key := LogicalCloudKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + } + + myMocks := new(mockValues) + + myMocks.On("DBRemove", "test_dcm", key).Return(nil) + + lcClient := LogicalCloudClient{"test_dcm", "test_meta", myMocks} + err := lcClient.Delete("test_project", "test_asdf") + if err != nil { + t.Errorf("Some error occured!") + } + +} + +func TestUpdateLogicalCloud(t *testing.T) { + key := LogicalCloudKey{ + Project: "test_project", + LogicalCloudName: "test_asdf", + } + mData := MetaDataList{ + LogicalCloudName: "test_asdf", + } + lc := LogicalCloud{ + MetaData: mData, + } + data1 := [][]byte{ + []byte("abc"), + } + data2 := []byte("abc") + + myMocks := new(mockValues) + + myMocks.On("DBInsert", "test_dcm", key, nil, "test_meta", lc).Return(nil) + myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, nil) + myMocks.On("DBUnmarshal", data2).Return(nil) + lcClient := LogicalCloudClient{"test_dcm", "test_meta", myMocks} + _, err := lcClient.Update("test_project", "test_asdf", lc) + if err != nil { + t.Errorf("Some error occured!") + } +} |