Skip to content

Commit

Permalink
Fix mocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylor-sutton committed Jul 19, 2021
1 parent d57fd17 commit 7880607
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
vendor/
bin/
release/
gen-go/
mocks/mock_*.go
cmd/sfncli/sfncli
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ clean:

mocks:
mkdir -p bin
go build -o ./bin/mockgen ./vendor/github.com/golang/mock/mockgen
rm -rf gen-go/mocksfn && mkdir -p gen-go/mocksfn
./bin/mockgen -source vendor/github.com/aws/aws-sdk-go/service/sfn/sfniface/interface.go -destination gen-go/mocksfn/mocksfn.go -package mocksfn
rm -rf gen-go/mockcloudwatch && mkdir -p gen-go/mockcloudwatch
./bin/mockgen -source vendor/github.com/aws/aws-sdk-go/service/cloudwatch/cloudwatchiface/interface.go -destination gen-go/mockcloudwatch/mockcloudwatch.go -package mockcloudwatch
go build -o ./bin/mockgen github.com/golang/mock/mockgen
rm -rf mocks/mock_*.go
./bin/mockgen -source ./vendor/github.com/aws/aws-sdk-go/service/sfn/sfniface/interface.go -destination mocks/mock_sfn.go -package mocks
./bin/mockgen -source ./vendor/github.com/aws/aws-sdk-go/service/cloudwatch/cloudwatchiface/interface.go -destination mocks/mock_cloudwatch.go -package mocks

install_deps:
go mod vendor
14 changes: 7 additions & 7 deletions cmd/sfncli/cloudwatchreporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"
"time"

