aboutsummaryrefslogtreecommitdiffstats
path: root/src/dcm/pkg/module/logicalcloud.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.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.go')
-rw-r--r--src/dcm/pkg/module/logicalcloud.go18
1 files changed, 7 insertions, 11 deletions
diff --git a/src/dcm/pkg/module/logicalcloud.go b/src/dcm/pkg/module/logicalcloud.go
index 580e9022..3fe981b8 100644
--- a/src/dcm/pkg/module/logicalcloud.go
+++ b/src/dcm/pkg/module/logicalcloud.go
@@ -75,7 +75,6 @@ type LogicalCloudManager interface {
GetAll(project string) ([]LogicalCloud, error)
Delete(project, name string) error
Update(project, name string, c LogicalCloud) (LogicalCloud, error)
- GetLogicalCloudContext(project string, name string) (appcontext.AppContext, string, error)
}
// Interface facilitates unit testing by mocking functions
@@ -86,6 +85,8 @@ type Utility interface {
DBRemove(storeName string, key db.Key) error
CheckProject(project string) error
CheckLogicalCloud(project, logicalCloud string) error
+ GetLogicalCloudContext(storeName string, key db.Key, meta string, project string, name string) (appcontext.AppContext, string, error)
+ GetAppContextStatus(ac appcontext.AppContext) (*appcontext.AppContextStatus, error)
}
// LogicalCloudClient implements the LogicalCloudManager
@@ -208,7 +209,7 @@ func (v *LogicalCloudClient) Delete(project, logicalCloudName string) error {
return pkgerrors.New("Logical Cloud does not exist")
}
- context, _, err := v.GetLogicalCloudContext(project, logicalCloudName)
+ context, _, err := v.util.GetLogicalCloudContext(v.storeName, key, v.tagMeta, project, logicalCloudName)
// If there's no context for Logical Cloud, just go ahead and delete it now
if err != nil {
err = v.util.DBRemove(v.storeName, key)
@@ -220,7 +221,7 @@ func (v *LogicalCloudClient) Delete(project, logicalCloudName string) error {
// Make sure rsync status for this logical cloud is Terminated,
// otherwise we can't remove appcontext yet
- acStatus, _ := getAppContextStatus(context)
+ acStatus, _ := v.util.GetAppContextStatus(context)
switch acStatus.Status {
case appcontext.AppContextStatusEnum.Terminated:
// remove the appcontext
@@ -267,14 +268,9 @@ func (v *LogicalCloudClient) Update(project, logicalCloudName string, c LogicalC
}
// GetLogicalCloudContext returns the AppContext for corresponding provider and name
-func (v *LogicalCloudClient) GetLogicalCloudContext(project string, name string) (appcontext.AppContext, string, error) {
- //Construct key and tag to select the entry
- key := LogicalCloudKey{
- LogicalCloudName: name,
- Project: project,
- }
+func (d DBService) GetLogicalCloudContext(storeName string, key db.Key, meta string, project string, name string) (appcontext.AppContext, string, error) {
- value, err := v.util.DBFind(v.storeName, key, v.tagContext)
+ value, err := d.DBFind(storeName, key, meta)
if err != nil {
return appcontext.AppContext{}, "", pkgerrors.Wrap(err, "Get Logical Cloud Context")
}
@@ -353,7 +349,7 @@ func (d DBService) CheckLogicalCloud(project, logicalCloud string) error {
return nil
}
-func getAppContextStatus(ac appcontext.AppContext) (*appcontext.AppContextStatus, error) {
+func (d DBService) GetAppContextStatus(ac appcontext.AppContext) (*appcontext.AppContextStatus, error) {
h, err := ac.GetCompositeAppHandle()
if err != nil {