Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
add support for ecs resource (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
roneli authored Apr 6, 2021
1 parent fe2ba6a commit 68f8a6a
Show file tree
Hide file tree
Showing 11 changed files with 2,088 additions and 52 deletions.
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type Services struct {
CloudwatchLogs CloudwatchLogsClient
Directconnect DirectconnectClient
ECR EcrClient
ECS *ecs.Client
ECS EcsClient
EC2 Ec2Client
EFS EfsClient
Eks EksClient
Expand Down
25 changes: 24 additions & 1 deletion client/mocks/builders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
ec2Types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/aws/aws-sdk-go-v2/service/ecr"
ecrTypes "github.com/aws/aws-sdk-go-v2/service/ecr/types"
"github.com/aws/aws-sdk-go-v2/service/ecs"
ecsTypes "github.com/aws/aws-sdk-go-v2/service/ecs/types"
"github.com/aws/aws-sdk-go-v2/service/efs"
efsTypes "github.com/aws/aws-sdk-go-v2/service/efs/types"
"github.com/aws/aws-sdk-go-v2/service/eks"
Expand Down Expand Up @@ -56,7 +58,7 @@ func buildAutoscalingLaunchConfigurationsMock(t *testing.T, ctrl *gomock.Control
l := autoscalingTypes.LaunchConfiguration{}
err := faker.FakeData(&l)
if err != nil {
panic(err)
t.Fatal(err)
}
autoscalingLaunchConfigurations := &autoscaling.DescribeLaunchConfigurationsOutput{
LaunchConfigurations: []autoscalingTypes.LaunchConfiguration{l},
Expand All @@ -65,6 +67,27 @@ func buildAutoscalingLaunchConfigurationsMock(t *testing.T, ctrl *gomock.Control
return services
}

func buildEcsClusterMock(t *testing.T, ctrl *gomock.Controller) client.Services {
m := mocks.NewMockEcsClient(ctrl)
services := client.Services{
ECS: m,
}
c := ecsTypes.Cluster{}
err := faker.FakeData(&c)
if err != nil {
t.Fatal(err)
}
ecsOutput := &ecs.DescribeClustersOutput{
Clusters: []ecsTypes.Cluster{c},
}
m.EXPECT().DescribeClusters(gomock.Any(), gomock.Any(), gomock.Any()).Return(ecsOutput, nil)
ecsListOutput := &ecs.ListClustersOutput{
ClusterArns: []string{"randomClusteArn"},
}
m.EXPECT().ListClusters(gomock.Any(), gomock.Any(), gomock.Any()).Return(ecsListOutput, nil)
return services
}

func buildCloudtrailTrailsMock(t *testing.T, ctrl *gomock.Controller) client.Services {
m := mocks.NewMockCloudtrailClient(ctrl)
services := client.Services{
Expand Down
5 changes: 5 additions & 0 deletions client/mocks/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ func TestResources(t *testing.T) {
mainTable: resources.RedshiftSubnetGroups(),
mockBuilder: buildRedshiftSubnetGroupsMock,
},
{
resource: "ecs.clusters",
mainTable: resources.EcsClusters(),
mockBuilder: buildEcsClusterMock,
},
}
for _, tc := range testResourcesTable {
t.Run(tc.resource, func(t *testing.T) {
Expand Down
66 changes: 65 additions & 1 deletion client/mocks/services.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion client/services.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// We define interfaces so we can easily mock AWS calls
package client

//go:generate mockgen -destination=../mocks/services.go -package=mocks . AutoscalingClient,CloudtrailClient,CloudwatchClient,CloudwatchLogsClient,DirectconnectClient,Ec2Client,EcrClient,EfsClient,ElasticbeanstalkClient,ElbV2Client,EmrClient,FsxClient,IamClient,KmsClient,OrganizationsClient,RdsClient,S3Client,SnsClient,EksClient,RedshiftClient
//go:generate mockgen -destination=./mocks/services.go -package=mocks . AutoscalingClient,CloudtrailClient,CloudwatchClient,CloudwatchLogsClient,DirectconnectClient,Ec2Client,EcrClient,EfsClient,ElasticbeanstalkClient,ElbV2Client,EmrClient,FsxClient,IamClient,KmsClient,OrganizationsClient,RdsClient,S3Client,SnsClient,EksClient,RedshiftClient,EcsClient

import (
"context"

"github.com/aws/aws-sdk-go-v2/service/ecs"

"github.com/aws/aws-sdk-go-v2/service/autoscaling"
"github.com/aws/aws-sdk-go-v2/service/cloudtrail"
"github.com/aws/aws-sdk-go-v2/service/cloudwatch"
Expand Down Expand Up @@ -145,6 +147,11 @@ type SnsClient interface {
GetTopicAttributes(ctx context.Context, params *sns.GetTopicAttributesInput, optFns ...func(*sns.Options)) (*sns.GetTopicAttributesOutput, error)
}

type EcsClient interface {
DescribeClusters(ctx context.Context, params *ecs.DescribeClustersInput, optFns ...func(*ecs.Options)) (*ecs.DescribeClustersOutput, error)
ListClusters(ctx context.Context, params *ecs.ListClustersInput, optFns ...func(*ecs.Options)) (*ecs.ListClustersOutput, error)
}

type EksClient interface {
ListClusters(ctx context.Context, params *eks.ListClustersInput, optFns ...func(*eks.Options)) (*eks.ListClustersOutput, error)
DescribeCluster(ctx context.Context, params *eks.DescribeClusterInput, optFns ...func(*eks.Options)) (*eks.DescribeClusterOutput, error)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/directconnect v1.1.2
github.com/aws/aws-sdk-go-v2/service/ec2 v1.2.0
github.com/aws/aws-sdk-go-v2/service/ecr v1.2.0
github.com/aws/aws-sdk-go-v2/service/ecs v1.1.2
github.com/aws/aws-sdk-go-v2/service/ecs v1.2.0
github.com/aws/aws-sdk-go-v2/service/efs v1.2.0
github.com/aws/aws-sdk-go-v2/service/eks v1.2.1
github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk v1.2.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ github.com/aws/aws-sdk-go-v2/service/ecr v1.2.0 h1:6ExOoVgntAVuVARounLgbXnMLWjy0
github.com/aws/aws-sdk-go-v2/service/ecr v1.2.0/go.mod h1:fxAA3GE+slgrsFyA3bsN0lknZ+egpPdvu7GosNGoVT4=
github.com/aws/aws-sdk-go-v2/service/ecs v1.1.2 h1:g3OpNiW1iW9euM9JL2OM6ufGe2eXU0y6nTuK4sgQX7w=
github.com/aws/aws-sdk-go-v2/service/ecs v1.1.2/go.mod h1:v0SesgZfZH39s3f/XaZH5RmT8qQ1ZSuWnYsh9eML0II=
github.com/aws/aws-sdk-go-v2/service/ecs v1.2.0 h1:LlnxkpvIugxKNMjANn4KsD4/Vxs2yc7KHqtmGCwY+5w=
github.com/aws/aws-sdk-go-v2/service/ecs v1.2.0/go.mod h1:t2Lhvr7z1eoNmVILjyAdhL8iElYeLeGSEK559gzbAVk=
github.com/aws/aws-sdk-go-v2/service/efs v1.2.0 h1:PCLM4aShavpVcyXqUoUsQpMJ+Z/PLOFjQuV3NKxitmg=
github.com/aws/aws-sdk-go-v2/service/efs v1.2.0/go.mod h1:6ZQj15y/BJWGzjbc7JIjD9K4QEINDR5Es/2OW9frZ7I=
github.com/aws/aws-sdk-go-v2/service/eks v1.2.1 h1:eNSGiZZKcrjT1/UlxOSL/v1gjR5bePJk4xMdGBZXd1o=
Expand Down
Loading

0 comments on commit 68f8a6a

Please sign in to comment.