-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
100 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package aws | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/service/resourcegroupstaggingapi" | ||
"github.com/integr8ly/cluster-service/pkg/clusterservice" | ||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
|
||
//"reflect" | ||
"testing" | ||
) | ||
|
||
func TestElasticacheSnapshotEngine_DeleteResourcesForCluster(t *testing.T) { | ||
fakeClusterId := fakeClusterID | ||
fakeLogger, err := fakeLogger(func(l *logrus.Entry) error { | ||
return nil | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
type fields struct { | ||
elasticacheClient func() *elasticacheClientMock | ||
taggingClient func() *taggingClientMock | ||
logger *logrus.Entry | ||
} | ||
type args struct { | ||
clusterId string | ||
tags map[string]string | ||
dryRun bool | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
want []*clusterservice.ReportItem | ||
wantFn func(mock *elasticacheClientMock) error | ||
wantErr string | ||
}{ | ||
{ | ||
name: "error when describing clusters fail", | ||
fields: fields{ | ||
elasticacheClient: func() *elasticacheClientMock { | ||
fakeClient, err := fakeElasticacheClient(func(c *elasticacheClientMock) error { | ||
return nil | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
return fakeClient | ||
}, | ||
taggingClient: func() *taggingClientMock { | ||
fakeTaggingClient, err := fakeResourcetaggingClient(func(c *taggingClientMock) error { | ||
c.GetResourcesFunc = func(in1 *resourcegroupstaggingapi.GetResourcesInput) (output *resourcegroupstaggingapi.GetResourcesOutput, e error) { | ||
return nil, errors.New("") | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
return fakeTaggingClient | ||
}, | ||
logger: fakeLogger, | ||
}, | ||
args: args{ | ||
clusterId: fakeClusterId, | ||
dryRun: true, | ||
}, | ||
wantErr: "failed to describe cache clusters: ", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
fakeClient := tt.fields.elasticacheClient() | ||
r := &ElasticacheEngine{ | ||
elasticacheClient: fakeClient, | ||
taggingClient: tt.fields.taggingClient(), | ||
logger: tt.fields.logger, | ||
} | ||
got, err := r.DeleteResourcesForCluster(tt.args.clusterId, nil, tt.args.dryRun) | ||
if tt.wantErr != "" && err.Error() != tt.wantErr { | ||
t.Errorf("DeleteResourcesForCluster() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
|
||
if !equalReportItems(got, tt.want) { | ||
t.Errorf("DeleteResourcesForCluster() got = %v, want %v", got, tt.want) | ||
} | ||
if tt.wantFn != nil { | ||
if err := tt.wantFn(fakeClient); err != nil { | ||
t.Errorf("DeleteResourcesForCluster() err = %v", err) | ||
} | ||
} | ||
}) | ||
} | ||
} |