"github.com/Clever/sfncli/gen-go/mockcloudwatch"
"github.com/Clever/sfncli/mocks"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/golang/mock/gomock"
Expand All @@ -21,7 +21,7 @@ func TestCloudWatchReporterReportsActiveZero(t *testing.T) {
defer testCtxCancel()
controller := gomock.NewController(t)
defer controller.Finish()
mockCW := mockcloudwatch.NewMockCloudWatchAPI(controller)
mockCW := mocks.NewMockCloudWatchAPI(controller)
cwr := NewCloudWatchReporter(mockCW, mockActivityArn)
go cwr.ReportActivePercent(testCtx, 100*time.Millisecond)
mockCW.EXPECT().PutMetricData(&cloudwatch.PutMetricDataInput{
Expand All @@ -44,7 +44,7 @@ func TestCloudWatchReporterReportsActiveFiftyPercent(t *testing.T) {
defer testCtxCancel()
controller := gomock.NewController(t)
defer controller.Finish()
mockCW := mockcloudwatch.NewMockCloudWatchAPI(controller)
mockCW := mocks.NewMockCloudWatchAPI(controller)
mockCW.EXPECT().PutMetricData(fuzzy(&cloudwatch.PutMetricDataInput{
MetricData: []*cloudwatch.MetricDatum{{
Dimensions: []*cloudwatch.Dimension{{
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestCloudWatchReporterReportsActiveHundredPercent(t *testing.T) {
defer testCtxCancel()
controller := gomock.NewController(t)
defer controller.Finish()
mockCW := mockcloudwatch.NewMockCloudWatchAPI(controller)
mockCW := mocks.NewMockCloudWatchAPI(controller)
mockCW.EXPECT().PutMetricData(fuzzy(&cloudwatch.PutMetricDataInput{
MetricData: []*cloudwatch.MetricDatum{{
Dimensions: []*cloudwatch.Dimension{{
Expand All @@ -99,7 +99,7 @@ func TestCloudWatchReporterReportsActiveOneHundredPercentWhenPausedForever(t *te
defer testCtxCancel()
controller := gomock.NewController(t)
defer controller.Finish()
mockCW := mockcloudwatch.NewMockCloudWatchAPI(controller)
mockCW := mocks.NewMockCloudWatchAPI(controller)
mockCW.EXPECT().PutMetricData(fuzzy(&cloudwatch.PutMetricDataInput{
MetricData: []*cloudwatch.MetricDatum{{
Dimensions: []*cloudwatch.Dimension{{
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestCloudWatchReporterReportsActiveOnehundredPercentWhenPaused(t *testing.T
defer testCtxCancel()
controller := gomock.NewController(t)
defer controller.Finish()
mockCW := mockcloudwatch.NewMockCloudWatchAPI(controller)
mockCW := mocks.NewMockCloudWatchAPI(controller)
mockCW.EXPECT().PutMetricData(fuzzy(&cloudwatch.PutMetricDataInput{
MetricData: []*cloudwatch.MetricDatum{{
Dimensions: []*cloudwatch.Dimension{{
Expand Down Expand Up @@ -173,7 +173,7 @@ func TestCloudWatchReporterReportsActiveFiftyPercentWhenPaused(t *testing.T) {
defer testCtxCancel()
controller := gomock.NewController(t)
defer controller.Finish()
mockCW := mockcloudwatch.NewMockCloudWatchAPI(controller)
mockCW := mocks.NewMockCloudWatchAPI(controller)
mockCW.EXPECT().PutMetricData(fuzzy(&cloudwatch.PutMetricDataInput{
MetricData: []*cloudwatch.MetricDatum{{
Dimensions: []*cloudwatch.Dimension{{
Expand Down
32 changes: 16 additions & 16 deletions cmd/sfncli/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"testing"
"time"

"github.com/Clever/sfncli/gen-go/mocksfn"
"github.com/Clever/sfncli/mocks"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/sfn"
"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestTaskFailureTaskInputNotJSON(t *testing.T) {

controller := gomock.NewController(t)
defer controller.Finish()
mockSFN := mocksfn.NewMockSFNAPI(controller)
mockSFN := mocks.NewMockSFNAPI(controller)
mockSFN.EXPECT().SendTaskFailure(&sfn.SendTaskFailureInput{
Cause: aws.String(expectedError.ErrorCause()),
Error: aws.String(expectedError.ErrorName()),
Expand All @@ -88,7 +88,7 @@ func TestTaskOutputEmptyStringAsJSON(t *testing.T) {

controller := gomock.NewController(t)
defer controller.Finish()
mockSFN := mocksfn.NewMockSFNAPI(controller)
mockSFN := mocks.NewMockSFNAPI(controller)
mockSFN.EXPECT().SendTaskSuccessWithContext(gomock.Any(), &sfn.SendTaskSuccessInput{
TaskToken: aws.String(mockTaskToken),
Output: aws.String(`{"_EXECUTION_NAME":"fake-WFM-uuid"}`),
Expand All @@ -109,7 +109,7 @@ func TestTaskFailureCommandNotFound(t *testing.T) {

controller := gomock.NewController(t)
defer controller.Finish()
mockSFN := mocksfn.NewMockSFNAPI(controller)
mockSFN := mocks.NewMockSFNAPI(controller)
mockSFN.EXPECT().SendTaskFailure(&sfn.SendTaskFailureInput{
Cause: aws.String(expectedError.ErrorCause()),
Error: aws.String(expectedError.ErrorName()),
Expand All @@ -130,7 +130,7 @@ func TestTaskFailureCommandKilled(t *testing.T) {

controller := gomock.NewController(t)
defer controller.Finish()
mockSFN := mocksfn.NewMockSFNAPI(controller)
mockSFN := mocks.NewMockSFNAPI(controller)
mockSFN.EXPECT().SendTaskFailure(&sfn.SendTaskFailureInput{
Cause: aws.String(expectedError.ErrorCause()),
Error: aws.String(expectedError.ErrorName()),
Expand All @@ -155,7 +155,7 @@ func TestTaskFailureCommandExitedNonzero(t *testing.T) {

controller := gomock.NewController(t)
defer controller.Finish()
mockSFN := mocksfn.NewMockSFNAPI(controller)
mockSFN := mocks.NewMockSFNAPI(controller)
mockSFN.EXPECT().SendTaskFailure(&sfn.SendTaskFailureInput{
Cause: aws.String(expectedError.ErrorCause()),
Error: aws.String(expectedError.ErrorName()),
Expand All @@ -176,7 +176,7 @@ func TestTaskFailureCustomErrorName(t *testing.T) {

controller := gomock.NewController(t)
defer controller.Finish()
mockSFN := mocksfn.NewMockSFNAPI(controller)
mockSFN := mocks.NewMockSFNAPI(controller)
mockSFN.EXPECT().SendTaskFailure(&sfn.SendTaskFailureInput{
Cause: aws.String(expectedError.ErrorCause()),
Error: aws.String(expectedError.ErrorName()),
Expand All @@ -197,7 +197,7 @@ func TestTaskFailureTaskOutputNotJSON(t *testing.T) {

controller := gomock.NewController(t)
defer controller.Finish()
mockSFN := mocksfn.NewMockSFNAPI(controller)
mockSFN := mocks.NewMockSFNAPI(controller)
mockSFN.EXPECT().SendTaskFailure(&sfn.SendTaskFailureInput{
Cause: aws.String(expectedError.ErrorCause()),
Error: aws.String(expectedError.ErrorName()),
Expand All @@ -218,7 +218,7 @@ func TestTaskFailureCommandTerminated(t *testing.T) {

controller := gomock.NewController(t)
defer controller.Finish()
mockSFN := mocksfn.NewMockSFNAPI(controller)
mockSFN := mocks.NewMockSFNAPI(controller)
mockSFN.EXPECT().SendTaskFailure(&sfn.SendTaskFailureInput{
Cause: aws.String(expectedError.ErrorCause()),
Error: aws.String(expectedError.ErrorName()),
Expand All @@ -243,7 +243,7 @@ func TestTaskFailureCommandTerminated(t *testing.T) {

controller := gomock.NewController(t)
defer controller.Finish()
mockSFN := mocksfn.NewMockSFNAPI(controller)
mockSFN := mocks.NewMockSFNAPI(controller)
mockSFN.EXPECT().SendTaskFailure(&sfn.SendTaskFailureInput{
Cause: aws.String(expectedError.ErrorCause()),
Error: aws.String(expectedError.ErrorName()),
Expand All @@ -268,7 +268,7 @@ func TestTaskFailureCommandTerminated(t *testing.T) {

controller := gomock.NewController(t)
defer controller.Finish()
mockSFN := mocksfn.NewMockSFNAPI(controller)
mockSFN := mocks.NewMockSFNAPI(controller)
mockSFN.EXPECT().SendTaskFailure(&sfn.SendTaskFailureInput{
Cause: aws.String(expectedError.ErrorCause()),
Error: aws.String(expectedError.ErrorName()),
Expand All @@ -294,7 +294,7 @@ func TestTaskSuccessSignalForwarded(t *testing.T) {
cmdArgs := []string{}

controller := gomock.NewController(t)
mockSFN := mocksfn.NewMockSFNAPI(controller)
mockSFN := mocks.NewMockSFNAPI(controller)
mockSFN.EXPECT().SendTaskSuccessWithContext(gomock.Any(), &sfn.SendTaskSuccessInput{
Output: aws.String(`{"_EXECUTION_NAME":"fake-WFM-uuid","signal":"1"}`),
TaskToken: aws.String(mockTaskToken),
Expand All @@ -316,7 +316,7 @@ func TestTaskSuccessOutputIsLastLineOfStdout(t *testing.T) {
cmdArgs := []string{}

controller := gomock.NewController(t)
mockSFN := mocksfn.NewMockSFNAPI(controller)
mockSFN := mocks.NewMockSFNAPI(controller)
mockSFN.EXPECT().SendTaskSuccessWithContext(gomock.Any(), &sfn.SendTaskSuccessInput{
Output: aws.String(`{"_EXECUTION_NAME":"fake-WFM-uuid","task":"output"}`),
TaskToken: aws.String(mockTaskToken),
Expand All @@ -336,7 +336,7 @@ func TestTaskWorkDirectorySetup(t *testing.T) {

controller := gomock.NewController(t)
defer controller.Finish()
mockSFN := mocksfn.NewMockSFNAPI(controller)
mockSFN := mocks.NewMockSFNAPI(controller)
mockSFN.EXPECT().SendTaskSuccessWithContext(gomock.Any(), &workdirMatcher{
taskToken: mockTaskToken,
expectedPrefix: "/tmp",
Expand All @@ -356,7 +356,7 @@ func TestTaskWorkDirectoryUnsetByDefault(t *testing.T) {

controller := gomock.NewController(t)
defer controller.Finish()
mockSFN := mocksfn.NewMockSFNAPI(controller)
mockSFN := mocks.NewMockSFNAPI(controller)
mockSFN.EXPECT().SendTaskSuccessWithContext(gomock.Any(), &sfn.SendTaskSuccessInput{
TaskToken: aws.String(mockTaskToken),
Output: aws.String(`{"_EXECUTION_NAME":"fake-WFM-uuid","work_dir":""}`), // returns the result of WORK_DIR
Expand All @@ -376,7 +376,7 @@ func TestTaskWorkDirectoryCleaned(t *testing.T) {

controller := gomock.NewController(t)
defer controller.Finish()
mockSFN := mocksfn.NewMockSFNAPI(controller)
mockSFN := mocks.NewMockSFNAPI(controller)
dirMatcher := workdirMatcher{
taskToken: mockTaskToken,
expectedPrefix: "/tmp/test",
Expand Down
2 changes: 2 additions & 0 deletions mocks/mocks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package mocks holds the generated mocks for testing.
package mocks
2 changes: 1 addition & 1 deletion tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
package main

import (
_ "github.com/golang/mock/mockgen"
_ "github.com/golang/mock/gomock"
)

0 comments on commit 7880607

Please sign in to comment.