aboutsummaryrefslogtreecommitdiffstats
path: root/src/dcm/pkg/module/logicalcloud_test.go
diff options
context:
space:
mode:
authorIgor D.C <igor.duarte.cardoso@intel.com>2020-10-08 18:44:14 +0000
committerIgor D.C <igor.duarte.cardoso@intel.com>2020-10-10 05:12:08 +0000
commit5e013d0d327dee9f5cd53fee6ec8d2d2593e0258 (patch)
tree2c50e2e4341dd302ddb1091dbf23171c2d7a43fc /src/dcm/pkg/module/logicalcloud_test.go
parentedaf4416c5002254b60199a0b9710ebb23ccdf7b (diff)
Restore commented unit test TestDeleteLogicalCloud
Restore the previously commented-out unit test TestDeleteLogicalCloud. That test was disabled due to a failure introduced by interacting with AppContext for the first time in module/logicalcloud.go and it not being ready to do so. This commit restores it and modifies code so dependent mocks can plug in correctly. This was done in order to keep testing the code that was previously being tested, not so much to add additional coverage. Although it would be a significant undertaking, the different types and interfaces in pkg/module should be redesigned to achieve better decoupling and thus make unit testing more straightforward. Issue-ID: MULTICLOUD-1143 Change-Id: I1e6b7bb9111fc6883f0c9cee887329a9e0b27fbd Signed-off-by: Igor D.C <igor.duarte.cardoso@intel.com>
Diffstat (limited to 'src/dcm/pkg/module/logicalcloud_test.go')
-rw-r--r--src/dcm/pkg/module/logicalcloud_test.go33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/dcm/pkg/module/logicalcloud_test.go b/src/dcm/pkg/module/logicalcloud_test.go
index efce568f..cbdc1304 100644
--- a/src/dcm/pkg/module/logicalcloud_test.go
+++ b/src/dcm/pkg/module/logicalcloud_test.go
@@ -4,6 +4,7 @@ import (
"fmt"
"testing"
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/appcontext"
"github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/db"
"github.com/pkg/errors"
"github.com/stretchr/testify/mock"
@@ -55,6 +56,20 @@ func (m *mockValues) CheckLogicalCloud(project, logicalCloud string) error {
return args.Error(0)
}
+func (m *mockValues) GetLogicalCloudContext(name string, key db.Key, meta string, project, logicalCloud string) (appcontext.AppContext, string, error) {
+ fmt.Println("Mocked Get Logical Cloud Context")
+ args := m.Called(name, key, meta, project, logicalCloud)
+
+ return appcontext.AppContext{}, "", args.Error(2)
+}
+
+func (m *mockValues) GetAppContextStatus(ac appcontext.AppContext) (*appcontext.AppContextStatus, error) {
+ fmt.Println("Mocked GetAppContextStatus")
+ args := m.Called(ac)
+
+ return &appcontext.AppContextStatus{}, args.Error(1)
+}
+
func TestCreateLogicalCloud(t *testing.T) {
mData := MetaDataList{
@@ -110,7 +125,7 @@ func TestGetLogicalCloud(t *testing.T) {
}
}
-func TestDeleteLogicalCloud(t *testing.T) {
+func TestDeleteLogicalCloudWithSuccess(t *testing.T) {
key := LogicalCloudKey{
Project: "test_project",
@@ -128,14 +143,14 @@ func TestDeleteLogicalCloud(t *testing.T) {
myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, nil)
myMocks.On("DBUnmarshal", data2).Return(nil)
myMocks.On("DBFind", "test_dcm", key, "test_context").Return(data1, nil)
- // TODO also test for when the logical cloud doesn't exist
-
- // TODO: fix Etcd-related test crash
- // lcClient := LogicalCloudClient{"test_dcm", "test_meta", "test_context", myMocks}
- // err := lcClient.Delete("test_project", "test_asdf")
- // if err != nil {
- // t.Errorf("Some error occured!")
- // }
+ myMocks.On("GetLogicalCloudContext", "test_dcm", key, "test_meta", "test_project", "test_asdf").Return(appcontext.AppContext{}, "", nil)
+ myMocks.On("GetAppContextStatus", appcontext.AppContext{}).Return(&appcontext.AppContextStatus{}, nil)
+
+ lcClient := LogicalCloudClient{"test_dcm", "test_meta", "test_context", myMocks}
+ err := lcClient.Delete("test_project", "test_asdf")
+ if err.Error() != "The Logical Cloud can't be deleted yet at this point." {
+ t.Errorf("Some unexpected error occurred!")
+ }
}
func TestUpdateLogicalCloud(t *testing.T) {