-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(elasticache): adding tests for subnet groups and clusters
- Loading branch information
Showing
6 changed files
with
4,841 additions
and
6 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,109 @@ | ||
package resources | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/elasticache" | ||
"github.com/ekristen/aws-nuke/mocks/mock_elasticacheiface" | ||
"github.com/ekristen/aws-nuke/pkg/nuke" | ||
"github.com/golang/mock/gomock" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func Test_Mock_ElastiCache_CacheCluster_Remove(t *testing.T) { | ||
a := assert.New(t) | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
mockElastiCache := mock_elasticacheiface.NewMockElastiCacheAPI(ctrl) | ||
|
||
cacheCluster := ElasticacheCacheCluster{ | ||
svc: mockElastiCache, | ||
clusterID: aws.String("foobar"), | ||
} | ||
|
||
mockElastiCache.EXPECT().DeleteCacheCluster(&elasticache.DeleteCacheClusterInput{ | ||
CacheClusterId: aws.String("foobar"), | ||
}).Return(&elasticache.DeleteCacheClusterOutput{}, nil) | ||
|
||
err := cacheCluster.Remove(nil) | ||
a.Nil(err) | ||
} | ||
|
||
func Test_Mock_ElastiCache_CacheCluster_List_NoTags(t *testing.T) { | ||
a := assert.New(t) | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
mockElastiCache := mock_elasticacheiface.NewMockElastiCacheAPI(ctrl) | ||
|
||
cacheClusterLister := ElasticacheCacheClusterLister{ | ||
mockSvc: mockElastiCache, | ||
} | ||
|
||
mockElastiCache.EXPECT().DescribeCacheClusters(gomock.Any()).Return(&elasticache.DescribeCacheClustersOutput{ | ||
CacheClusters: []*elasticache.CacheCluster{ | ||
{ | ||
CacheClusterId: aws.String("foobar"), | ||
CacheClusterStatus: aws.String("available"), | ||
}, | ||
}, | ||
}, nil) | ||
|
||
mockElastiCache.EXPECT().ListTagsForResource(&elasticache.ListTagsForResourceInput{ | ||
ResourceName: aws.String("foobar"), | ||
}).Return(&elasticache.TagListMessage{}, nil) | ||
|
||
resources, err := cacheClusterLister.List(nil, &nuke.ListerOpts{}) | ||
a.Nil(err) | ||
a.Len(resources, 1) | ||
|
||
resource := resources[0].(*ElasticacheCacheCluster) | ||
a.Equal("foobar", resource.String()) | ||
} | ||
|
||
func Test_Mock_ElastiCache_CacheCluster_List_WithTags(t *testing.T) { | ||
a := assert.New(t) | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
mockElastiCache := mock_elasticacheiface.NewMockElastiCacheAPI(ctrl) | ||
|
||
cacheClusterLister := ElasticacheCacheClusterLister{ | ||
mockSvc: mockElastiCache, | ||
} | ||
|
||
mockElastiCache.EXPECT().DescribeCacheClusters(gomock.Any()).Return(&elasticache.DescribeCacheClustersOutput{ | ||
CacheClusters: []*elasticache.CacheCluster{ | ||
{ | ||
CacheClusterId: aws.String("foobar"), | ||
}, | ||
}, | ||
}, nil) | ||
|
||
mockElastiCache.EXPECT().ListTagsForResource(&elasticache.ListTagsForResourceInput{ | ||
ResourceName: aws.String("foobar"), | ||
}).Return(&elasticache.TagListMessage{ | ||
TagList: []*elasticache.Tag{ | ||
{ | ||
Key: aws.String("Name"), | ||
Value: aws.String("foobar"), | ||
}, | ||
{ | ||
Key: aws.String("aws-nuke"), | ||
Value: aws.String("test"), | ||
}, | ||
}, | ||
}, nil) | ||
|
||
resources, err := cacheClusterLister.List(nil, &nuke.ListerOpts{}) | ||
a.Nil(err) | ||
a.Len(resources, 1) | ||
|
||
resource := resources[0].(*ElasticacheCacheCluster) | ||
a.Len(resource.Tags, 2) | ||
a.Equal("foobar", resource.String()) | ||
a.Equal("foobar", resource.Properties().Get("tag:Name")) | ||
a.Equal("test", resource.Properties().Get("tag:aws-nuke")) | ||
|
||
} |
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,2 @@ | ||
//go:generate ../mocks/generate_mocks.sh elasticache elasticacheiface | ||
package resources |
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,113 @@ | ||
package resources | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/elasticache" | ||
|
||
"github.com/ekristen/aws-nuke/mocks/mock_elasticacheiface" | ||
"github.com/ekristen/aws-nuke/pkg/nuke" | ||
) | ||
|
||
func Test_Mock_ElastiCache_SubnetGroup_Remove(t *testing.T) { | ||
a := assert.New(t) | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
mockElastiCache := mock_elasticacheiface.NewMockElastiCacheAPI(ctrl) | ||
|
||
subnetGroup := ElasticacheSubnetGroup{ | ||
svc: mockElastiCache, | ||
name: aws.String("foobar"), | ||
} | ||
|
||
mockElastiCache.EXPECT().DeleteCacheSubnetGroup(gomock.Any()).Return(&elasticache.DeleteCacheSubnetGroupOutput{}, nil) | ||
|
||
err := subnetGroup.Remove(nil) | ||
a.Nil(err) | ||
a.Equal("foobar", *subnetGroup.name) | ||
} | ||
|
||
func Test_Mock_ElastiCache_SubnetGroup_List_NoTags(t *testing.T) { | ||
a := assert.New(t) | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
mockElastiCache := mock_elasticacheiface.NewMockElastiCacheAPI(ctrl) | ||
|
||
subnetGroupsLister := ElasticacheSubnetGroupLister{ | ||
mockSvc: mockElastiCache, | ||
} | ||
|
||
mockElastiCache.EXPECT().DescribeCacheSubnetGroups(gomock.Any()).Return(&elasticache.DescribeCacheSubnetGroupsOutput{ | ||
CacheSubnetGroups: []*elasticache.CacheSubnetGroup{ | ||
{ | ||
CacheSubnetGroupName: aws.String("foobar"), | ||
}, | ||
}, | ||
}, nil) | ||
|
||
mockElastiCache.EXPECT().ListTagsForResource(&elasticache.ListTagsForResourceInput{ | ||
ResourceName: aws.String("foobar"), | ||
}).Return(&elasticache.TagListMessage{}, nil) | ||
|
||
resources, err := subnetGroupsLister.List(nil, &nuke.ListerOpts{}) | ||
a.Nil(err) | ||
a.Len(resources, 1) | ||
|
||
resource := resources[0].(*ElasticacheSubnetGroup) | ||
a.Len(resource.Tags, 0) | ||
|
||
a.Equal("foobar", resource.String()) | ||
} | ||
|
||
func Test_Mock_ElastiCache_SubnetGroup_List_WithTags(t *testing.T) { | ||
a := assert.New(t) | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
mockElastiCache := mock_elasticacheiface.NewMockElastiCacheAPI(ctrl) | ||
|
||
subnetGroupsLister := ElasticacheSubnetGroupLister{ | ||
mockSvc: mockElastiCache, | ||
} | ||
|
||
mockElastiCache.EXPECT().DescribeCacheSubnetGroups(gomock.Any()).Return(&elasticache.DescribeCacheSubnetGroupsOutput{ | ||
CacheSubnetGroups: []*elasticache.CacheSubnetGroup{ | ||
{ | ||
CacheSubnetGroupName: aws.String("foobar"), | ||
}, | ||
}, | ||
}, nil) | ||
|
||
mockElastiCache.EXPECT().ListTagsForResource(&elasticache.ListTagsForResourceInput{ | ||
ResourceName: aws.String("foobar"), | ||
}).Return(&elasticache.TagListMessage{ | ||
TagList: []*elasticache.Tag{ | ||
{ | ||
Key: aws.String("Name"), | ||
Value: aws.String("foobar"), | ||
}, | ||
{ | ||
Key: aws.String("aws-nuke"), | ||
Value: aws.String("test"), | ||
}, | ||
}, | ||
}, nil) | ||
|
||
resources, err := subnetGroupsLister.List(nil, &nuke.ListerOpts{}) | ||
a.Nil(err) | ||
|
||
a.Len(resources, 1) | ||
|
||
resource := resources[0].(*ElasticacheSubnetGroup) | ||
a.Len(resource.Tags, 2) | ||
|
||
a.Equal("foobar", resource.String()) | ||
a.Equal("foobar", resource.Properties().Get("tag:Name")) | ||
a.Equal("test", resource.Properties().Get("tag:aws-nuke")) | ||
} |