-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from ekristen/additional-tags
feat: adding additional tags to various resources
- Loading branch information
Showing
20 changed files
with
11,478 additions
and
29 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,84 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/gotidy/ptr" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/ecs" | ||
|
||
"github.com/ekristen/aws-nuke/mocks/mock_ecsiface" | ||
|
||
"github.com/ekristen/aws-nuke/pkg/nuke" | ||
) | ||
|
||
func Test_Mock_ECSCluster_List(t *testing.T) { | ||
a := assert.New(t) | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
mockECS := mock_ecsiface.NewMockECSAPI(ctrl) | ||
|
||
ecsClusterLister := ECSClusterLister{ | ||
mockSvc: mockECS, | ||
} | ||
|
||
mockECS.EXPECT().ListClusters(gomock.Any()).Return(&ecs.ListClustersOutput{ | ||
ClusterArns: []*string{ | ||
aws.String("foobar"), | ||
}, | ||
}, nil) | ||
|
||
mockECS.EXPECT().DescribeClusters(gomock.Any()).Return(&ecs.DescribeClustersOutput{ | ||
Clusters: []*ecs.Cluster{ | ||
{ | ||
ClusterArn: aws.String("foobar"), | ||
Tags: []*ecs.Tag{ | ||
{ | ||
Key: aws.String("Name"), | ||
Value: aws.String("foobar"), | ||
}, | ||
{ | ||
Key: aws.String("aws-nuke"), | ||
Value: aws.String("test"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, nil) | ||
|
||
resources, err := ecsClusterLister.List(context.TODO(), &nuke.ListerOpts{}) | ||
a.Nil(err) | ||
a.Len(resources, 1) | ||
|
||
ecsCluster := resources[0].(*ECSCluster) | ||
a.Equal("foobar", ecsCluster.String()) | ||
a.Equal("foobar", ecsCluster.Properties().Get("tag:Name")) | ||
a.Equal("test", ecsCluster.Properties().Get("tag:aws-nuke")) | ||
} | ||
|
||
func Test_Mock_ECSCluster_Remove(t *testing.T) { | ||
a := assert.New(t) | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
mockECS := mock_ecsiface.NewMockECSAPI(ctrl) | ||
|
||
ecsCluster := ECSCluster{ | ||
svc: mockECS, | ||
ARN: ptr.String("foobar"), | ||
} | ||
|
||
a.Equal("foobar", ecsCluster.String()) | ||
|
||
mockECS.EXPECT().DeleteCluster(gomock.Eq(&ecs.DeleteClusterInput{ | ||
Cluster: aws.String("foobar"), | ||
})).Return(&ecs.DeleteClusterOutput{}, nil) | ||
|
||
err := ecsCluster.Remove(context.TODO()) | ||
a.Nil(err) | ||
} |
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 ecs ecsiface | ||
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,112 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
"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_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(context.TODO()) | ||
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(context.TODO(), &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(context.TODO(), &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 |
Oops, something went wrong.