-
-
Notifications
You must be signed in to change notification settings - Fork 2
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 #42 from nao1215/feat/cfn-list
Add cloudformation(cfn) ls subcommand
- Loading branch information
Showing
16 changed files
with
784 additions
and
74 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,15 @@ | ||
package mock | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/nao1215/rainbow/app/domain/service" | ||
) | ||
|
||
// CFnStackLister is a mock of the CFnStackLister interface. | ||
type CFnStackLister func(ctx context.Context, input *service.CFnStackListerInput) (*service.CFnStackListerOutput, error) | ||
|
||
// CFnStackLister calls the CFnStackListerFunc. | ||
func (m CFnStackLister) CFnStackLister(ctx context.Context, input *service.CFnStackListerInput) (*service.CFnStackListerOutput, error) { | ||
return m(ctx, input) | ||
} |
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,44 @@ | ||
package interactor | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/google/wire" | ||
"github.com/nao1215/rainbow/app/domain/service" | ||
"github.com/nao1215/rainbow/app/usecase" | ||
) | ||
|
||
// CFnStackListerSet is a set of CFnStackLister. | ||
// | ||
//nolint:gochecknoglobals | ||
var CFnStackListerSet = wire.NewSet( | ||
NewCFnStackLister, | ||
wire.Bind(new(usecase.CFnStackLister), new(*CFnStackLister)), | ||
) | ||
|
||
var _ usecase.CFnStackLister = (*CFnStackLister)(nil) | ||
|
||
// CFnStackLister is an implementation for CFnStackLister. | ||
type CFnStackLister struct { | ||
service.CFnStackLister | ||
} | ||
|
||
// NewCFnStackLister returns a new CFnStackLister struct. | ||
func NewCFnStackLister(lister service.CFnStackLister) *CFnStackLister { | ||
return &CFnStackLister{ | ||
CFnStackLister: lister, | ||
} | ||
} | ||
|
||
// ListCFnStack returns a list of CloudFormation stacks. | ||
func (l *CFnStackLister) ListCFnStack(ctx context.Context, input *usecase.CFnStackListerInput) (*usecase.CFnStackListerOutput, error) { | ||
output, err := l.CFnStackLister.CFnStackLister(ctx, &service.CFnStackListerInput{ | ||
Region: input.Region, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &usecase.CFnStackListerOutput{ | ||
Stacks: output.Stacks, | ||
}, nil | ||
} |
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 interactor | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/google/go-cmp/cmp" | ||
"github.com/nao1215/rainbow/app/domain/model" | ||
"github.com/nao1215/rainbow/app/domain/service" | ||
"github.com/nao1215/rainbow/app/external/mock" | ||
"github.com/nao1215/rainbow/app/usecase" | ||
) | ||
|
||
func TestCFnStackLister_ListCFnStack(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("success to get cloudformation stack list", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
stackLister := mock.CFnStackLister(func(ctx context.Context, input *service.CFnStackListerInput) (*service.CFnStackListerOutput, error) { | ||
want := &service.CFnStackListerInput{ | ||
Region: model.RegionAPEast1, | ||
} | ||
if diff := cmp.Diff(want, input); diff != "" { | ||
t.Errorf("differs: (-want +got)\n%s", diff) | ||
} | ||
|
||
return &service.CFnStackListerOutput{ | ||
Stacks: []*model.Stack{ | ||
{ | ||
StackName: aws.String("stackName1"), | ||
StackID: aws.String(model.StackStatusCreateComplete.String()), | ||
}, | ||
{ | ||
StackName: aws.String("stackName2"), | ||
StackID: aws.String(model.StackStatusCreateComplete.String()), | ||
}, | ||
}, | ||
}, nil | ||
}) | ||
|
||
lister := NewCFnStackLister(stackLister) | ||
output, err := lister.ListCFnStack(context.Background(), &usecase.CFnStackListerInput{ | ||
Region: model.RegionAPEast1, | ||
}) | ||
if err != nil { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
|
||
want := &usecase.CFnStackListerOutput{ | ||
Stacks: []*model.Stack{ | ||
{ | ||
StackName: aws.String("stackName1"), | ||
StackID: aws.String(model.StackStatusCreateComplete.String()), | ||
}, | ||
{ | ||
StackName: aws.String("stackName2"), | ||
StackID: aws.String(model.StackStatusCreateComplete.String()), | ||
}, | ||
}, | ||
} | ||
if diff := cmp.Diff(want, output); diff != "" { | ||
t.Errorf("differs: (-want +got)\n%s", diff) | ||
} | ||
}) | ||
|
||
t.Run("fail to get cloudformation stack list", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
stackLister := mock.CFnStackLister(func(ctx context.Context, input *service.CFnStackListerInput) (*service.CFnStackListerOutput, error) { | ||
return nil, errors.New("some error") | ||
}) | ||
|
||
lister := NewCFnStackLister(stackLister) | ||
_, err := lister.ListCFnStack(context.Background(), &usecase.CFnStackListerInput{ | ||
Region: model.RegionAPEast1, | ||
}) | ||
if err == nil { | ||
t.Error("expected error, but nil") | ||
} | ||
}) | ||
} |
Oops, something went wrong.