diff --git a/.gitignore b/.gitignore index 2ea4ca7e5..7314bc3a0 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ terraform-provider-layer0 *terraform.tfstate* .vscode/ crash.log +_vendor* diff --git a/Makefile b/Makefile index 59cfda1c8..fd1ace5c5 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,10 @@ smoketest: $(MAKE) -C tests/smoke test systemtest: - $(MAKE) -C tests/system test + $(MAKE) -C tests/system test + +benchmark: + $(MAKE) -C tests/stress benchmark install-smoketest: $(MAKE) -C cli install-smoketest @@ -44,4 +47,4 @@ apply-smoketest: destroy-smoketest: $(MAKE) -C setup destroy-smoketest -.PHONY: release unittest smoketest install-smoketest apply-smoketest destroy-smoketest systemtest +.PHONY: release unittest smoketest install-smoketest apply-smoketest destroy-smoketest systemtest benchmark diff --git a/api/backend/ecs/environment_manager.go b/api/backend/ecs/environment_manager.go index f07e4889c..1a1faa2fe 100644 --- a/api/backend/ecs/environment_manager.go +++ b/api/backend/ecs/environment_manager.go @@ -44,25 +44,18 @@ func NewECSEnvironmentManager( } } -func (e *ECSEnvironmentManager) ListEnvironments() ([]*models.Environment, error) { - clusters, err := e.ECS.Helper_DescribeClusters() +func (e *ECSEnvironmentManager) ListEnvironments() ([]id.ECSEnvironmentID, error) { + clusterNames, err := e.ECS.ListClusterNames(id.PREFIX) if err != nil { return nil, err } - environments := []*models.Environment{} - for _, cluster := range clusters { - if strings.HasPrefix(*cluster.ClusterName, id.PREFIX) { - ecsEnvironmentID := id.ECSEnvironmentID(*cluster.ClusterName) - environment := &models.Environment{ - EnvironmentID: ecsEnvironmentID.L0EnvironmentID(), - } - - environments = append(environments, environment) - } + ecsEnvironmentIDs := make([]id.ECSEnvironmentID, len(clusterNames)) + for i, clusterName := range clusterNames { + ecsEnvironmentIDs[i] = id.ECSEnvironmentID(clusterName) } - return environments, nil + return ecsEnvironmentIDs, nil } func (e *ECSEnvironmentManager) GetEnvironment(environmentID string) (*models.Environment, error) { diff --git a/api/backend/ecs/environment_manager_test.go b/api/backend/ecs/environment_manager_test.go index 3f5f72beb..e690141aa 100644 --- a/api/backend/ecs/environment_manager_test.go +++ b/api/backend/ecs/environment_manager_test.go @@ -20,6 +20,7 @@ import ( "github.com/quintilesims/layer0/common/config" "github.com/quintilesims/layer0/common/models" "github.com/quintilesims/layer0/common/testutils" + "github.com/stretchr/testify/assert" ) type MockECSEnvironmentManager struct { @@ -146,55 +147,31 @@ func TestGetEnvironment(t *testing.T) { } func TestListEnvironments(t *testing.T) { - testCases := []testutils.TestCase{ - { - Name: "Should return layer0-formatted environment ids and use proper params in aws calls", - Setup: func(reporter *testutils.Reporter, ctrl *gomock.Controller) interface{} { - mockEnvironment := NewMockECSEnvironmentManager(ctrl) - - ecsEnvironmentID := id.L0EnvironmentID("envid").ECSEnvironmentID() - clusterName := ecsEnvironmentID.String() - - mockEnvironment.ECS.EXPECT(). - Helper_DescribeClusters(). - Return([]*ecs.Cluster{ecs.NewCluster(clusterName)}, nil) + ctrl := gomock.NewController(t) + defer ctrl.Finish() - return mockEnvironment.Environment() - }, - Run: func(reporter *testutils.Reporter, target interface{}) { - manager := target.(*ECSEnvironmentManager) + mockEnvironment := NewMockECSEnvironmentManager(ctrl) - environments, err := manager.ListEnvironments() - if err != nil { - reporter.Fatal(err) - } - - reporter.AssertEqual(len(environments), 1) - reporter.AssertEqual(environments[0].EnvironmentID, "envid") - }, - }, - { - Name: "Should propagate ecs.Helper_DescribeClusters error", - Setup: func(reporter *testutils.Reporter, ctrl *gomock.Controller) interface{} { - mockEnvironment := NewMockECSEnvironmentManager(ctrl) + clusterNames := []string{ + "env_id1", + "env_id2", + } - mockEnvironment.ECS.EXPECT(). - Helper_DescribeClusters(). - Return(nil, fmt.Errorf("some_error")) + mockEnvironment.ECS.EXPECT(). + ListClusterNames(id.PREFIX). + Return(clusterNames, nil) - return mockEnvironment.Environment() - }, - Run: func(reporter *testutils.Reporter, target interface{}) { - manager := target.(*ECSEnvironmentManager) + result, err := mockEnvironment.Environment().ListEnvironments() + if err != nil { + t.Fatal(err) + } - if _, err := manager.ListEnvironments(); err == nil { - reporter.Errorf("Error was nil!") - } - }, - }, + expected := []id.ECSEnvironmentID{ + id.ECSEnvironmentID("env_id1"), + id.ECSEnvironmentID("env_id2"), } - testutils.RunTests(t, testCases) + assert.Equal(t, result, expected) } func TestDeleteEnvironment(t *testing.T) { diff --git a/api/backend/ecs/resource_manager.go b/api/backend/ecs/resource_manager.go index 0b2a0cf47..c7c1f8e28 100644 --- a/api/backend/ecs/resource_manager.go +++ b/api/backend/ecs/resource_manager.go @@ -24,7 +24,7 @@ func NewECSResourceManager(e ecs.Provider, a autoscaling.Provider) *ECSResourceM return &ECSResourceManager{ ECS: e, Autoscaling: a, - logger: logutils.NewStandardLogger("ECS Resource Manager"), + logger: logutils.NewStandardLogger("ECS Resource Manager").Logger, } } @@ -62,8 +62,7 @@ func (r *ECSResourceManager) getResourceProvider(ecsEnvironmentID id.ECSEnvironm } if !pbool(instance.AgentConnected) { - r.logger.Errorf("Instance %s agent is disconnected", instanceID) - return nil, false + r.logger.Infof("Instance %s agent is disconnected", instanceID) } // this is non-intuitive, but the ports being used by tasks are kept in diff --git a/api/backend/ecs/resource_manager_test.go b/api/backend/ecs/resource_manager_test.go index 1502fe3a9..5be4d54e8 100644 --- a/api/backend/ecs/resource_manager_test.go +++ b/api/backend/ecs/resource_manager_test.go @@ -71,7 +71,7 @@ func TestResourceManager_GetProviders(t *testing.T) { { &awsecs.ContainerInstance{ Status: stringp("ACTIVE"), - AgentConnected: boolp(true), + AgentConnected: boolp(false), RunningTasksCount: int64p(0), PendingTasksCount: int64p(0), RemainingResources: []*awsecs.Resource{ diff --git a/api/backend/ecs/service_manager.go b/api/backend/ecs/service_manager.go index 1448a6b78..faf48aff3 100644 --- a/api/backend/ecs/service_manager.go +++ b/api/backend/ecs/service_manager.go @@ -5,6 +5,7 @@ import ( "time" log "github.com/Sirupsen/logrus" + "github.com/aws/aws-sdk-go/aws/awserr" "github.com/quintilesims/layer0/api/backend" "github.com/quintilesims/layer0/api/backend/ecs/id" "github.com/quintilesims/layer0/common/aws/cloudwatchlogs" @@ -40,21 +41,25 @@ func NewECSServiceManager( } } -func (this *ECSServiceManager) ListServices() ([]*models.Service, error) { - serviceARNs, err := this.ECS.Helper_ListServices(id.PREFIX) +func (this *ECSServiceManager) ListServices() ([]id.ECSServiceID, error) { + clusterNames, err := this.Backend.ListEnvironments() if err != nil { return nil, err } - services := make([]*models.Service, len(serviceARNs)) - for i, arn := range serviceARNs { - ecsServiceID := id.ServiceARNToECSServiceID(*arn) - services[i] = &models.Service{ - ServiceID: ecsServiceID.L0ServiceID(), + serviceIDs := []id.ECSServiceID{} + for _, clusterName := range clusterNames { + clusterServiceIDs, err := this.ECS.ListClusterServiceNames(clusterName.String(), id.PREFIX) + if err != nil { + return nil, err + } + + for _, serviceID := range clusterServiceIDs { + serviceIDs = append(serviceIDs, id.ECSServiceID(serviceID)) } } - return services, nil + return serviceIDs, nil } func (this *ECSServiceManager) GetService(environmentID, serviceID string) (*models.Service, error) { @@ -63,9 +68,8 @@ func (this *ECSServiceManager) GetService(environmentID, serviceID string) (*mod description, err := this.ECS.DescribeService(ecsEnvironmentID.String(), ecsServiceID.String()) if err != nil { - if ContainsErrMsg(err, "Service Not Found") { - err := fmt.Errorf("Service with id '%s' does not exist", serviceID) - return nil, errors.New(errors.ServiceDoesNotExist, err) + if err, ok := err.(awserr.Error); ok && err.Code() == "ServiceNotFoundException" { + return nil, errors.Newf(errors.ServiceDoesNotExist, "Service '%s' does not exist", serviceID) } return nil, err @@ -74,6 +78,22 @@ func (this *ECSServiceManager) GetService(environmentID, serviceID string) (*mod return this.populateModel(description), nil } +func (this *ECSServiceManager) GetEnvironmentServices(environmentID string) ([]*models.Service, error) { + clusterName := id.L0EnvironmentID(environmentID).ECSEnvironmentID() + + serviceDescriptions, err := this.ECS.DescribeClusterServices(clusterName.String(), id.PREFIX) + if err != nil { + return nil, err + } + + services := make([]*models.Service, len(serviceDescriptions)) + for i, description := range serviceDescriptions { + services[i] = this.populateModel(description) + } + + return services, nil +} + func (this *ECSServiceManager) UpdateService( environmentID string, serviceID string, diff --git a/api/backend/ecs/service_manager_test.go b/api/backend/ecs/service_manager_test.go index 728af61bf..411c69030 100644 --- a/api/backend/ecs/service_manager_test.go +++ b/api/backend/ecs/service_manager_test.go @@ -15,6 +15,7 @@ import ( "github.com/quintilesims/layer0/common/aws/ecs/mock_ecs" "github.com/quintilesims/layer0/common/models" "github.com/quintilesims/layer0/common/testutils" + "github.com/stretchr/testify/assert" ) type MockECSServiceManager struct { @@ -111,74 +112,38 @@ func TestGetService(t *testing.T) { } func TestListServices(t *testing.T) { - testCases := []testutils.TestCase{ - { - Name: "Should call ecs.Helper_ListServices with proper params", - Setup: func(reporter *testutils.Reporter, ctrl *gomock.Controller) interface{} { - mockService := NewMockECSServiceManager(ctrl) + ctrl := gomock.NewController(t) + defer ctrl.Finish() - serviceID := id.L0ServiceID("svcid").ECSServiceID() - serviceARN := fmt.Sprintf("arn:aws:ecs:region:aws_account_id:service/%s", serviceID.String()) - - mockService.ECS.EXPECT(). - Helper_ListServices(id.PREFIX). - Return([]*string{&serviceARN}, nil) - - return mockService.Service() - }, - Run: func(reporter *testutils.Reporter, target interface{}) { - manager := target.(*ECSServiceManager) - manager.ListServices() - }, - }, - { - Name: "Should return layer0-formatted ids", - Setup: func(reporter *testutils.Reporter, ctrl *gomock.Controller) interface{} { - mockService := NewMockECSServiceManager(ctrl) - - serviceID := id.L0ServiceID("svcid").ECSServiceID() - serviceARN := fmt.Sprintf("arn:aws:ecs:region:aws_account_id:service/%s", serviceID.String()) - - mockService.ECS.EXPECT(). - Helper_ListServices(id.PREFIX). - Return([]*string{&serviceARN}, nil) - - return mockService.Service() - }, - Run: func(reporter *testutils.Reporter, target interface{}) { - manager := target.(*ECSServiceManager) + ecsEnvironmentIDs := []id.ECSEnvironmentID{ + id.ECSEnvironmentID("env_id1"), + id.ECSEnvironmentID("env_id2"), + } - services, err := manager.ListServices() - if err != nil { - reporter.Fatal(err) - } + mockService := NewMockECSServiceManager(ctrl) + mockService.Backend.EXPECT(). + ListEnvironments(). + Return(ecsEnvironmentIDs, nil) - reporter.AssertEqual(len(services), 1) - reporter.AssertEqual(services[0].ServiceID, "svcid") - }, - }, - { - Name: "Should propagate ecs.Helper_ListServices error", - Setup: func(reporter *testutils.Reporter, ctrl *gomock.Controller) interface{} { - mockService := NewMockECSServiceManager(ctrl) + for i, ecsEnvironmentID := range ecsEnvironmentIDs { + name := fmt.Sprintf("name_%d", i) - mockService.ECS.EXPECT(). - Helper_ListServices(gomock.Any()). - Return(nil, fmt.Errorf("some error")) + mockService.ECS.EXPECT(). + ListClusterServiceNames(ecsEnvironmentID.String(), id.PREFIX). + Return([]string{name}, nil) + } - return mockService.Service() - }, - Run: func(reporter *testutils.Reporter, target interface{}) { - manager := target.(*ECSServiceManager) + result, err := mockService.Service().ListServices() + if err != nil { + t.Fatal(err) + } - if _, err := manager.ListServices(); err == nil { - reporter.Fatalf("Error was nil!") - } - }, - }, + expected := []id.ECSServiceID{ + id.ECSServiceID("name_0"), + id.ECSServiceID("name_1"), } - testutils.RunTests(t, testCases) + assert.Equal(t, expected, result) } func TestDeleteService(t *testing.T) { diff --git a/api/backend/ecs/task_manager.go b/api/backend/ecs/task_manager.go index af058f456..8cb742c4b 100644 --- a/api/backend/ecs/task_manager.go +++ b/api/backend/ecs/task_manager.go @@ -1,9 +1,7 @@ package ecsbackend import ( - "fmt" - "strings" - + "github.com/aws/aws-sdk-go/aws" "github.com/quintilesims/layer0/api/backend" "github.com/quintilesims/layer0/api/backend/ecs/id" "github.com/quintilesims/layer0/common/aws/cloudwatchlogs" @@ -12,7 +10,10 @@ import ( "github.com/quintilesims/layer0/common/models" ) -var ClusterCapacityReason = "Waiting for cluster capacity to run" +const ( + ClusterCapacityReason = "Waiting for cluster capacity to run" + StopTaskReason = "Task deleted by user" +) type ECSTaskManager struct { ECS ecs.Provider @@ -32,148 +33,85 @@ func NewECSTaskManager( } } -func (this *ECSTaskManager) ListTasks() ([]*models.Task, error) { - environments, err := this.Backend.ListEnvironments() +func (this *ECSTaskManager) ListTasks() ([]string, error) { + clusterNames, err := this.Backend.ListEnvironments() if err != nil { return nil, err } - taskCopies := map[string][]*ecs.Task{} - for _, environment := range environments { - ecsEnvironmentID := id.L0EnvironmentID(environment.EnvironmentID).ECSEnvironmentID() - - taskARNs, err := getTaskARNs(this.ECS, ecsEnvironmentID, nil) + taskARNs := []string{} + for _, clusterName := range clusterNames { + clusterTaskARNs, err := this.ECS.ListClusterTaskARNs(clusterName.String(), id.PREFIX) if err != nil { return nil, err } - if len(taskARNs) > 0 { - tasks, err := this.describeTasks(ecsEnvironmentID, taskARNs) - if err != nil { - return nil, err - } - - for _, task := range tasks { - startedBy := stringOrEmpty(task.StartedBy) - - if strings.HasPrefix(startedBy, id.PREFIX) { - if _, ok := taskCopies[startedBy]; !ok { - taskCopies[startedBy] = []*ecs.Task{} - } - - taskCopies[startedBy] = append(taskCopies[startedBy], task) - } - } - } + taskARNs = append(taskARNs, clusterTaskARNs...) } - getModel := func(tasks []*ecs.Task) (*models.Task, error) { - if len(tasks) == 0 { - return nil, errors.Newf(errors.InvalidTaskID, "The specified task does not exist") - } - - model := &models.Task{ - EnvironmentID: id.ClusterARNToECSEnvironmentID(*tasks[0].ClusterArn).L0EnvironmentID(), - TaskID: id.ECSTaskID(*tasks[0].StartedBy).L0TaskID(), - } - - return model, nil - } - - tasks := []*models.Task{} - for _, copies := range taskCopies { - model, err := getModel(copies) - if err != nil { - return nil, err - } + return taskARNs, nil +} - tasks = append(tasks, model) +func (this *ECSTaskManager) GetTask(environmentID, taskARN string) (*models.Task, error) { + clusterName := id.L0EnvironmentID(environmentID).ECSEnvironmentID() + task, err := this.ECS.DescribeTask(clusterName.String(), taskARN) + if err != nil { + return nil, err } - return tasks, nil + return modelFromTasks([]*ecs.Task{task}) } -func (this *ECSTaskManager) GetTask(environmentID, taskID string) (*models.Task, error) { - ecsEnvironmentID := id.L0EnvironmentID(environmentID).ECSEnvironmentID() - ecsTaskID := id.L0TaskID(taskID).ECSTaskID() - - tasks, err := getTaskARNs(this.ECS, ecsEnvironmentID, stringp(ecsTaskID.String())) +func (this *ECSTaskManager) GetEnvironmentTasks(environmentID string) (map[string]*models.Task, error) { + clusterName := id.L0EnvironmentID(environmentID).ECSEnvironmentID() + taskDescriptions, err := this.ECS.DescribeEnvironmentTasks(clusterName.String(), id.PREFIX) if err != nil { return nil, err } - taskDescs := []*ecs.Task{} - if len(tasks) > 0 { - taskDescs, err = this.describeTasks(ecsEnvironmentID, tasks) + taskARNModels := map[string]*models.Task{} + for _, taskDescription := range taskDescriptions { + task, err := modelFromTasks([]*ecs.Task{taskDescription}) if err != nil { return nil, err } + + taskARNModels[aws.StringValue(taskDescription.TaskArn)] = task } - return modelFromTasks(taskDescs) + return taskARNModels, nil } -func (this *ECSTaskManager) DeleteTask(environmentID, taskID string) error { +func (this *ECSTaskManager) DeleteTask(environmentID, taskARN string) error { ecsEnvironmentID := id.L0EnvironmentID(environmentID).ECSEnvironmentID() - ecsTaskID := id.L0TaskID(taskID).ECSTaskID() - - taskARNs, err := getTaskARNs(this.ECS, ecsEnvironmentID, stringp(ecsTaskID.String())) - if err != nil { - return err - } - - // This stops the task, later reaping by AWS will prevent it from being returned. - reason := "Task stopped by User" - - for _, taskARN := range taskARNs { - if err := this.ECS.StopTask(ecsEnvironmentID.String(), reason, *taskARN); err != nil { - return err - } - } - - return nil + return this.ECS.StopTask(ecsEnvironmentID.String(), taskARN, StopTaskReason) } func (this *ECSTaskManager) CreateTask( environmentID string, - taskName string, deployID string, overrides []models.ContainerOverride, -) (*models.Task, error) { +) (string, error) { ecsEnvironmentID := id.L0EnvironmentID(environmentID).ECSEnvironmentID() ecsDeployID := id.L0DeployID(deployID).ECSDeployID() - taskID := id.GenerateHashedEntityID(taskName) - ecsTaskID := id.L0TaskID(taskID).ECSTaskID() - ecsOverrides := []*ecs.ContainerOverride{} for _, override := range overrides { o := ecs.NewContainerOverride(override.ContainerName, override.EnvironmentOverrides) ecsOverrides = append(ecsOverrides, o) } - tasks, failed, err := this.ECS.RunTask(ecsEnvironmentID.String(), ecsDeployID.TaskDefinition(), 1, stringp(ecsTaskID.String()), ecsOverrides) + startedBy := id.PREFIX + task, err := this.ECS.RunTask(ecsEnvironmentID.String(), ecsDeployID.TaskDefinition(), startedBy, ecsOverrides) if err != nil { - return nil, err + return "", err } - if len(failed) > 0 { - return nil, fmt.Errorf("ECS failed to start the task!") - } - - return modelFromTasks(tasks) + return aws.StringValue(task.TaskArn), nil } -func (this *ECSTaskManager) GetTaskLogs(environmentID, taskID, start, end string, tail int) ([]*models.LogFile, error) { - ecsEnvironmentID := id.L0EnvironmentID(environmentID).ECSEnvironmentID() - ecsTaskID := id.L0TaskID(taskID).ECSTaskID() - - taskARNs, err := getTaskARNs(this.ECS, ecsEnvironmentID, stringp(ecsTaskID.String())) - if err != nil { - return nil, err - } - - return GetLogs(this.CloudWatchLogs, taskARNs, start, end, tail) +func (this *ECSTaskManager) GetTaskLogs(environmentID, taskARN, start, end string, tail int) ([]*models.LogFile, error) { + return GetLogs(this.CloudWatchLogs, []*string{stringp(taskARN)}, start, end, tail) } // Assumes the tasks are all of the same type @@ -185,17 +123,18 @@ func modelFromTasks(tasks []*ecs.Task) (*models.Task, error) { var pendingCount, runningCount int64 copies := []models.TaskCopy{} for _, task := range tasks { - if *task.LastStatus == "RUNNING" { + switch status := aws.StringValue(task.LastStatus); status { + case "RUNNING": runningCount = runningCount + 1 - } else if *task.LastStatus == "PENDING" { + case "PENDING": pendingCount = pendingCount + 1 } details := []models.TaskDetail{} for _, container := range task.Containers { detail := models.TaskDetail{ - ContainerName: *container.Name, - LastStatus: *container.LastStatus, + ContainerName: aws.StringValue(container.Name), + LastStatus: aws.StringValue(container.LastStatus), Reason: stringOrEmpty(container.Reason), ExitCode: int64OrZero(container.ExitCode), } @@ -213,13 +152,9 @@ func modelFromTasks(tasks []*ecs.Task) (*models.Task, error) { } model := &models.Task{ - EnvironmentID: id.ClusterARNToECSEnvironmentID(*tasks[0].ClusterArn).L0EnvironmentID(), - PendingCount: pendingCount, - RunningCount: runningCount, - DesiredCount: int64(len(tasks)), - TaskID: id.ECSTaskID(*tasks[0].StartedBy).L0TaskID(), - Copies: copies, - DeployID: id.TaskDefinitionARNToECSDeployID(*tasks[0].TaskDefinitionArn).L0DeployID(), + RunningCount: runningCount, + PendingCount: pendingCount, + Copies: copies, } return model, nil diff --git a/api/backend/ecs/task_manager_test.go b/api/backend/ecs/task_manager_test.go index 988715406..198ffc79f 100644 --- a/api/backend/ecs/task_manager_test.go +++ b/api/backend/ecs/task_manager_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/aws/awserr" + "github.com/aws/aws-sdk-go/aws" aws_ecs "github.com/aws/aws-sdk-go/service/ecs" "github.com/golang/mock/gomock" "github.com/quintilesims/layer0/api/backend/ecs/id" @@ -15,6 +15,7 @@ import ( "github.com/quintilesims/layer0/common/aws/ecs/mock_ecs" "github.com/quintilesims/layer0/common/models" "github.com/quintilesims/layer0/common/testutils" + "github.com/stretchr/testify/assert" ) type MockECSTaskManager struct { @@ -37,265 +38,104 @@ func (this *MockECSTaskManager) Task() *ECSTaskManager { } func TestGetTask(t *testing.T) { - testCases := []testutils.TestCase{ - { - Name: "Should call ecs.ListTasks with proper params", - Setup: func(reporter *testutils.Reporter, ctrl *gomock.Controller) interface{} { - mockTask := NewMockECSTaskManager(ctrl) - - environmentID := id.L0EnvironmentID("envid").ECSEnvironmentID() - taskID := id.L0TaskID("tskid").ECSTaskID() - - mockTask.ECS.EXPECT(). - ListTasks(environmentID.String(), nil, gomock.Any(), stringp(taskID.String()), nil). - Return(nil, nil). - Times(2) + ctrl := gomock.NewController(t) + defer ctrl.Finish() - return mockTask.Task() - }, - Run: func(reporter *testutils.Reporter, target interface{}) { - manager := target.(*ECSTaskManager) - manager.GetTask("envid", "tskid") - }, + environmentID := id.L0EnvironmentID("env_id") + task := &ecs.Task{ + &aws_ecs.Task{ + LastStatus: aws.String("RUNNING"), }, - { - Name: "Should return layer0-formatted ids", - Setup: func(reporter *testutils.Reporter, ctrl *gomock.Controller) interface{} { - mockTask := NewMockECSTaskManager(ctrl) - - mockTask.ECS.EXPECT(). - ListTasks(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). - Return([]*string{stringp("task_arn")}, nil). - Times(2) - - task := &ecs.Task{ - &aws_ecs.Task{ - LastStatus: stringp("RUNNING"), - ClusterArn: stringp("aws:arn:ecs:cluster/envid"), - StartedBy: stringp("tskid"), - TaskDefinitionArn: stringp("aws:arn:ecs:task_definition/dply.1"), - }, - } - - mockTask.ECS.EXPECT(). - DescribeTasks(gomock.Any(), gomock.Any()). - Return([]*ecs.Task{task}, nil) - - return mockTask.Task() - }, - Run: func(reporter *testutils.Reporter, target interface{}) { - manager := target.(*ECSTaskManager) + } - task, err := manager.GetTask("envid", "tskid") - if err != nil { - reporter.Fatal(err) - } + mockTask := NewMockECSTaskManager(ctrl) + mockTask.ECS.EXPECT(). + DescribeTask(environmentID.ECSEnvironmentID().String(), "task_arn"). + Return(task, nil) - reporter.AssertEqual(task.TaskID, "tskid") - reporter.AssertEqual(task.EnvironmentID, "envid") - reporter.AssertEqual(task.DeployID, "dply.1") - }, - }, + result, err := mockTask.Task().GetTask("env_id", "task_arn") + if err != nil { + t.Fatal(err) } - testutils.RunTests(t, testCases) + assert.Equal(t, int64(1), result.RunningCount) + assert.Equal(t, int64(0), result.PendingCount) + assert.Len(t, result.Copies, 1) } func TestListTasks(t *testing.T) { - testCases := []testutils.TestCase{ - { - Name: "Should use proper params in dependent calls", - Setup: func(reporter *testutils.Reporter, ctrl *gomock.Controller) interface{} { - mockTask := NewMockECSTaskManager(ctrl) - - environmentID := id.L0EnvironmentID("envid") - environments := []*models.Environment{ - { - EnvironmentID: environmentID.String(), - }, - } + ctrl := gomock.NewController(t) + defer ctrl.Finish() - mockTask.Backend.EXPECT(). - ListEnvironments(). - Return(environments, nil) - - mockTask.ECS.EXPECT(). - ListTasks(environmentID.ECSEnvironmentID().String(), nil, gomock.Any(), nil, nil). - Return(nil, nil). - Times(2) + ecsEnvironmentIDs := []id.ECSEnvironmentID{ + id.ECSEnvironmentID("env_id1"), + id.ECSEnvironmentID("env_id2"), + } - return mockTask.Task() - }, - Run: func(reporter *testutils.Reporter, target interface{}) { - manager := target.(*ECSTaskManager) - manager.ListTasks() - }, - }, - { - Name: "Should propagate ecs.ListTasks error", - Setup: func(reporter *testutils.Reporter, ctrl *gomock.Controller) interface{} { - mockTask := NewMockECSTaskManager(ctrl) + mockTask := NewMockECSTaskManager(ctrl) + mockTask.Backend.EXPECT(). + ListEnvironments(). + Return(ecsEnvironmentIDs, nil) - environmentID := id.L0EnvironmentID("envid") - environments := []*models.Environment{ - { - EnvironmentID: environmentID.String(), - }, - } + for i, ecsEnvironmentID := range ecsEnvironmentIDs { + arn := fmt.Sprintf("arn_%d", i) - mockTask.Backend.EXPECT(). - ListEnvironments(). - Return(environments, nil) - - mockTask.ECS.EXPECT(). - ListTasks(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). - Return(nil, fmt.Errorf("some error")) + mockTask.ECS.EXPECT(). + ListClusterTaskARNs(ecsEnvironmentID.String(), id.PREFIX). + Return([]string{arn}, nil) + } - return mockTask.Task() - }, - Run: func(reporter *testutils.Reporter, target interface{}) { - manager := target.(*ECSTaskManager) + result, err := mockTask.Task().ListTasks() + if err != nil { + t.Fatal(err) + } - if _, err := manager.ListTasks(); err == nil { - reporter.Fatalf("Error was nil!") - } - }, - }, + expected := []string{ + "arn_0", + "arn_1", } - testutils.RunTests(t, testCases) + assert.Equal(t, expected, result) } func TestDeleteTask(t *testing.T) { - testCases := []testutils.TestCase{ - { - Name: "Should use proper params in dependent calls", - Setup: func(reporter *testutils.Reporter, ctrl *gomock.Controller) interface{} { - mockTask := NewMockECSTaskManager(ctrl) + ctrl := gomock.NewController(t) + defer ctrl.Finish() - environmentID := id.L0EnvironmentID("envid").ECSEnvironmentID() - taskID := id.L0TaskID("tskid").ECSTaskID() - - mockTask.ECS.EXPECT(). - ListTasks(environmentID.String(), nil, gomock.Any(), stringp(taskID.String()), nil). - Return(nil, nil). - Times(2) - - return mockTask.Task() - }, - Run: func(reporter *testutils.Reporter, target interface{}) { - manager := target.(*ECSTaskManager) - manager.DeleteTask("envid", "tskid") - }, - }, - { - Name: "Should propagate ecs.ListTasks error", - Setup: func(reporter *testutils.Reporter, ctrl *gomock.Controller) interface{} { - mockTask := NewMockECSTaskManager(ctrl) + mockTask := NewMockECSTaskManager(ctrl) + ecsEnvironmentID := id.L0EnvironmentID("env_id").ECSEnvironmentID() - mockTask.ECS.EXPECT(). - ListTasks(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). - Return(nil, fmt.Errorf("some error")) + mockTask.ECS.EXPECT(). + StopTask(ecsEnvironmentID.String(), "tsk_arn", StopTaskReason). + Return(nil) - return mockTask.Task() - }, - Run: func(reporter *testutils.Reporter, target interface{}) { - manager := target.(*ECSTaskManager) - - if err := manager.DeleteTask("envid", "tskid"); err == nil { - reporter.Fatalf("Error was nil!") - } - }, - }, + if err := mockTask.Task().DeleteTask("env_id", "tsk_arn"); err != nil { + t.Fatal(err) } - - testutils.RunTests(t, testCases) } func TestCreateTask(t *testing.T) { - defer id.StubIDGeneration("tskid")() + ctrl := gomock.NewController(t) + defer ctrl.Finish() - testCases := []testutils.TestCase{ - { - Name: "Should use proper params in aws calls", - Setup: func(reporter *testutils.Reporter, ctrl *gomock.Controller) interface{} { - mockTask := NewMockECSTaskManager(ctrl) + task := &ecs.Task{&aws_ecs.Task{ + TaskArn: aws.String("tsk_arn"), + }} - deployID := id.L0DeployID("dplyid.1").ECSDeployID() - environmentID := id.L0EnvironmentID("envid").ECSEnvironmentID() - taskID := id.L0TaskID("tskid").ECSTaskID() + ecsEnvironmentID := id.L0EnvironmentID("env_id").ECSEnvironmentID() + ecsDeployID := id.L0DeployID("dpl_id.1").ECSDeployID() - task := &ecs.TaskDefinition{ - &aws_ecs.TaskDefinition{ - Revision: int64p(1), - Family: stringp(deployID.FamilyName()), - }, - } - - mockTask.ECS.EXPECT(). - DescribeTaskDefinition(deployID.TaskDefinition()). - Return(task, nil). - AnyTimes() - - mockTask.ECS.EXPECT().RunTask( - environmentID.String(), - deployID.TaskDefinition(), - int64(1), - stringp(taskID.String()), - []*ecs.ContainerOverride{}, - ).Return(nil, nil, nil) - - return mockTask.Task() - }, - Run: func(reporter *testutils.Reporter, target interface{}) { - manager := target.(*ECSTaskManager) - manager.CreateTask("envid", "tsk_name", "dplyid.1", nil) - }, - }, - { - Name: "Should not create cloudwatch logs group if disableLogging is true", - Setup: func(reporter *testutils.Reporter, ctrl *gomock.Controller) interface{} { - mockTask := NewMockECSTaskManager(ctrl) - - mockTask.ECS.EXPECT().RunTask( - gomock.Any(), - gomock.Any(), - gomock.Any(), - gomock.Any(), - gomock.Any(), - ).Return(nil, nil, nil) - - return mockTask.Task() - }, - Run: func(reporter *testutils.Reporter, target interface{}) { - manager := target.(*ECSTaskManager) - manager.CreateTask("envid", "tsk_name", "dplyid.1", nil) - }, - }, - { - Name: "Should add task to scheduler when cluster capacity is low", - Setup: func(reporter *testutils.Reporter, ctrl *gomock.Controller) interface{} { - mockTask := NewMockECSTaskManager(ctrl) + mockTask := NewMockECSTaskManager(ctrl) + mockTask.ECS.EXPECT(). + RunTask(ecsEnvironmentID.String(), ecsDeployID.TaskDefinition(), id.PREFIX, []*ecs.ContainerOverride{}). + Return(task, nil) - err := awserr.New("", "No Container Instances were found in your cluster", nil) - mockTask.ECS.EXPECT().RunTask( - gomock.Any(), - gomock.Any(), - gomock.Any(), - gomock.Any(), - gomock.Any(), - ).Return(nil, nil, err) - - return mockTask.Task() - }, - Run: func(reporter *testutils.Reporter, target interface{}) { - manager := target.(*ECSTaskManager) - manager.CreateTask("envid", "tsk_name", "dplyid.1", nil) - }, - }, + result, err := mockTask.Task().CreateTask("env_id", "dpl_id.1", nil) + if err != nil { + t.Fatal(err) } - testutils.RunTests(t, testCases) + assert.Equal(t, "tsk_arn", result) } func TestGetTaskLogs(t *testing.T) { diff --git a/api/backend/interface.go b/api/backend/interface.go index de4492ed2..58dfed7a5 100644 --- a/api/backend/interface.go +++ b/api/backend/interface.go @@ -1,6 +1,7 @@ package backend import ( + "github.com/quintilesims/layer0/api/backend/ecs/id" "github.com/quintilesims/layer0/common/models" ) @@ -9,7 +10,7 @@ type Backend interface { UpdateEnvironment(environmentID string, minClusterCount int) (*models.Environment, error) DeleteEnvironment(environmentID string) error GetEnvironment(environmentID string) (*models.Environment, error) - ListEnvironments() ([]*models.Environment, error) + ListEnvironments() ([]id.ECSEnvironmentID, error) CreateEnvironmentLink(sourceEnvironmentID, destEnvironmentID string) error DeleteEnvironmentLink(sourceEnvironmentID, destEnvironmentID string) error @@ -18,19 +19,21 @@ type Backend interface { CreateDeploy(name string, body []byte) (*models.Deploy, error) DeleteDeploy(deployID string) error - ListServices() ([]*models.Service, error) - GetService(envID, serviceID string) (*models.Service, error) + ListServices() ([]id.ECSServiceID, error) + GetService(environmentID, serviceID string) (*models.Service, error) + GetEnvironmentServices(environmentID string) ([]*models.Service, error) CreateService(serviceName, environmentID, deployID, loadBalancerID string) (*models.Service, error) DeleteService(environmentID, serviceID string) error ScaleService(environmentID, serviceID string, count int) (*models.Service, error) UpdateService(environmentID, serviceID, deployID string) (*models.Service, error) GetServiceLogs(environmentID, serviceID, start, end string, tail int) ([]*models.LogFile, error) - CreateTask(envID, taskName, deployVersion string, overrides []models.ContainerOverride) (*models.Task, error) - ListTasks() ([]*models.Task, error) - GetTask(envID, taskID string) (*models.Task, error) - DeleteTask(envID, taskID string) error - GetTaskLogs(environmentID, taskID, start, end string, tail int) ([]*models.LogFile, error) + CreateTask(environmentID, deployID string, overrides []models.ContainerOverride) (string, error) + ListTasks() ([]string, error) + GetTask(environmentID, taskARN string) (*models.Task, error) + GetEnvironmentTasks(environmentID string) (map[string]*models.Task, error) + DeleteTask(environmentID, taskARN string) error + GetTaskLogs(environmentID, taskARN, start, end string, tail int) ([]*models.LogFile, error) ListLoadBalancers() ([]*models.LoadBalancer, error) GetLoadBalancer(id string) (*models.LoadBalancer, error) diff --git a/api/backend/mock_backend/mock_backend.go b/api/backend/mock_backend/mock_backend.go index 41970034f..a2adb0340 100644 --- a/api/backend/mock_backend/mock_backend.go +++ b/api/backend/mock_backend/mock_backend.go @@ -1,342 +1,432 @@ -// Automatically generated by MockGen. DO NOT EDIT! +// Code generated by MockGen. DO NOT EDIT. // Source: github.com/quintilesims/layer0/api/backend (interfaces: Backend) +// Package mock_backend is a generated GoMock package. package mock_backend import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" + id "github.com/quintilesims/layer0/api/backend/ecs/id" models "github.com/quintilesims/layer0/common/models" ) -// Mock of Backend interface +// MockBackend is a mock of Backend interface type MockBackend struct { ctrl *gomock.Controller - recorder *_MockBackendRecorder + recorder *MockBackendMockRecorder } -// Recorder for MockBackend (not exported) -type _MockBackendRecorder struct { +// MockBackendMockRecorder is the mock recorder for MockBackend +type MockBackendMockRecorder struct { mock *MockBackend } +// NewMockBackend creates a new mock instance func NewMockBackend(ctrl *gomock.Controller) *MockBackend { mock := &MockBackend{ctrl: ctrl} - mock.recorder = &_MockBackendRecorder{mock} + mock.recorder = &MockBackendMockRecorder{mock} return mock } -func (_m *MockBackend) EXPECT() *_MockBackendRecorder { - return _m.recorder +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockBackend) EXPECT() *MockBackendMockRecorder { + return m.recorder } -func (_m *MockBackend) CreateDeploy(_param0 string, _param1 []byte) (*models.Deploy, error) { - ret := _m.ctrl.Call(_m, "CreateDeploy", _param0, _param1) +// CreateDeploy mocks base method +func (m *MockBackend) CreateDeploy(arg0 string, arg1 []byte) (*models.Deploy, error) { + ret := m.ctrl.Call(m, "CreateDeploy", arg0, arg1) ret0, _ := ret[0].(*models.Deploy) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockBackendRecorder) CreateDeploy(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateDeploy", arg0, arg1) +// CreateDeploy indicates an expected call of CreateDeploy +func (mr *MockBackendMockRecorder) CreateDeploy(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateDeploy", reflect.TypeOf((*MockBackend)(nil).CreateDeploy), arg0, arg1) } -func (_m *MockBackend) CreateEnvironment(_param0 string, _param1 string, _param2 string, _param3 string, _param4 int, _param5 []byte) (*models.Environment, error) { - ret := _m.ctrl.Call(_m, "CreateEnvironment", _param0, _param1, _param2, _param3, _param4, _param5) +// CreateEnvironment mocks base method +func (m *MockBackend) CreateEnvironment(arg0, arg1, arg2, arg3 string, arg4 int, arg5 []byte) (*models.Environment, error) { + ret := m.ctrl.Call(m, "CreateEnvironment", arg0, arg1, arg2, arg3, arg4, arg5) ret0, _ := ret[0].(*models.Environment) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockBackendRecorder) CreateEnvironment(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateEnvironment", arg0, arg1, arg2, arg3, arg4, arg5) +// CreateEnvironment indicates an expected call of CreateEnvironment +func (mr *MockBackendMockRecorder) CreateEnvironment(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateEnvironment", reflect.TypeOf((*MockBackend)(nil).CreateEnvironment), arg0, arg1, arg2, arg3, arg4, arg5) } -func (_m *MockBackend) CreateEnvironmentLink(_param0 string, _param1 string) error { - ret := _m.ctrl.Call(_m, "CreateEnvironmentLink", _param0, _param1) +// CreateEnvironmentLink mocks base method +func (m *MockBackend) CreateEnvironmentLink(arg0, arg1 string) error { + ret := m.ctrl.Call(m, "CreateEnvironmentLink", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockBackendRecorder) CreateEnvironmentLink(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateEnvironmentLink", arg0, arg1) +// CreateEnvironmentLink indicates an expected call of CreateEnvironmentLink +func (mr *MockBackendMockRecorder) CreateEnvironmentLink(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateEnvironmentLink", reflect.TypeOf((*MockBackend)(nil).CreateEnvironmentLink), arg0, arg1) } -func (_m *MockBackend) CreateLoadBalancer(_param0 string, _param1 string, _param2 bool, _param3 []models.Port, _param4 models.HealthCheck) (*models.LoadBalancer, error) { - ret := _m.ctrl.Call(_m, "CreateLoadBalancer", _param0, _param1, _param2, _param3, _param4) +// CreateLoadBalancer mocks base method +func (m *MockBackend) CreateLoadBalancer(arg0, arg1 string, arg2 bool, arg3 []models.Port, arg4 models.HealthCheck) (*models.LoadBalancer, error) { + ret := m.ctrl.Call(m, "CreateLoadBalancer", arg0, arg1, arg2, arg3, arg4) ret0, _ := ret[0].(*models.LoadBalancer) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockBackendRecorder) CreateLoadBalancer(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateLoadBalancer", arg0, arg1, arg2, arg3, arg4) +// CreateLoadBalancer indicates an expected call of CreateLoadBalancer +func (mr *MockBackendMockRecorder) CreateLoadBalancer(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateLoadBalancer", reflect.TypeOf((*MockBackend)(nil).CreateLoadBalancer), arg0, arg1, arg2, arg3, arg4) } -func (_m *MockBackend) CreateService(_param0 string, _param1 string, _param2 string, _param3 string) (*models.Service, error) { - ret := _m.ctrl.Call(_m, "CreateService", _param0, _param1, _param2, _param3) +// CreateService mocks base method +func (m *MockBackend) CreateService(arg0, arg1, arg2, arg3 string) (*models.Service, error) { + ret := m.ctrl.Call(m, "CreateService", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(*models.Service) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockBackendRecorder) CreateService(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateService", arg0, arg1, arg2, arg3) +// CreateService indicates an expected call of CreateService +func (mr *MockBackendMockRecorder) CreateService(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateService", reflect.TypeOf((*MockBackend)(nil).CreateService), arg0, arg1, arg2, arg3) } -func (_m *MockBackend) CreateTask(_param0 string, _param1 string, _param2 string, _param3 []models.ContainerOverride) (*models.Task, error) { - ret := _m.ctrl.Call(_m, "CreateTask", _param0, _param1, _param2, _param3) - ret0, _ := ret[0].(*models.Task) +// CreateTask mocks base method +func (m *MockBackend) CreateTask(arg0, arg1 string, arg2 []models.ContainerOverride) (string, error) { + ret := m.ctrl.Call(m, "CreateTask", arg0, arg1, arg2) + ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockBackendRecorder) CreateTask(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateTask", arg0, arg1, arg2, arg3) +// CreateTask indicates an expected call of CreateTask +func (mr *MockBackendMockRecorder) CreateTask(arg0, arg1, arg2 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateTask", reflect.TypeOf((*MockBackend)(nil).CreateTask), arg0, arg1, arg2) } -func (_m *MockBackend) DeleteDeploy(_param0 string) error { - ret := _m.ctrl.Call(_m, "DeleteDeploy", _param0) +// DeleteDeploy mocks base method +func (m *MockBackend) DeleteDeploy(arg0 string) error { + ret := m.ctrl.Call(m, "DeleteDeploy", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockBackendRecorder) DeleteDeploy(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteDeploy", arg0) +// DeleteDeploy indicates an expected call of DeleteDeploy +func (mr *MockBackendMockRecorder) DeleteDeploy(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteDeploy", reflect.TypeOf((*MockBackend)(nil).DeleteDeploy), arg0) } -func (_m *MockBackend) DeleteEnvironment(_param0 string) error { - ret := _m.ctrl.Call(_m, "DeleteEnvironment", _param0) +// DeleteEnvironment mocks base method +func (m *MockBackend) DeleteEnvironment(arg0 string) error { + ret := m.ctrl.Call(m, "DeleteEnvironment", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockBackendRecorder) DeleteEnvironment(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteEnvironment", arg0) +// DeleteEnvironment indicates an expected call of DeleteEnvironment +func (mr *MockBackendMockRecorder) DeleteEnvironment(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteEnvironment", reflect.TypeOf((*MockBackend)(nil).DeleteEnvironment), arg0) } -func (_m *MockBackend) DeleteEnvironmentLink(_param0 string, _param1 string) error { - ret := _m.ctrl.Call(_m, "DeleteEnvironmentLink", _param0, _param1) +// DeleteEnvironmentLink mocks base method +func (m *MockBackend) DeleteEnvironmentLink(arg0, arg1 string) error { + ret := m.ctrl.Call(m, "DeleteEnvironmentLink", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockBackendRecorder) DeleteEnvironmentLink(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteEnvironmentLink", arg0, arg1) +// DeleteEnvironmentLink indicates an expected call of DeleteEnvironmentLink +func (mr *MockBackendMockRecorder) DeleteEnvironmentLink(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteEnvironmentLink", reflect.TypeOf((*MockBackend)(nil).DeleteEnvironmentLink), arg0, arg1) } -func (_m *MockBackend) DeleteLoadBalancer(_param0 string) error { - ret := _m.ctrl.Call(_m, "DeleteLoadBalancer", _param0) +// DeleteLoadBalancer mocks base method +func (m *MockBackend) DeleteLoadBalancer(arg0 string) error { + ret := m.ctrl.Call(m, "DeleteLoadBalancer", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockBackendRecorder) DeleteLoadBalancer(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteLoadBalancer", arg0) +// DeleteLoadBalancer indicates an expected call of DeleteLoadBalancer +func (mr *MockBackendMockRecorder) DeleteLoadBalancer(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteLoadBalancer", reflect.TypeOf((*MockBackend)(nil).DeleteLoadBalancer), arg0) } -func (_m *MockBackend) DeleteService(_param0 string, _param1 string) error { - ret := _m.ctrl.Call(_m, "DeleteService", _param0, _param1) +// DeleteService mocks base method +func (m *MockBackend) DeleteService(arg0, arg1 string) error { + ret := m.ctrl.Call(m, "DeleteService", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockBackendRecorder) DeleteService(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteService", arg0, arg1) +// DeleteService indicates an expected call of DeleteService +func (mr *MockBackendMockRecorder) DeleteService(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteService", reflect.TypeOf((*MockBackend)(nil).DeleteService), arg0, arg1) } -func (_m *MockBackend) DeleteTask(_param0 string, _param1 string) error { - ret := _m.ctrl.Call(_m, "DeleteTask", _param0, _param1) +// DeleteTask mocks base method +func (m *MockBackend) DeleteTask(arg0, arg1 string) error { + ret := m.ctrl.Call(m, "DeleteTask", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockBackendRecorder) DeleteTask(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteTask", arg0, arg1) +// DeleteTask indicates an expected call of DeleteTask +func (mr *MockBackendMockRecorder) DeleteTask(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteTask", reflect.TypeOf((*MockBackend)(nil).DeleteTask), arg0, arg1) } -func (_m *MockBackend) GetDeploy(_param0 string) (*models.Deploy, error) { - ret := _m.ctrl.Call(_m, "GetDeploy", _param0) +// GetDeploy mocks base method +func (m *MockBackend) GetDeploy(arg0 string) (*models.Deploy, error) { + ret := m.ctrl.Call(m, "GetDeploy", arg0) ret0, _ := ret[0].(*models.Deploy) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockBackendRecorder) GetDeploy(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetDeploy", arg0) +// GetDeploy indicates an expected call of GetDeploy +func (mr *MockBackendMockRecorder) GetDeploy(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDeploy", reflect.TypeOf((*MockBackend)(nil).GetDeploy), arg0) } -func (_m *MockBackend) GetEnvironment(_param0 string) (*models.Environment, error) { - ret := _m.ctrl.Call(_m, "GetEnvironment", _param0) +// GetEnvironment mocks base method +func (m *MockBackend) GetEnvironment(arg0 string) (*models.Environment, error) { + ret := m.ctrl.Call(m, "GetEnvironment", arg0) ret0, _ := ret[0].(*models.Environment) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockBackendRecorder) GetEnvironment(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetEnvironment", arg0) +// GetEnvironment indicates an expected call of GetEnvironment +func (mr *MockBackendMockRecorder) GetEnvironment(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEnvironment", reflect.TypeOf((*MockBackend)(nil).GetEnvironment), arg0) +} + +// GetEnvironmentServices mocks base method +func (m *MockBackend) GetEnvironmentServices(arg0 string) ([]*models.Service, error) { + ret := m.ctrl.Call(m, "GetEnvironmentServices", arg0) + ret0, _ := ret[0].([]*models.Service) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetEnvironmentServices indicates an expected call of GetEnvironmentServices +func (mr *MockBackendMockRecorder) GetEnvironmentServices(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEnvironmentServices", reflect.TypeOf((*MockBackend)(nil).GetEnvironmentServices), arg0) +} + +// GetEnvironmentTasks mocks base method +func (m *MockBackend) GetEnvironmentTasks(arg0 string) (map[string]*models.Task, error) { + ret := m.ctrl.Call(m, "GetEnvironmentTasks", arg0) + ret0, _ := ret[0].(map[string]*models.Task) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetEnvironmentTasks indicates an expected call of GetEnvironmentTasks +func (mr *MockBackendMockRecorder) GetEnvironmentTasks(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEnvironmentTasks", reflect.TypeOf((*MockBackend)(nil).GetEnvironmentTasks), arg0) } -func (_m *MockBackend) GetLoadBalancer(_param0 string) (*models.LoadBalancer, error) { - ret := _m.ctrl.Call(_m, "GetLoadBalancer", _param0) +// GetLoadBalancer mocks base method +func (m *MockBackend) GetLoadBalancer(arg0 string) (*models.LoadBalancer, error) { + ret := m.ctrl.Call(m, "GetLoadBalancer", arg0) ret0, _ := ret[0].(*models.LoadBalancer) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockBackendRecorder) GetLoadBalancer(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetLoadBalancer", arg0) +// GetLoadBalancer indicates an expected call of GetLoadBalancer +func (mr *MockBackendMockRecorder) GetLoadBalancer(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLoadBalancer", reflect.TypeOf((*MockBackend)(nil).GetLoadBalancer), arg0) } -func (_m *MockBackend) GetService(_param0 string, _param1 string) (*models.Service, error) { - ret := _m.ctrl.Call(_m, "GetService", _param0, _param1) +// GetService mocks base method +func (m *MockBackend) GetService(arg0, arg1 string) (*models.Service, error) { + ret := m.ctrl.Call(m, "GetService", arg0, arg1) ret0, _ := ret[0].(*models.Service) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockBackendRecorder) GetService(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetService", arg0, arg1) +// GetService indicates an expected call of GetService +func (mr *MockBackendMockRecorder) GetService(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetService", reflect.TypeOf((*MockBackend)(nil).GetService), arg0, arg1) } -func (_m *MockBackend) GetServiceLogs(_param0 string, _param1 string, _param2 string, _param3 string, _param4 int) ([]*models.LogFile, error) { - ret := _m.ctrl.Call(_m, "GetServiceLogs", _param0, _param1, _param2, _param3, _param4) +// GetServiceLogs mocks base method +func (m *MockBackend) GetServiceLogs(arg0, arg1, arg2, arg3 string, arg4 int) ([]*models.LogFile, error) { + ret := m.ctrl.Call(m, "GetServiceLogs", arg0, arg1, arg2, arg3, arg4) ret0, _ := ret[0].([]*models.LogFile) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockBackendRecorder) GetServiceLogs(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetServiceLogs", arg0, arg1, arg2, arg3, arg4) +// GetServiceLogs indicates an expected call of GetServiceLogs +func (mr *MockBackendMockRecorder) GetServiceLogs(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetServiceLogs", reflect.TypeOf((*MockBackend)(nil).GetServiceLogs), arg0, arg1, arg2, arg3, arg4) } -func (_m *MockBackend) GetTask(_param0 string, _param1 string) (*models.Task, error) { - ret := _m.ctrl.Call(_m, "GetTask", _param0, _param1) +// GetTask mocks base method +func (m *MockBackend) GetTask(arg0, arg1 string) (*models.Task, error) { + ret := m.ctrl.Call(m, "GetTask", arg0, arg1) ret0, _ := ret[0].(*models.Task) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockBackendRecorder) GetTask(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetTask", arg0, arg1) +// GetTask indicates an expected call of GetTask +func (mr *MockBackendMockRecorder) GetTask(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTask", reflect.TypeOf((*MockBackend)(nil).GetTask), arg0, arg1) } -func (_m *MockBackend) GetTaskLogs(_param0 string, _param1 string, _param2 string, _param3 string, _param4 int) ([]*models.LogFile, error) { - ret := _m.ctrl.Call(_m, "GetTaskLogs", _param0, _param1, _param2, _param3, _param4) +// GetTaskLogs mocks base method +func (m *MockBackend) GetTaskLogs(arg0, arg1, arg2, arg3 string, arg4 int) ([]*models.LogFile, error) { + ret := m.ctrl.Call(m, "GetTaskLogs", arg0, arg1, arg2, arg3, arg4) ret0, _ := ret[0].([]*models.LogFile) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockBackendRecorder) GetTaskLogs(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetTaskLogs", arg0, arg1, arg2, arg3, arg4) +// GetTaskLogs indicates an expected call of GetTaskLogs +func (mr *MockBackendMockRecorder) GetTaskLogs(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTaskLogs", reflect.TypeOf((*MockBackend)(nil).GetTaskLogs), arg0, arg1, arg2, arg3, arg4) } -func (_m *MockBackend) ListDeploys() ([]*models.Deploy, error) { - ret := _m.ctrl.Call(_m, "ListDeploys") +// ListDeploys mocks base method +func (m *MockBackend) ListDeploys() ([]*models.Deploy, error) { + ret := m.ctrl.Call(m, "ListDeploys") ret0, _ := ret[0].([]*models.Deploy) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockBackendRecorder) ListDeploys() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListDeploys") +// ListDeploys indicates an expected call of ListDeploys +func (mr *MockBackendMockRecorder) ListDeploys() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListDeploys", reflect.TypeOf((*MockBackend)(nil).ListDeploys)) } -func (_m *MockBackend) ListEnvironments() ([]*models.Environment, error) { - ret := _m.ctrl.Call(_m, "ListEnvironments") - ret0, _ := ret[0].([]*models.Environment) +// ListEnvironments mocks base method +func (m *MockBackend) ListEnvironments() ([]id.ECSEnvironmentID, error) { + ret := m.ctrl.Call(m, "ListEnvironments") + ret0, _ := ret[0].([]id.ECSEnvironmentID) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockBackendRecorder) ListEnvironments() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListEnvironments") +// ListEnvironments indicates an expected call of ListEnvironments +func (mr *MockBackendMockRecorder) ListEnvironments() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListEnvironments", reflect.TypeOf((*MockBackend)(nil).ListEnvironments)) } -func (_m *MockBackend) ListLoadBalancers() ([]*models.LoadBalancer, error) { - ret := _m.ctrl.Call(_m, "ListLoadBalancers") +// ListLoadBalancers mocks base method +func (m *MockBackend) ListLoadBalancers() ([]*models.LoadBalancer, error) { + ret := m.ctrl.Call(m, "ListLoadBalancers") ret0, _ := ret[0].([]*models.LoadBalancer) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockBackendRecorder) ListLoadBalancers() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListLoadBalancers") +// ListLoadBalancers indicates an expected call of ListLoadBalancers +func (mr *MockBackendMockRecorder) ListLoadBalancers() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListLoadBalancers", reflect.TypeOf((*MockBackend)(nil).ListLoadBalancers)) } -func (_m *MockBackend) ListServices() ([]*models.Service, error) { - ret := _m.ctrl.Call(_m, "ListServices") - ret0, _ := ret[0].([]*models.Service) +// ListServices mocks base method +func (m *MockBackend) ListServices() ([]id.ECSServiceID, error) { + ret := m.ctrl.Call(m, "ListServices") + ret0, _ := ret[0].([]id.ECSServiceID) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockBackendRecorder) ListServices() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListServices") +// ListServices indicates an expected call of ListServices +func (mr *MockBackendMockRecorder) ListServices() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListServices", reflect.TypeOf((*MockBackend)(nil).ListServices)) } -func (_m *MockBackend) ListTasks() ([]*models.Task, error) { - ret := _m.ctrl.Call(_m, "ListTasks") - ret0, _ := ret[0].([]*models.Task) +// ListTasks mocks base method +func (m *MockBackend) ListTasks() ([]string, error) { + ret := m.ctrl.Call(m, "ListTasks") + ret0, _ := ret[0].([]string) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockBackendRecorder) ListTasks() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListTasks") +// ListTasks indicates an expected call of ListTasks +func (mr *MockBackendMockRecorder) ListTasks() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListTasks", reflect.TypeOf((*MockBackend)(nil).ListTasks)) } -func (_m *MockBackend) ScaleService(_param0 string, _param1 string, _param2 int) (*models.Service, error) { - ret := _m.ctrl.Call(_m, "ScaleService", _param0, _param1, _param2) +// ScaleService mocks base method +func (m *MockBackend) ScaleService(arg0, arg1 string, arg2 int) (*models.Service, error) { + ret := m.ctrl.Call(m, "ScaleService", arg0, arg1, arg2) ret0, _ := ret[0].(*models.Service) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockBackendRecorder) ScaleService(arg0, arg1, arg2 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ScaleService", arg0, arg1, arg2) +// ScaleService indicates an expected call of ScaleService +func (mr *MockBackendMockRecorder) ScaleService(arg0, arg1, arg2 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ScaleService", reflect.TypeOf((*MockBackend)(nil).ScaleService), arg0, arg1, arg2) } -func (_m *MockBackend) UpdateEnvironment(_param0 string, _param1 int) (*models.Environment, error) { - ret := _m.ctrl.Call(_m, "UpdateEnvironment", _param0, _param1) +// UpdateEnvironment mocks base method +func (m *MockBackend) UpdateEnvironment(arg0 string, arg1 int) (*models.Environment, error) { + ret := m.ctrl.Call(m, "UpdateEnvironment", arg0, arg1) ret0, _ := ret[0].(*models.Environment) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockBackendRecorder) UpdateEnvironment(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "UpdateEnvironment", arg0, arg1) +// UpdateEnvironment indicates an expected call of UpdateEnvironment +func (mr *MockBackendMockRecorder) UpdateEnvironment(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateEnvironment", reflect.TypeOf((*MockBackend)(nil).UpdateEnvironment), arg0, arg1) } -func (_m *MockBackend) UpdateLoadBalancerHealthCheck(_param0 string, _param1 models.HealthCheck) (*models.LoadBalancer, error) { - ret := _m.ctrl.Call(_m, "UpdateLoadBalancerHealthCheck", _param0, _param1) +// UpdateLoadBalancerHealthCheck mocks base method +func (m *MockBackend) UpdateLoadBalancerHealthCheck(arg0 string, arg1 models.HealthCheck) (*models.LoadBalancer, error) { + ret := m.ctrl.Call(m, "UpdateLoadBalancerHealthCheck", arg0, arg1) ret0, _ := ret[0].(*models.LoadBalancer) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockBackendRecorder) UpdateLoadBalancerHealthCheck(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "UpdateLoadBalancerHealthCheck", arg0, arg1) +// UpdateLoadBalancerHealthCheck indicates an expected call of UpdateLoadBalancerHealthCheck +func (mr *MockBackendMockRecorder) UpdateLoadBalancerHealthCheck(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateLoadBalancerHealthCheck", reflect.TypeOf((*MockBackend)(nil).UpdateLoadBalancerHealthCheck), arg0, arg1) } -func (_m *MockBackend) UpdateLoadBalancerPorts(_param0 string, _param1 []models.Port) (*models.LoadBalancer, error) { - ret := _m.ctrl.Call(_m, "UpdateLoadBalancerPorts", _param0, _param1) +// UpdateLoadBalancerPorts mocks base method +func (m *MockBackend) UpdateLoadBalancerPorts(arg0 string, arg1 []models.Port) (*models.LoadBalancer, error) { + ret := m.ctrl.Call(m, "UpdateLoadBalancerPorts", arg0, arg1) ret0, _ := ret[0].(*models.LoadBalancer) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockBackendRecorder) UpdateLoadBalancerPorts(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "UpdateLoadBalancerPorts", arg0, arg1) +// UpdateLoadBalancerPorts indicates an expected call of UpdateLoadBalancerPorts +func (mr *MockBackendMockRecorder) UpdateLoadBalancerPorts(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateLoadBalancerPorts", reflect.TypeOf((*MockBackend)(nil).UpdateLoadBalancerPorts), arg0, arg1) } -func (_m *MockBackend) UpdateService(_param0 string, _param1 string, _param2 string) (*models.Service, error) { - ret := _m.ctrl.Call(_m, "UpdateService", _param0, _param1, _param2) +// UpdateService mocks base method +func (m *MockBackend) UpdateService(arg0, arg1, arg2 string) (*models.Service, error) { + ret := m.ctrl.Call(m, "UpdateService", arg0, arg1, arg2) ret0, _ := ret[0].(*models.Service) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockBackendRecorder) UpdateService(arg0, arg1, arg2 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "UpdateService", arg0, arg1, arg2) +// UpdateService indicates an expected call of UpdateService +func (mr *MockBackendMockRecorder) UpdateService(arg0, arg1, arg2 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateService", reflect.TypeOf((*MockBackend)(nil).UpdateService), arg0, arg1, arg2) } diff --git a/api/handlers/environment_handler_test.go b/api/handlers/environment_handler_test.go index 28bcdde62..95f08ca11 100644 --- a/api/handlers/environment_handler_test.go +++ b/api/handlers/environment_handler_test.go @@ -14,7 +14,7 @@ import ( ) func TestListEnvironments(t *testing.T) { - environments := []*models.EnvironmentSummary{ + environments := []models.EnvironmentSummary{ { EnvironmentID: "some_id_1", }, @@ -41,7 +41,7 @@ func TestListEnvironments(t *testing.T) { handler := target.(*EnvironmentHandler) handler.ListEnvironments(req, resp) - var response []*models.EnvironmentSummary + var response []models.EnvironmentSummary read(&response) reporter.AssertEqual(response, environments) diff --git a/api/handlers/service_handler_test.go b/api/handlers/service_handler_test.go index 45f70b74c..74d8be805 100644 --- a/api/handlers/service_handler_test.go +++ b/api/handlers/service_handler_test.go @@ -13,7 +13,7 @@ import ( ) func TestListServices(t *testing.T) { - services := []*models.ServiceSummary{ + services := []models.ServiceSummary{ { ServiceID: "some_id_1", }, @@ -40,7 +40,7 @@ func TestListServices(t *testing.T) { handler := target.(*ServiceHandler) handler.ListServices(req, resp) - var response []*models.ServiceSummary + var response []models.ServiceSummary read(&response) reporter.AssertEqual(response, services) diff --git a/api/handlers/task_handler_test.go b/api/handlers/task_handler_test.go index fee5a2c3d..c27033a66 100644 --- a/api/handlers/task_handler_test.go +++ b/api/handlers/task_handler_test.go @@ -232,7 +232,6 @@ func TestCreateTask(t *testing.T) { TaskName: "tsk_name", DeployID: "dply_id", EnvironmentID: "env_id", - Copies: 2, } testCase := HandlerTestCase{ diff --git a/api/logic/environment_logic.go b/api/logic/environment_logic.go index ccee3fd31..4863e99bd 100644 --- a/api/logic/environment_logic.go +++ b/api/logic/environment_logic.go @@ -1,12 +1,13 @@ package logic import ( + "github.com/quintilesims/layer0/api/backend/ecs/id" "github.com/quintilesims/layer0/common/errors" "github.com/quintilesims/layer0/common/models" ) type EnvironmentLogic interface { - ListEnvironments() ([]*models.EnvironmentSummary, error) + ListEnvironments() ([]models.EnvironmentSummary, error) GetEnvironment(id string) (*models.Environment, error) DeleteEnvironment(id string) error CanCreateEnvironment(req models.CreateEnvironmentRequest) (bool, error) @@ -26,26 +27,13 @@ func NewL0EnvironmentLogic(logic Logic) *L0EnvironmentLogic { } } -func (e *L0EnvironmentLogic) ListEnvironments() ([]*models.EnvironmentSummary, error) { - environments, err := e.Backend.ListEnvironments() +func (e *L0EnvironmentLogic) ListEnvironments() ([]models.EnvironmentSummary, error) { + environmentIDs, err := e.Backend.ListEnvironments() if err != nil { return nil, err } - summaries := make([]*models.EnvironmentSummary, len(environments)) - for i, environment := range environments { - if err := e.populateModel(environment); err != nil { - return nil, err - } - - summaries[i] = &models.EnvironmentSummary{ - EnvironmentID: environment.EnvironmentID, - EnvironmentName: environment.EnvironmentName, - OperatingSystem: environment.OperatingSystem, - } - } - - return summaries, nil + return e.makeEnvironmentSummaryModels(environmentIDs) } func (e *L0EnvironmentLogic) GetEnvironment(environmentID string) (*models.Environment, error) { @@ -209,3 +197,26 @@ func (e *L0EnvironmentLogic) populateModel(model *models.Environment) error { return nil } + +func (e *L0EnvironmentLogic) makeEnvironmentSummaryModels(environmentIDs []id.ECSEnvironmentID) ([]models.EnvironmentSummary, error) { + tags, err := e.TagStore.SelectByType("environment") + if err != nil { + return nil, err + } + + summaries := make([]models.EnvironmentSummary, len(environmentIDs)) + for i, ecsEnvironmentID := range environmentIDs { + environmentID := ecsEnvironmentID.L0EnvironmentID() + summaries[i].EnvironmentID = environmentID + + if tag, ok := tags.WithID(environmentID).WithKey("name").First(); ok { + summaries[i].EnvironmentName = tag.Value + } + + if tag, ok := tags.WithID(environmentID).WithKey("os").First(); ok { + summaries[i].OperatingSystem = tag.Value + } + } + + return summaries, nil +} diff --git a/api/logic/environment_logic_test.go b/api/logic/environment_logic_test.go index 5f6fa9192..4fa2d640f 100644 --- a/api/logic/environment_logic_test.go +++ b/api/logic/environment_logic_test.go @@ -3,8 +3,10 @@ package logic import ( "testing" + "github.com/quintilesims/layer0/api/backend/ecs/id" "github.com/quintilesims/layer0/common/models" "github.com/quintilesims/layer0/common/testutils" + "github.com/stretchr/testify/assert" ) func TestGetEnvironment(t *testing.T) { @@ -46,43 +48,43 @@ func TestListEnvironments(t *testing.T) { testLogic, ctrl := NewTestLogic(t) defer ctrl.Finish() - retEnvironments := []*models.Environment{ - {EnvironmentID: "e1"}, - {EnvironmentID: "e2"}, + ecsEnvironmentIDs := []id.ECSEnvironmentID{ + id.L0EnvironmentID("env_id1").ECSEnvironmentID(), + id.L0EnvironmentID("env_id2").ECSEnvironmentID(), } testLogic.Backend.EXPECT(). ListEnvironments(). - Return(retEnvironments, nil) + Return(ecsEnvironmentIDs, nil) testLogic.AddTags(t, []*models.Tag{ - {EntityID: "e1", EntityType: "environment", Key: "name", Value: "env_1"}, - {EntityID: "e1", EntityType: "environment", Key: "os", Value: "linux"}, - {EntityID: "e2", EntityType: "environment", Key: "name", Value: "env_2"}, - {EntityID: "e2", EntityType: "environment", Key: "os", Value: "windows"}, + {EntityID: "env_id1", EntityType: "environment", Key: "name", Value: "env_name1"}, + {EntityID: "env_id1", EntityType: "environment", Key: "os", Value: "linux"}, + {EntityID: "env_id2", EntityType: "environment", Key: "name", Value: "env_name2"}, + {EntityID: "env_id2", EntityType: "environment", Key: "os", Value: "windows"}, {EntityID: "extra", EntityType: "environment", Key: "name", Value: "extra"}, }) environmentLogic := NewL0EnvironmentLogic(testLogic.Logic()) - received, err := environmentLogic.ListEnvironments() + result, err := environmentLogic.ListEnvironments() if err != nil { t.Fatal(err) } - expected := []*models.EnvironmentSummary{ + expected := []models.EnvironmentSummary{ { - EnvironmentID: "e1", - EnvironmentName: "env_1", + EnvironmentID: "env_id1", + EnvironmentName: "env_name1", OperatingSystem: "linux", }, { - EnvironmentID: "e2", - EnvironmentName: "env_2", + EnvironmentID: "env_id2", + EnvironmentName: "env_name2", OperatingSystem: "windows", }, } - testutils.AssertEqual(t, received, expected) + assert.Equal(t, expected, result) } func TestDeleteEnvironment(t *testing.T) { diff --git a/api/logic/environment_resource_getter.go b/api/logic/environment_resource_getter.go index 2429ebcae..1e49504cd 100644 --- a/api/logic/environment_resource_getter.go +++ b/api/logic/environment_resource_getter.go @@ -51,85 +51,71 @@ func (c *EnvironmentResourceGetter) GetConsumers(environmentID string) ([]resour } func (c *EnvironmentResourceGetter) getPendingServiceResources(environmentID string) ([]resource.ResourceConsumer, error) { - serviceSummaries, err := c.ServiceLogic.ListServices() + resourceConsumers := []resource.ResourceConsumer{} + services, err := c.ServiceLogic.GetEnvironmentServices(environmentID) if err != nil { return nil, err } - resourceConsumers := []resource.ResourceConsumer{} - for _, summary := range serviceSummaries { - if summary.EnvironmentID == environmentID { - service, err := c.ServiceLogic.GetService(summary.ServiceID) - if err != nil { - return nil, err - } - - deployIDCopies := map[string]int{} - for _, deployment := range service.Deployments { - // deployment.RunningCount is the number of containers already running on an instance - // deployment.PendingCount is the number of containers that are alraedy on an instance, but are being pulled - // we only care about containers that are not on instances yet - - if numPending := deployment.DesiredCount - (deployment.RunningCount + deployment.PendingCount); numPending > 0 { - deployIDCopies[deployment.DeployID] = int(numPending) - } - } + for _, service := range services { + deployIDCopies := map[string]int{} + for _, deployment := range service.Deployments { + // deployment.RunningCount is the number of containers already running on an instance + // deployment.PendingCount is the number of containers that are alraedy on an instance, but are being pulled + // we only care about containers that are not on instances yet - if len(deployIDCopies) == 0 { - continue + if numPending := deployment.DesiredCount - (deployment.RunningCount + deployment.PendingCount); numPending > 0 { + deployIDCopies[deployment.DeployID] = int(numPending) } + } - // resource consumer ids are just used for debugging purposes - generateID := func(deployID, containerName string, copy int) string { - return fmt.Sprintf("Service: %s, Deploy: %s, Container: %s, Copy: %d", summary.ServiceID, deployID, containerName, copy) - } + if len(deployIDCopies) == 0 { + continue + } - serviceResourceConsumers, err := c.getResourcesHelper(deployIDCopies, generateID) - if err != nil { - return nil, err - } + // resource consumer ids are just used for debugging purposes + generateID := func(deployID, containerName string, copy int) string { + return fmt.Sprintf("Service: %s, Deploy: %s, Container: %s, Copy: %d", service.ServiceID, deployID, containerName, copy) + } - resourceConsumers = append(resourceConsumers, serviceResourceConsumers...) + serviceResourceConsumers, err := c.getResourcesHelper(deployIDCopies, generateID) + if err != nil { + return nil, err } + + resourceConsumers = append(resourceConsumers, serviceResourceConsumers...) } return resourceConsumers, nil } func (c *EnvironmentResourceGetter) getPendingTaskResourcesInECS(environmentID string) ([]resource.ResourceConsumer, error) { - taskSummaries, err := c.TaskLogic.ListTasks() + tasks, err := c.TaskLogic.GetEnvironmentTasks(environmentID) if err != nil { return nil, err } resourceConsumers := []resource.ResourceConsumer{} - for _, summary := range taskSummaries { - if summary.EnvironmentID == environmentID { - task, err := c.TaskLogic.GetTask(summary.TaskID) - if err != nil { - return nil, err - } - - if task.PendingCount == 0 { - continue - } - - deployIDCopies := map[string]int{ - task.DeployID: int(task.PendingCount), - } + for _, task := range tasks { + if task.PendingCount == 0 { + continue + } - // resource consumer ids are just used for debugging purposes - generateID := func(deployID, containerName string, copy int) string { - return fmt.Sprintf("Task: %s, Deploy: %s, Container: %s, Copy: %d", summary.TaskID, deployID, containerName, copy) - } + deployIDCopies := map[string]int{ + task.DeployID: int(task.PendingCount), + } - taskResourceConsumers, err := c.getResourcesHelper(deployIDCopies, generateID) - if err != nil { - return nil, err - } + // resource consumer ids are just used for debugging purposes + generateID := func(deployID, containerName string, copy int) string { + return fmt.Sprintf("Task: %s, Deploy: %s, Container: %s, Copy: %d", task.TaskID, deployID, containerName, copy) + } - resourceConsumers = append(resourceConsumers, taskResourceConsumers...) + taskResourceConsumers, err := c.getResourcesHelper(deployIDCopies, generateID) + if err != nil { + return nil, err } + + resourceConsumers = append(resourceConsumers, taskResourceConsumers...) } return resourceConsumers, nil @@ -153,7 +139,7 @@ func (c *EnvironmentResourceGetter) getPendingTaskResourcesInJobs(environmentID if req.EnvironmentID == environmentID { // note that this isn't exact if the job has started some, but not all of the tasks deployIDCopies := map[string]int{ - req.DeployID: int(req.Copies), + req.DeployID: 1, } // resource consumer ids are just used for debugging purposes diff --git a/api/logic/environment_resource_getter_test.go b/api/logic/environment_resource_getter_test.go index 2df69a8c1..b6b9ce141 100644 --- a/api/logic/environment_resource_getter_test.go +++ b/api/logic/environment_resource_getter_test.go @@ -109,7 +109,6 @@ func TestGetPendingTaskResourcesInJobs(t *testing.T) { TaskName: "t1", DeployID: "d1", EnvironmentID: "e1", - Copies: 2, }), }, { @@ -120,7 +119,6 @@ func TestGetPendingTaskResourcesInJobs(t *testing.T) { TaskName: "t2", DeployID: "d2", EnvironmentID: "e1", - Copies: 1, }), }, { @@ -155,52 +153,17 @@ func TestGetPendingTaskResourcesInJobs(t *testing.T) { t.Fatal(err) } - testutils.AssertEqual(t, len(resources), 4) + testutils.AssertEqual(t, len(resources), 3) - // job1, deploy1, container1, copy1 + // job1, deploy1, container1 testutils.AssertEqual(t, resources[0].Ports, []int{80, 22}) testutils.AssertEqual(t, resources[0].Memory, bytesize.MiB*500) - - // job1, deploy1, container1, copy2 - testutils.AssertEqual(t, resources[1].Ports, []int{80, 22}) - testutils.AssertEqual(t, resources[1].Memory, bytesize.MiB*500) - - // job2, deploy2, container1, copy1 - testutils.AssertEqual(t, resources[2].Ports, []int{80}) - testutils.AssertEqual(t, resources[2].Memory, bytesize.MiB*500) - - // job2, deploy2, container2, copy1 - testutils.AssertEqual(t, resources[3].Ports, []int{8000}) - testutils.AssertEqual(t, resources[3].Memory, bytesize.MiB*1000) } func TestGetPendingTaskResourcesInECS(t *testing.T) { crg, ctrl := newTestEnvironmentResourceGetter(t) defer ctrl.Finish() - taskSummaries := []*models.TaskSummary{ - { - TaskID: "t1", - EnvironmentID: "e1", - }, - { - TaskID: "t2", - EnvironmentID: "e1", - }, - { - TaskID: "t3", - EnvironmentID: "e1", - }, - { - TaskID: "t4", - EnvironmentID: "e4", - }, - } - - crg.TaskLogic.EXPECT(). - ListTasks(). - Return(taskSummaries, nil) - tasks := []*models.Task{ { TaskID: "t1", @@ -223,16 +186,8 @@ func TestGetPendingTaskResourcesInECS(t *testing.T) { } crg.TaskLogic.EXPECT(). - GetTask("t1"). - Return(tasks[0], nil) - - crg.TaskLogic.EXPECT(). - GetTask("t2"). - Return(tasks[1], nil) - - crg.TaskLogic.EXPECT(). - GetTask("t3"). - Return(tasks[2], nil) + GetEnvironmentTasks("e1"). + Return(tasks, nil) crg.DeployLogic.EXPECT(). GetDeploy("d1"). @@ -270,29 +225,6 @@ func TestGetPendingServiceResources(t *testing.T) { crg, ctrl := newTestEnvironmentResourceGetter(t) defer ctrl.Finish() - serviceSummaries := []*models.ServiceSummary{ - { - ServiceID: "s1", - EnvironmentID: "e1", - }, - { - ServiceID: "s2", - EnvironmentID: "e1", - }, - { - ServiceID: "s3", - EnvironmentID: "e1", - }, - { - ServiceID: "s4", - EnvironmentID: "e4", - }, - } - - crg.ServiceLogic.EXPECT(). - ListServices(). - Return(serviceSummaries, nil) - services := []*models.Service{ { ServiceID: "s1", @@ -330,16 +262,8 @@ func TestGetPendingServiceResources(t *testing.T) { } crg.ServiceLogic.EXPECT(). - GetService("s1"). - Return(services[0], nil) - - crg.ServiceLogic.EXPECT(). - GetService("s2"). - Return(services[1], nil) - - crg.ServiceLogic.EXPECT(). - GetService("s3"). - Return(services[2], nil) + GetEnvironmentServices("e1"). + Return(services, nil) crg.DeployLogic.EXPECT(). GetDeploy("d1"). diff --git a/api/logic/job_logic.go b/api/logic/job_logic.go index ce5b2ca73..ebea7acb5 100644 --- a/api/logic/job_logic.go +++ b/api/logic/job_logic.go @@ -95,14 +95,14 @@ func (this *L0JobLogic) CreateJob(jobType types.JobType, request interface{}) (* return nil, err } - task, err := this.createJobTask(jobID, deploy.DeployID) + taskID, err := this.createJobTask(jobID, deploy.DeployID) if err != nil { return nil, err } job := &models.Job{ JobID: jobID, - TaskID: task.TaskID, + TaskID: taskID, JobStatus: int64(types.Pending), JobType: int64(jobType), Request: reqStr, @@ -113,7 +113,7 @@ func (this *L0JobLogic) CreateJob(jobType types.JobType, request interface{}) (* return nil, err } - if err := this.TagStore.Insert(models.Tag{EntityID: jobID, EntityType: "job", Key: "task_id", Value: task.TaskID}); err != nil { + if err := this.TagStore.Insert(models.Tag{EntityID: jobID, EntityType: "job", Key: "task_id", Value: taskID}); err != nil { return nil, err } @@ -129,20 +129,19 @@ func (this *L0JobLogic) CreateJob(jobType types.JobType, request interface{}) (* return job, nil } -func (this *L0JobLogic) createJobTask(jobID, deployID string) (*models.Task, error) { +func (this *L0JobLogic) createJobTask(jobID, deployID string) (string, error) { taskRequest := models.CreateTaskRequest{ DeployID: deployID, EnvironmentID: config.API_ENVIRONMENT_ID, - Copies: 1, TaskName: jobID, } - task, err := this.TaskLogic.CreateTask(taskRequest) + taskID, err := this.TaskLogic.CreateTask(taskRequest) if err != nil { - return nil, err + return "", err } - return task, nil + return taskID, nil } func (this *L0JobLogic) createJobDeploy(jobID string) (*models.Deploy, error) { diff --git a/api/logic/job_logic_test.go b/api/logic/job_logic_test.go index 9a675714a..1de04e292 100644 --- a/api/logic/job_logic_test.go +++ b/api/logic/job_logic_test.go @@ -106,7 +106,7 @@ func TestCreateJob(t *testing.T) { taskLogic.EXPECT(). CreateTask(gomock.Any()). - Return(&models.Task{TaskID: "t1"}, nil) + Return("t1", nil) jobLogic := NewL0JobLogic(testLogic.Logic(), taskLogic, deployLogic) job, err := jobLogic.CreateJob(types.DeleteEnvironmentJob, "e1") diff --git a/api/logic/logic_test.go b/api/logic/logic_test.go index 34ae5e0ec..da7f5276f 100644 --- a/api/logic/logic_test.go +++ b/api/logic/logic_test.go @@ -18,6 +18,7 @@ func TestMain(m *testing.M) { config.SetTestConfig() log.SetLevel(log.FatalLevel) jobLogger.Level = log.FatalLevel + tagLogger.Level = log.FatalLevel retCode := m.Run() os.Exit(retCode) } diff --git a/api/logic/mock_logic/mock_deploy_logic.go b/api/logic/mock_logic/mock_deploy_logic.go index a0dd939da..f38e1cfb7 100644 --- a/api/logic/mock_logic/mock_deploy_logic.go +++ b/api/logic/mock_logic/mock_deploy_logic.go @@ -1,73 +1,86 @@ -// Automatically generated by MockGen. DO NOT EDIT! +// Code generated by MockGen. DO NOT EDIT. // Source: github.com/quintilesims/layer0/api/logic (interfaces: DeployLogic) +// Package mock_logic is a generated GoMock package. package mock_logic import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" models "github.com/quintilesims/layer0/common/models" ) -// Mock of DeployLogic interface +// MockDeployLogic is a mock of DeployLogic interface type MockDeployLogic struct { ctrl *gomock.Controller - recorder *_MockDeployLogicRecorder + recorder *MockDeployLogicMockRecorder } -// Recorder for MockDeployLogic (not exported) -type _MockDeployLogicRecorder struct { +// MockDeployLogicMockRecorder is the mock recorder for MockDeployLogic +type MockDeployLogicMockRecorder struct { mock *MockDeployLogic } +// NewMockDeployLogic creates a new mock instance func NewMockDeployLogic(ctrl *gomock.Controller) *MockDeployLogic { mock := &MockDeployLogic{ctrl: ctrl} - mock.recorder = &_MockDeployLogicRecorder{mock} + mock.recorder = &MockDeployLogicMockRecorder{mock} return mock } -func (_m *MockDeployLogic) EXPECT() *_MockDeployLogicRecorder { - return _m.recorder +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockDeployLogic) EXPECT() *MockDeployLogicMockRecorder { + return m.recorder } -func (_m *MockDeployLogic) CreateDeploy(_param0 models.CreateDeployRequest) (*models.Deploy, error) { - ret := _m.ctrl.Call(_m, "CreateDeploy", _param0) +// CreateDeploy mocks base method +func (m *MockDeployLogic) CreateDeploy(arg0 models.CreateDeployRequest) (*models.Deploy, error) { + ret := m.ctrl.Call(m, "CreateDeploy", arg0) ret0, _ := ret[0].(*models.Deploy) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockDeployLogicRecorder) CreateDeploy(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateDeploy", arg0) +// CreateDeploy indicates an expected call of CreateDeploy +func (mr *MockDeployLogicMockRecorder) CreateDeploy(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateDeploy", reflect.TypeOf((*MockDeployLogic)(nil).CreateDeploy), arg0) } -func (_m *MockDeployLogic) DeleteDeploy(_param0 string) error { - ret := _m.ctrl.Call(_m, "DeleteDeploy", _param0) +// DeleteDeploy mocks base method +func (m *MockDeployLogic) DeleteDeploy(arg0 string) error { + ret := m.ctrl.Call(m, "DeleteDeploy", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockDeployLogicRecorder) DeleteDeploy(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteDeploy", arg0) +// DeleteDeploy indicates an expected call of DeleteDeploy +func (mr *MockDeployLogicMockRecorder) DeleteDeploy(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteDeploy", reflect.TypeOf((*MockDeployLogic)(nil).DeleteDeploy), arg0) } -func (_m *MockDeployLogic) GetDeploy(_param0 string) (*models.Deploy, error) { - ret := _m.ctrl.Call(_m, "GetDeploy", _param0) +// GetDeploy mocks base method +func (m *MockDeployLogic) GetDeploy(arg0 string) (*models.Deploy, error) { + ret := m.ctrl.Call(m, "GetDeploy", arg0) ret0, _ := ret[0].(*models.Deploy) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockDeployLogicRecorder) GetDeploy(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetDeploy", arg0) +// GetDeploy indicates an expected call of GetDeploy +func (mr *MockDeployLogicMockRecorder) GetDeploy(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDeploy", reflect.TypeOf((*MockDeployLogic)(nil).GetDeploy), arg0) } -func (_m *MockDeployLogic) ListDeploys() ([]*models.DeploySummary, error) { - ret := _m.ctrl.Call(_m, "ListDeploys") +// ListDeploys mocks base method +func (m *MockDeployLogic) ListDeploys() ([]*models.DeploySummary, error) { + ret := m.ctrl.Call(m, "ListDeploys") ret0, _ := ret[0].([]*models.DeploySummary) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockDeployLogicRecorder) ListDeploys() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListDeploys") +// ListDeploys indicates an expected call of ListDeploys +func (mr *MockDeployLogicMockRecorder) ListDeploys() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListDeploys", reflect.TypeOf((*MockDeployLogic)(nil).ListDeploys)) } diff --git a/api/logic/mock_logic/mock_environment_logic.go b/api/logic/mock_logic/mock_environment_logic.go index ccd1fe9e7..743d0214f 100644 --- a/api/logic/mock_logic/mock_environment_logic.go +++ b/api/logic/mock_logic/mock_environment_logic.go @@ -1,115 +1,136 @@ -// Automatically generated by MockGen. DO NOT EDIT! +// Code generated by MockGen. DO NOT EDIT. // Source: github.com/quintilesims/layer0/api/logic (interfaces: EnvironmentLogic) +// Package mock_logic is a generated GoMock package. package mock_logic import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" models "github.com/quintilesims/layer0/common/models" ) -// Mock of EnvironmentLogic interface +// MockEnvironmentLogic is a mock of EnvironmentLogic interface type MockEnvironmentLogic struct { ctrl *gomock.Controller - recorder *_MockEnvironmentLogicRecorder + recorder *MockEnvironmentLogicMockRecorder } -// Recorder for MockEnvironmentLogic (not exported) -type _MockEnvironmentLogicRecorder struct { +// MockEnvironmentLogicMockRecorder is the mock recorder for MockEnvironmentLogic +type MockEnvironmentLogicMockRecorder struct { mock *MockEnvironmentLogic } +// NewMockEnvironmentLogic creates a new mock instance func NewMockEnvironmentLogic(ctrl *gomock.Controller) *MockEnvironmentLogic { mock := &MockEnvironmentLogic{ctrl: ctrl} - mock.recorder = &_MockEnvironmentLogicRecorder{mock} + mock.recorder = &MockEnvironmentLogicMockRecorder{mock} return mock } -func (_m *MockEnvironmentLogic) EXPECT() *_MockEnvironmentLogicRecorder { - return _m.recorder +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockEnvironmentLogic) EXPECT() *MockEnvironmentLogicMockRecorder { + return m.recorder } -func (_m *MockEnvironmentLogic) CanCreateEnvironment(_param0 models.CreateEnvironmentRequest) (bool, error) { - ret := _m.ctrl.Call(_m, "CanCreateEnvironment", _param0) +// CanCreateEnvironment mocks base method +func (m *MockEnvironmentLogic) CanCreateEnvironment(arg0 models.CreateEnvironmentRequest) (bool, error) { + ret := m.ctrl.Call(m, "CanCreateEnvironment", arg0) ret0, _ := ret[0].(bool) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockEnvironmentLogicRecorder) CanCreateEnvironment(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CanCreateEnvironment", arg0) +// CanCreateEnvironment indicates an expected call of CanCreateEnvironment +func (mr *MockEnvironmentLogicMockRecorder) CanCreateEnvironment(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CanCreateEnvironment", reflect.TypeOf((*MockEnvironmentLogic)(nil).CanCreateEnvironment), arg0) } -func (_m *MockEnvironmentLogic) CreateEnvironment(_param0 models.CreateEnvironmentRequest) (*models.Environment, error) { - ret := _m.ctrl.Call(_m, "CreateEnvironment", _param0) +// CreateEnvironment mocks base method +func (m *MockEnvironmentLogic) CreateEnvironment(arg0 models.CreateEnvironmentRequest) (*models.Environment, error) { + ret := m.ctrl.Call(m, "CreateEnvironment", arg0) ret0, _ := ret[0].(*models.Environment) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockEnvironmentLogicRecorder) CreateEnvironment(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateEnvironment", arg0) +// CreateEnvironment indicates an expected call of CreateEnvironment +func (mr *MockEnvironmentLogicMockRecorder) CreateEnvironment(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateEnvironment", reflect.TypeOf((*MockEnvironmentLogic)(nil).CreateEnvironment), arg0) } -func (_m *MockEnvironmentLogic) CreateEnvironmentLink(_param0 string, _param1 string) error { - ret := _m.ctrl.Call(_m, "CreateEnvironmentLink", _param0, _param1) +// CreateEnvironmentLink mocks base method +func (m *MockEnvironmentLogic) CreateEnvironmentLink(arg0, arg1 string) error { + ret := m.ctrl.Call(m, "CreateEnvironmentLink", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockEnvironmentLogicRecorder) CreateEnvironmentLink(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateEnvironmentLink", arg0, arg1) +// CreateEnvironmentLink indicates an expected call of CreateEnvironmentLink +func (mr *MockEnvironmentLogicMockRecorder) CreateEnvironmentLink(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateEnvironmentLink", reflect.TypeOf((*MockEnvironmentLogic)(nil).CreateEnvironmentLink), arg0, arg1) } -func (_m *MockEnvironmentLogic) DeleteEnvironment(_param0 string) error { - ret := _m.ctrl.Call(_m, "DeleteEnvironment", _param0) +// DeleteEnvironment mocks base method +func (m *MockEnvironmentLogic) DeleteEnvironment(arg0 string) error { + ret := m.ctrl.Call(m, "DeleteEnvironment", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockEnvironmentLogicRecorder) DeleteEnvironment(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteEnvironment", arg0) +// DeleteEnvironment indicates an expected call of DeleteEnvironment +func (mr *MockEnvironmentLogicMockRecorder) DeleteEnvironment(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteEnvironment", reflect.TypeOf((*MockEnvironmentLogic)(nil).DeleteEnvironment), arg0) } -func (_m *MockEnvironmentLogic) DeleteEnvironmentLink(_param0 string, _param1 string) error { - ret := _m.ctrl.Call(_m, "DeleteEnvironmentLink", _param0, _param1) +// DeleteEnvironmentLink mocks base method +func (m *MockEnvironmentLogic) DeleteEnvironmentLink(arg0, arg1 string) error { + ret := m.ctrl.Call(m, "DeleteEnvironmentLink", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockEnvironmentLogicRecorder) DeleteEnvironmentLink(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteEnvironmentLink", arg0, arg1) +// DeleteEnvironmentLink indicates an expected call of DeleteEnvironmentLink +func (mr *MockEnvironmentLogicMockRecorder) DeleteEnvironmentLink(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteEnvironmentLink", reflect.TypeOf((*MockEnvironmentLogic)(nil).DeleteEnvironmentLink), arg0, arg1) } -func (_m *MockEnvironmentLogic) GetEnvironment(_param0 string) (*models.Environment, error) { - ret := _m.ctrl.Call(_m, "GetEnvironment", _param0) +// GetEnvironment mocks base method +func (m *MockEnvironmentLogic) GetEnvironment(arg0 string) (*models.Environment, error) { + ret := m.ctrl.Call(m, "GetEnvironment", arg0) ret0, _ := ret[0].(*models.Environment) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockEnvironmentLogicRecorder) GetEnvironment(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetEnvironment", arg0) +// GetEnvironment indicates an expected call of GetEnvironment +func (mr *MockEnvironmentLogicMockRecorder) GetEnvironment(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEnvironment", reflect.TypeOf((*MockEnvironmentLogic)(nil).GetEnvironment), arg0) } -func (_m *MockEnvironmentLogic) ListEnvironments() ([]*models.EnvironmentSummary, error) { - ret := _m.ctrl.Call(_m, "ListEnvironments") - ret0, _ := ret[0].([]*models.EnvironmentSummary) +// ListEnvironments mocks base method +func (m *MockEnvironmentLogic) ListEnvironments() ([]models.EnvironmentSummary, error) { + ret := m.ctrl.Call(m, "ListEnvironments") + ret0, _ := ret[0].([]models.EnvironmentSummary) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockEnvironmentLogicRecorder) ListEnvironments() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListEnvironments") +// ListEnvironments indicates an expected call of ListEnvironments +func (mr *MockEnvironmentLogicMockRecorder) ListEnvironments() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListEnvironments", reflect.TypeOf((*MockEnvironmentLogic)(nil).ListEnvironments)) } -func (_m *MockEnvironmentLogic) UpdateEnvironment(_param0 string, _param1 int) (*models.Environment, error) { - ret := _m.ctrl.Call(_m, "UpdateEnvironment", _param0, _param1) +// UpdateEnvironment mocks base method +func (m *MockEnvironmentLogic) UpdateEnvironment(arg0 string, arg1 int) (*models.Environment, error) { + ret := m.ctrl.Call(m, "UpdateEnvironment", arg0, arg1) ret0, _ := ret[0].(*models.Environment) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockEnvironmentLogicRecorder) UpdateEnvironment(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "UpdateEnvironment", arg0, arg1) +// UpdateEnvironment indicates an expected call of UpdateEnvironment +func (mr *MockEnvironmentLogicMockRecorder) UpdateEnvironment(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateEnvironment", reflect.TypeOf((*MockEnvironmentLogic)(nil).UpdateEnvironment), arg0, arg1) } diff --git a/api/logic/mock_logic/mock_job_logic.go b/api/logic/mock_logic/mock_job_logic.go index 637dc11d9..bf9e097f9 100644 --- a/api/logic/mock_logic/mock_job_logic.go +++ b/api/logic/mock_logic/mock_job_logic.go @@ -1,74 +1,87 @@ -// Automatically generated by MockGen. DO NOT EDIT! +// Code generated by MockGen. DO NOT EDIT. // Source: github.com/quintilesims/layer0/api/logic (interfaces: JobLogic) +// Package mock_logic is a generated GoMock package. package mock_logic import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" models "github.com/quintilesims/layer0/common/models" types "github.com/quintilesims/layer0/common/types" ) -// Mock of JobLogic interface +// MockJobLogic is a mock of JobLogic interface type MockJobLogic struct { ctrl *gomock.Controller - recorder *_MockJobLogicRecorder + recorder *MockJobLogicMockRecorder } -// Recorder for MockJobLogic (not exported) -type _MockJobLogicRecorder struct { +// MockJobLogicMockRecorder is the mock recorder for MockJobLogic +type MockJobLogicMockRecorder struct { mock *MockJobLogic } +// NewMockJobLogic creates a new mock instance func NewMockJobLogic(ctrl *gomock.Controller) *MockJobLogic { mock := &MockJobLogic{ctrl: ctrl} - mock.recorder = &_MockJobLogicRecorder{mock} + mock.recorder = &MockJobLogicMockRecorder{mock} return mock } -func (_m *MockJobLogic) EXPECT() *_MockJobLogicRecorder { - return _m.recorder +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockJobLogic) EXPECT() *MockJobLogicMockRecorder { + return m.recorder } -func (_m *MockJobLogic) CreateJob(_param0 types.JobType, _param1 interface{}) (*models.Job, error) { - ret := _m.ctrl.Call(_m, "CreateJob", _param0, _param1) +// CreateJob mocks base method +func (m *MockJobLogic) CreateJob(arg0 types.JobType, arg1 interface{}) (*models.Job, error) { + ret := m.ctrl.Call(m, "CreateJob", arg0, arg1) ret0, _ := ret[0].(*models.Job) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockJobLogicRecorder) CreateJob(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateJob", arg0, arg1) +// CreateJob indicates an expected call of CreateJob +func (mr *MockJobLogicMockRecorder) CreateJob(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateJob", reflect.TypeOf((*MockJobLogic)(nil).CreateJob), arg0, arg1) } -func (_m *MockJobLogic) Delete(_param0 string) error { - ret := _m.ctrl.Call(_m, "Delete", _param0) +// Delete mocks base method +func (m *MockJobLogic) Delete(arg0 string) error { + ret := m.ctrl.Call(m, "Delete", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockJobLogicRecorder) Delete(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "Delete", arg0) +// Delete indicates an expected call of Delete +func (mr *MockJobLogicMockRecorder) Delete(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockJobLogic)(nil).Delete), arg0) } -func (_m *MockJobLogic) GetJob(_param0 string) (*models.Job, error) { - ret := _m.ctrl.Call(_m, "GetJob", _param0) +// GetJob mocks base method +func (m *MockJobLogic) GetJob(arg0 string) (*models.Job, error) { + ret := m.ctrl.Call(m, "GetJob", arg0) ret0, _ := ret[0].(*models.Job) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockJobLogicRecorder) GetJob(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetJob", arg0) +// GetJob indicates an expected call of GetJob +func (mr *MockJobLogicMockRecorder) GetJob(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetJob", reflect.TypeOf((*MockJobLogic)(nil).GetJob), arg0) } -func (_m *MockJobLogic) ListJobs() ([]*models.Job, error) { - ret := _m.ctrl.Call(_m, "ListJobs") +// ListJobs mocks base method +func (m *MockJobLogic) ListJobs() ([]*models.Job, error) { + ret := m.ctrl.Call(m, "ListJobs") ret0, _ := ret[0].([]*models.Job) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockJobLogicRecorder) ListJobs() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListJobs") +// ListJobs indicates an expected call of ListJobs +func (mr *MockJobLogicMockRecorder) ListJobs() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListJobs", reflect.TypeOf((*MockJobLogic)(nil).ListJobs)) } diff --git a/api/logic/mock_logic/mock_load_balancer_logic.go b/api/logic/mock_logic/mock_load_balancer_logic.go index 3e9cad7e8..9161c72d6 100644 --- a/api/logic/mock_logic/mock_load_balancer_logic.go +++ b/api/logic/mock_logic/mock_load_balancer_logic.go @@ -1,95 +1,112 @@ -// Automatically generated by MockGen. DO NOT EDIT! +// Code generated by MockGen. DO NOT EDIT. // Source: github.com/quintilesims/layer0/api/logic (interfaces: LoadBalancerLogic) +// Package mock_logic is a generated GoMock package. package mock_logic import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" models "github.com/quintilesims/layer0/common/models" ) -// Mock of LoadBalancerLogic interface +// MockLoadBalancerLogic is a mock of LoadBalancerLogic interface type MockLoadBalancerLogic struct { ctrl *gomock.Controller - recorder *_MockLoadBalancerLogicRecorder + recorder *MockLoadBalancerLogicMockRecorder } -// Recorder for MockLoadBalancerLogic (not exported) -type _MockLoadBalancerLogicRecorder struct { +// MockLoadBalancerLogicMockRecorder is the mock recorder for MockLoadBalancerLogic +type MockLoadBalancerLogicMockRecorder struct { mock *MockLoadBalancerLogic } +// NewMockLoadBalancerLogic creates a new mock instance func NewMockLoadBalancerLogic(ctrl *gomock.Controller) *MockLoadBalancerLogic { mock := &MockLoadBalancerLogic{ctrl: ctrl} - mock.recorder = &_MockLoadBalancerLogicRecorder{mock} + mock.recorder = &MockLoadBalancerLogicMockRecorder{mock} return mock } -func (_m *MockLoadBalancerLogic) EXPECT() *_MockLoadBalancerLogicRecorder { - return _m.recorder +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockLoadBalancerLogic) EXPECT() *MockLoadBalancerLogicMockRecorder { + return m.recorder } -func (_m *MockLoadBalancerLogic) CreateLoadBalancer(_param0 models.CreateLoadBalancerRequest) (*models.LoadBalancer, error) { - ret := _m.ctrl.Call(_m, "CreateLoadBalancer", _param0) +// CreateLoadBalancer mocks base method +func (m *MockLoadBalancerLogic) CreateLoadBalancer(arg0 models.CreateLoadBalancerRequest) (*models.LoadBalancer, error) { + ret := m.ctrl.Call(m, "CreateLoadBalancer", arg0) ret0, _ := ret[0].(*models.LoadBalancer) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockLoadBalancerLogicRecorder) CreateLoadBalancer(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateLoadBalancer", arg0) +// CreateLoadBalancer indicates an expected call of CreateLoadBalancer +func (mr *MockLoadBalancerLogicMockRecorder) CreateLoadBalancer(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateLoadBalancer", reflect.TypeOf((*MockLoadBalancerLogic)(nil).CreateLoadBalancer), arg0) } -func (_m *MockLoadBalancerLogic) DeleteLoadBalancer(_param0 string) error { - ret := _m.ctrl.Call(_m, "DeleteLoadBalancer", _param0) +// DeleteLoadBalancer mocks base method +func (m *MockLoadBalancerLogic) DeleteLoadBalancer(arg0 string) error { + ret := m.ctrl.Call(m, "DeleteLoadBalancer", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockLoadBalancerLogicRecorder) DeleteLoadBalancer(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteLoadBalancer", arg0) +// DeleteLoadBalancer indicates an expected call of DeleteLoadBalancer +func (mr *MockLoadBalancerLogicMockRecorder) DeleteLoadBalancer(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteLoadBalancer", reflect.TypeOf((*MockLoadBalancerLogic)(nil).DeleteLoadBalancer), arg0) } -func (_m *MockLoadBalancerLogic) GetLoadBalancer(_param0 string) (*models.LoadBalancer, error) { - ret := _m.ctrl.Call(_m, "GetLoadBalancer", _param0) +// GetLoadBalancer mocks base method +func (m *MockLoadBalancerLogic) GetLoadBalancer(arg0 string) (*models.LoadBalancer, error) { + ret := m.ctrl.Call(m, "GetLoadBalancer", arg0) ret0, _ := ret[0].(*models.LoadBalancer) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockLoadBalancerLogicRecorder) GetLoadBalancer(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetLoadBalancer", arg0) +// GetLoadBalancer indicates an expected call of GetLoadBalancer +func (mr *MockLoadBalancerLogicMockRecorder) GetLoadBalancer(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLoadBalancer", reflect.TypeOf((*MockLoadBalancerLogic)(nil).GetLoadBalancer), arg0) } -func (_m *MockLoadBalancerLogic) ListLoadBalancers() ([]*models.LoadBalancerSummary, error) { - ret := _m.ctrl.Call(_m, "ListLoadBalancers") +// ListLoadBalancers mocks base method +func (m *MockLoadBalancerLogic) ListLoadBalancers() ([]*models.LoadBalancerSummary, error) { + ret := m.ctrl.Call(m, "ListLoadBalancers") ret0, _ := ret[0].([]*models.LoadBalancerSummary) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockLoadBalancerLogicRecorder) ListLoadBalancers() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListLoadBalancers") +// ListLoadBalancers indicates an expected call of ListLoadBalancers +func (mr *MockLoadBalancerLogicMockRecorder) ListLoadBalancers() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListLoadBalancers", reflect.TypeOf((*MockLoadBalancerLogic)(nil).ListLoadBalancers)) } -func (_m *MockLoadBalancerLogic) UpdateLoadBalancerHealthCheck(_param0 string, _param1 models.HealthCheck) (*models.LoadBalancer, error) { - ret := _m.ctrl.Call(_m, "UpdateLoadBalancerHealthCheck", _param0, _param1) +// UpdateLoadBalancerHealthCheck mocks base method +func (m *MockLoadBalancerLogic) UpdateLoadBalancerHealthCheck(arg0 string, arg1 models.HealthCheck) (*models.LoadBalancer, error) { + ret := m.ctrl.Call(m, "UpdateLoadBalancerHealthCheck", arg0, arg1) ret0, _ := ret[0].(*models.LoadBalancer) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockLoadBalancerLogicRecorder) UpdateLoadBalancerHealthCheck(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "UpdateLoadBalancerHealthCheck", arg0, arg1) +// UpdateLoadBalancerHealthCheck indicates an expected call of UpdateLoadBalancerHealthCheck +func (mr *MockLoadBalancerLogicMockRecorder) UpdateLoadBalancerHealthCheck(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateLoadBalancerHealthCheck", reflect.TypeOf((*MockLoadBalancerLogic)(nil).UpdateLoadBalancerHealthCheck), arg0, arg1) } -func (_m *MockLoadBalancerLogic) UpdateLoadBalancerPorts(_param0 string, _param1 []models.Port) (*models.LoadBalancer, error) { - ret := _m.ctrl.Call(_m, "UpdateLoadBalancerPorts", _param0, _param1) +// UpdateLoadBalancerPorts mocks base method +func (m *MockLoadBalancerLogic) UpdateLoadBalancerPorts(arg0 string, arg1 []models.Port) (*models.LoadBalancer, error) { + ret := m.ctrl.Call(m, "UpdateLoadBalancerPorts", arg0, arg1) ret0, _ := ret[0].(*models.LoadBalancer) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockLoadBalancerLogicRecorder) UpdateLoadBalancerPorts(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "UpdateLoadBalancerPorts", arg0, arg1) +// UpdateLoadBalancerPorts indicates an expected call of UpdateLoadBalancerPorts +func (mr *MockLoadBalancerLogicMockRecorder) UpdateLoadBalancerPorts(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateLoadBalancerPorts", reflect.TypeOf((*MockLoadBalancerLogic)(nil).UpdateLoadBalancerPorts), arg0, arg1) } diff --git a/api/logic/mock_logic/mock_service_logic.go b/api/logic/mock_logic/mock_service_logic.go index 64a22a347..7748ca8c7 100644 --- a/api/logic/mock_logic/mock_service_logic.go +++ b/api/logic/mock_logic/mock_service_logic.go @@ -1,106 +1,138 @@ -// Automatically generated by MockGen. DO NOT EDIT! +// Code generated by MockGen. DO NOT EDIT. // Source: github.com/quintilesims/layer0/api/logic (interfaces: ServiceLogic) +// Package mock_logic is a generated GoMock package. package mock_logic import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" models "github.com/quintilesims/layer0/common/models" ) -// Mock of ServiceLogic interface +// MockServiceLogic is a mock of ServiceLogic interface type MockServiceLogic struct { ctrl *gomock.Controller - recorder *_MockServiceLogicRecorder + recorder *MockServiceLogicMockRecorder } -// Recorder for MockServiceLogic (not exported) -type _MockServiceLogicRecorder struct { +// MockServiceLogicMockRecorder is the mock recorder for MockServiceLogic +type MockServiceLogicMockRecorder struct { mock *MockServiceLogic } +// NewMockServiceLogic creates a new mock instance func NewMockServiceLogic(ctrl *gomock.Controller) *MockServiceLogic { mock := &MockServiceLogic{ctrl: ctrl} - mock.recorder = &_MockServiceLogicRecorder{mock} + mock.recorder = &MockServiceLogicMockRecorder{mock} return mock } -func (_m *MockServiceLogic) EXPECT() *_MockServiceLogicRecorder { - return _m.recorder +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockServiceLogic) EXPECT() *MockServiceLogicMockRecorder { + return m.recorder } -func (_m *MockServiceLogic) CreateService(_param0 models.CreateServiceRequest) (*models.Service, error) { - ret := _m.ctrl.Call(_m, "CreateService", _param0) +// CreateService mocks base method +func (m *MockServiceLogic) CreateService(arg0 models.CreateServiceRequest) (*models.Service, error) { + ret := m.ctrl.Call(m, "CreateService", arg0) ret0, _ := ret[0].(*models.Service) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockServiceLogicRecorder) CreateService(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateService", arg0) +// CreateService indicates an expected call of CreateService +func (mr *MockServiceLogicMockRecorder) CreateService(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateService", reflect.TypeOf((*MockServiceLogic)(nil).CreateService), arg0) } -func (_m *MockServiceLogic) DeleteService(_param0 string) error { - ret := _m.ctrl.Call(_m, "DeleteService", _param0) +// DeleteService mocks base method +func (m *MockServiceLogic) DeleteService(arg0 string) error { + ret := m.ctrl.Call(m, "DeleteService", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockServiceLogicRecorder) DeleteService(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteService", arg0) +// DeleteService indicates an expected call of DeleteService +func (mr *MockServiceLogicMockRecorder) DeleteService(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteService", reflect.TypeOf((*MockServiceLogic)(nil).DeleteService), arg0) +} + +// GetEnvironmentServices mocks base method +func (m *MockServiceLogic) GetEnvironmentServices(arg0 string) ([]*models.Service, error) { + ret := m.ctrl.Call(m, "GetEnvironmentServices", arg0) + ret0, _ := ret[0].([]*models.Service) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetEnvironmentServices indicates an expected call of GetEnvironmentServices +func (mr *MockServiceLogicMockRecorder) GetEnvironmentServices(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEnvironmentServices", reflect.TypeOf((*MockServiceLogic)(nil).GetEnvironmentServices), arg0) } -func (_m *MockServiceLogic) GetService(_param0 string) (*models.Service, error) { - ret := _m.ctrl.Call(_m, "GetService", _param0) +// GetService mocks base method +func (m *MockServiceLogic) GetService(arg0 string) (*models.Service, error) { + ret := m.ctrl.Call(m, "GetService", arg0) ret0, _ := ret[0].(*models.Service) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockServiceLogicRecorder) GetService(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetService", arg0) +// GetService indicates an expected call of GetService +func (mr *MockServiceLogicMockRecorder) GetService(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetService", reflect.TypeOf((*MockServiceLogic)(nil).GetService), arg0) } -func (_m *MockServiceLogic) GetServiceLogs(_param0 string, _param1 string, _param2 string, _param3 int) ([]*models.LogFile, error) { - ret := _m.ctrl.Call(_m, "GetServiceLogs", _param0, _param1, _param2, _param3) +// GetServiceLogs mocks base method +func (m *MockServiceLogic) GetServiceLogs(arg0, arg1, arg2 string, arg3 int) ([]*models.LogFile, error) { + ret := m.ctrl.Call(m, "GetServiceLogs", arg0, arg1, arg2, arg3) ret0, _ := ret[0].([]*models.LogFile) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockServiceLogicRecorder) GetServiceLogs(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetServiceLogs", arg0, arg1, arg2, arg3) +// GetServiceLogs indicates an expected call of GetServiceLogs +func (mr *MockServiceLogicMockRecorder) GetServiceLogs(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetServiceLogs", reflect.TypeOf((*MockServiceLogic)(nil).GetServiceLogs), arg0, arg1, arg2, arg3) } -func (_m *MockServiceLogic) ListServices() ([]*models.ServiceSummary, error) { - ret := _m.ctrl.Call(_m, "ListServices") - ret0, _ := ret[0].([]*models.ServiceSummary) +// ListServices mocks base method +func (m *MockServiceLogic) ListServices() ([]models.ServiceSummary, error) { + ret := m.ctrl.Call(m, "ListServices") + ret0, _ := ret[0].([]models.ServiceSummary) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockServiceLogicRecorder) ListServices() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListServices") +// ListServices indicates an expected call of ListServices +func (mr *MockServiceLogicMockRecorder) ListServices() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListServices", reflect.TypeOf((*MockServiceLogic)(nil).ListServices)) } -func (_m *MockServiceLogic) ScaleService(_param0 string, _param1 int) (*models.Service, error) { - ret := _m.ctrl.Call(_m, "ScaleService", _param0, _param1) +// ScaleService mocks base method +func (m *MockServiceLogic) ScaleService(arg0 string, arg1 int) (*models.Service, error) { + ret := m.ctrl.Call(m, "ScaleService", arg0, arg1) ret0, _ := ret[0].(*models.Service) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockServiceLogicRecorder) ScaleService(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ScaleService", arg0, arg1) +// ScaleService indicates an expected call of ScaleService +func (mr *MockServiceLogicMockRecorder) ScaleService(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ScaleService", reflect.TypeOf((*MockServiceLogic)(nil).ScaleService), arg0, arg1) } -func (_m *MockServiceLogic) UpdateService(_param0 string, _param1 models.UpdateServiceRequest) (*models.Service, error) { - ret := _m.ctrl.Call(_m, "UpdateService", _param0, _param1) +// UpdateService mocks base method +func (m *MockServiceLogic) UpdateService(arg0 string, arg1 models.UpdateServiceRequest) (*models.Service, error) { + ret := m.ctrl.Call(m, "UpdateService", arg0, arg1) ret0, _ := ret[0].(*models.Service) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockServiceLogicRecorder) UpdateService(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "UpdateService", arg0, arg1) +// UpdateService indicates an expected call of UpdateService +func (mr *MockServiceLogicMockRecorder) UpdateService(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateService", reflect.TypeOf((*MockServiceLogic)(nil).UpdateService), arg0, arg1) } diff --git a/api/logic/mock_logic/mock_task_logic.go b/api/logic/mock_logic/mock_task_logic.go index 57b9612e8..f200fa9d5 100644 --- a/api/logic/mock_logic/mock_task_logic.go +++ b/api/logic/mock_logic/mock_task_logic.go @@ -1,84 +1,112 @@ -// Automatically generated by MockGen. DO NOT EDIT! +// Code generated by MockGen. DO NOT EDIT. // Source: github.com/quintilesims/layer0/api/logic (interfaces: TaskLogic) +// Package mock_logic is a generated GoMock package. package mock_logic import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" models "github.com/quintilesims/layer0/common/models" ) -// Mock of TaskLogic interface +// MockTaskLogic is a mock of TaskLogic interface type MockTaskLogic struct { ctrl *gomock.Controller - recorder *_MockTaskLogicRecorder + recorder *MockTaskLogicMockRecorder } -// Recorder for MockTaskLogic (not exported) -type _MockTaskLogicRecorder struct { +// MockTaskLogicMockRecorder is the mock recorder for MockTaskLogic +type MockTaskLogicMockRecorder struct { mock *MockTaskLogic } +// NewMockTaskLogic creates a new mock instance func NewMockTaskLogic(ctrl *gomock.Controller) *MockTaskLogic { mock := &MockTaskLogic{ctrl: ctrl} - mock.recorder = &_MockTaskLogicRecorder{mock} + mock.recorder = &MockTaskLogicMockRecorder{mock} return mock } -func (_m *MockTaskLogic) EXPECT() *_MockTaskLogicRecorder { - return _m.recorder +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockTaskLogic) EXPECT() *MockTaskLogicMockRecorder { + return m.recorder } -func (_m *MockTaskLogic) CreateTask(_param0 models.CreateTaskRequest) (*models.Task, error) { - ret := _m.ctrl.Call(_m, "CreateTask", _param0) - ret0, _ := ret[0].(*models.Task) +// CreateTask mocks base method +func (m *MockTaskLogic) CreateTask(arg0 models.CreateTaskRequest) (string, error) { + ret := m.ctrl.Call(m, "CreateTask", arg0) + ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockTaskLogicRecorder) CreateTask(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateTask", arg0) +// CreateTask indicates an expected call of CreateTask +func (mr *MockTaskLogicMockRecorder) CreateTask(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateTask", reflect.TypeOf((*MockTaskLogic)(nil).CreateTask), arg0) } -func (_m *MockTaskLogic) DeleteTask(_param0 string) error { - ret := _m.ctrl.Call(_m, "DeleteTask", _param0) +// DeleteTask mocks base method +func (m *MockTaskLogic) DeleteTask(arg0 string) error { + ret := m.ctrl.Call(m, "DeleteTask", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockTaskLogicRecorder) DeleteTask(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteTask", arg0) +// DeleteTask indicates an expected call of DeleteTask +func (mr *MockTaskLogicMockRecorder) DeleteTask(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteTask", reflect.TypeOf((*MockTaskLogic)(nil).DeleteTask), arg0) +} + +// GetEnvironmentTasks mocks base method +func (m *MockTaskLogic) GetEnvironmentTasks(arg0 string) ([]*models.Task, error) { + ret := m.ctrl.Call(m, "GetEnvironmentTasks", arg0) + ret0, _ := ret[0].([]*models.Task) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetEnvironmentTasks indicates an expected call of GetEnvironmentTasks +func (mr *MockTaskLogicMockRecorder) GetEnvironmentTasks(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEnvironmentTasks", reflect.TypeOf((*MockTaskLogic)(nil).GetEnvironmentTasks), arg0) } -func (_m *MockTaskLogic) GetTask(_param0 string) (*models.Task, error) { - ret := _m.ctrl.Call(_m, "GetTask", _param0) +// GetTask mocks base method +func (m *MockTaskLogic) GetTask(arg0 string) (*models.Task, error) { + ret := m.ctrl.Call(m, "GetTask", arg0) ret0, _ := ret[0].(*models.Task) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockTaskLogicRecorder) GetTask(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetTask", arg0) +// GetTask indicates an expected call of GetTask +func (mr *MockTaskLogicMockRecorder) GetTask(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTask", reflect.TypeOf((*MockTaskLogic)(nil).GetTask), arg0) } -func (_m *MockTaskLogic) GetTaskLogs(_param0 string, _param1 string, _param2 string, _param3 int) ([]*models.LogFile, error) { - ret := _m.ctrl.Call(_m, "GetTaskLogs", _param0, _param1, _param2, _param3) +// GetTaskLogs mocks base method +func (m *MockTaskLogic) GetTaskLogs(arg0, arg1, arg2 string, arg3 int) ([]*models.LogFile, error) { + ret := m.ctrl.Call(m, "GetTaskLogs", arg0, arg1, arg2, arg3) ret0, _ := ret[0].([]*models.LogFile) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockTaskLogicRecorder) GetTaskLogs(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetTaskLogs", arg0, arg1, arg2, arg3) +// GetTaskLogs indicates an expected call of GetTaskLogs +func (mr *MockTaskLogicMockRecorder) GetTaskLogs(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTaskLogs", reflect.TypeOf((*MockTaskLogic)(nil).GetTaskLogs), arg0, arg1, arg2, arg3) } -func (_m *MockTaskLogic) ListTasks() ([]*models.TaskSummary, error) { - ret := _m.ctrl.Call(_m, "ListTasks") +// ListTasks mocks base method +func (m *MockTaskLogic) ListTasks() ([]*models.TaskSummary, error) { + ret := m.ctrl.Call(m, "ListTasks") ret0, _ := ret[0].([]*models.TaskSummary) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockTaskLogicRecorder) ListTasks() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListTasks") +// ListTasks indicates an expected call of ListTasks +func (mr *MockTaskLogicMockRecorder) ListTasks() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListTasks", reflect.TypeOf((*MockTaskLogic)(nil).ListTasks)) } diff --git a/api/logic/service_logic.go b/api/logic/service_logic.go index a6d66d27f..0bbe9b228 100644 --- a/api/logic/service_logic.go +++ b/api/logic/service_logic.go @@ -4,13 +4,15 @@ import ( "fmt" "time" + "github.com/quintilesims/layer0/api/backend/ecs/id" "github.com/quintilesims/layer0/common/errors" "github.com/quintilesims/layer0/common/models" ) type ServiceLogic interface { - ListServices() ([]*models.ServiceSummary, error) + ListServices() ([]models.ServiceSummary, error) GetService(serviceID string) (*models.Service, error) + GetEnvironmentServices(environmentID string) ([]*models.Service, error) CreateService(req models.CreateServiceRequest) (*models.Service, error) DeleteService(serviceID string) error UpdateService(serviceID string, req models.UpdateServiceRequest) (*models.Service, error) @@ -28,27 +30,13 @@ func NewL0ServiceLogic(logic Logic) *L0ServiceLogic { } } -func (this *L0ServiceLogic) ListServices() ([]*models.ServiceSummary, error) { - services, err := this.Backend.ListServices() +func (this *L0ServiceLogic) ListServices() ([]models.ServiceSummary, error) { + serviceIDs, err := this.Backend.ListServices() if err != nil { return nil, err } - summaries := make([]*models.ServiceSummary, len(services)) - for i, service := range services { - if err := this.populateModel(service); err != nil { - return nil, err - } - - summaries[i] = &models.ServiceSummary{ - ServiceID: service.ServiceID, - ServiceName: service.ServiceName, - EnvironmentID: service.EnvironmentID, - EnvironmentName: service.EnvironmentName, - } - } - - return summaries, nil + return this.makeServiceSummaryModels(serviceIDs) } func (this *L0ServiceLogic) GetService(serviceID string) (*models.Service, error) { @@ -69,6 +57,21 @@ func (this *L0ServiceLogic) GetService(serviceID string) (*models.Service, error return service, nil } +func (this *L0ServiceLogic) GetEnvironmentServices(environmentID string) ([]*models.Service, error) { + services, err := this.Backend.GetEnvironmentServices(environmentID) + if err != nil { + return nil, err + } + + for _, service := range services { + if err := this.populateModel(service); err != nil { + return nil, err + } + } + + return services, nil +} + func (this *L0ServiceLogic) DeleteService(serviceID string) error { environmentID, err := this.getEnvironmentID(serviceID) if err != nil { @@ -297,3 +300,36 @@ func (this *L0ServiceLogic) populateModel(model *models.Service) error { return nil } + +func (s *L0ServiceLogic) makeServiceSummaryModels(ecsServiceIDs []id.ECSServiceID) ([]models.ServiceSummary, error) { + serviceTags, err := s.TagStore.SelectByType("service") + if err != nil { + return nil, err + } + + models := make([]models.ServiceSummary, len(ecsServiceIDs)) + for i, ecsServiceID := range ecsServiceIDs { + serviceID := ecsServiceID.L0ServiceID() + models[i].ServiceID = serviceID + + if tag, ok := serviceTags.WithID(serviceID).WithKey("name").First(); ok { + models[i].ServiceName = tag.Value + } + + if tag, ok := serviceTags.WithID(serviceID).WithKey("environment_id").First(); ok { + environmentID := tag.Value + models[i].EnvironmentID = environmentID + + environmentTags, err := s.TagStore.SelectByTypeAndID("environment", environmentID) + if err != nil { + return nil, err + } + + if tag, ok := environmentTags.WithKey("name").First(); ok { + models[i].EnvironmentName = tag.Value + } + } + } + + return models, nil +} diff --git a/api/logic/service_logic_test.go b/api/logic/service_logic_test.go index 0ffbac47f..337433c69 100644 --- a/api/logic/service_logic_test.go +++ b/api/logic/service_logic_test.go @@ -4,8 +4,10 @@ import ( "testing" "github.com/golang/mock/gomock" + "github.com/quintilesims/layer0/api/backend/ecs/id" "github.com/quintilesims/layer0/common/models" "github.com/quintilesims/layer0/common/testutils" + "github.com/stretchr/testify/assert" ) func TestServicePopulateModel(t *testing.T) { @@ -82,29 +84,36 @@ func TestListServices(t *testing.T) { testLogic, ctrl := NewTestLogic(t) defer ctrl.Finish() + ecsServiceIDs := []id.ECSServiceID{ + "svc_id1", + "svc_id2", + } + testLogic.Backend.EXPECT(). ListServices(). - Return([]*models.Service{ - {ServiceID: "s1"}, - {ServiceID: "s2"}, - }, nil) + Return(ecsServiceIDs, nil) testLogic.AddTags(t, []*models.Tag{ - {EntityID: "s1", EntityType: "service", Key: "environment_id", Value: "e1"}, - {EntityID: "s2", EntityType: "service", Key: "environment_id", Value: "e2"}, + {EntityID: "env_id1", EntityType: "environment", Key: "name", Value: "env_name1"}, + {EntityID: "env_id2", EntityType: "environment", Key: "name", Value: "env_name2"}, + {EntityID: "svc_id1", EntityType: "service", Key: "name", Value: "svc_name1"}, + {EntityID: "svc_id1", EntityType: "service", Key: "environment_id", Value: "env_id1"}, + {EntityID: "svc_id2", EntityType: "service", Key: "name", Value: "svc_name2"}, + {EntityID: "svc_id2", EntityType: "service", Key: "environment_id", Value: "env_id2"}, }) serviceLogic := NewL0ServiceLogic(testLogic.Logic()) - services, err := serviceLogic.ListServices() + result, err := serviceLogic.ListServices() if err != nil { t.Fatal(err) } - testutils.AssertEqual(t, len(services), 2) - testutils.AssertEqual(t, services[0].ServiceID, "s1") - testutils.AssertEqual(t, services[0].EnvironmentID, "e1") - testutils.AssertEqual(t, services[1].ServiceID, "s2") - testutils.AssertEqual(t, services[1].EnvironmentID, "e2") + expected := []models.ServiceSummary{ + {EnvironmentID: "env_id1", EnvironmentName: "env_name1", ServiceID: "svc_id1", ServiceName: "svc_name1"}, + {EnvironmentID: "env_id2", EnvironmentName: "env_name2", ServiceID: "svc_id2", ServiceName: "svc_name2"}, + } + + assert.Equal(t, expected, result) } func TestDeleteService(t *testing.T) { diff --git a/api/logic/task_logic.go b/api/logic/task_logic.go index 18c6cb16b..3052b2b89 100644 --- a/api/logic/task_logic.go +++ b/api/logic/task_logic.go @@ -1,14 +1,18 @@ package logic import ( + "fmt" + + "github.com/quintilesims/layer0/api/backend/ecs/id" "github.com/quintilesims/layer0/common/errors" "github.com/quintilesims/layer0/common/models" ) type TaskLogic interface { - CreateTask(models.CreateTaskRequest) (*models.Task, error) + CreateTask(models.CreateTaskRequest) (string, error) ListTasks() ([]*models.TaskSummary, error) GetTask(string) (*models.Task, error) + GetEnvironmentTasks(environmentID string) ([]*models.Task, error) DeleteTask(string) error GetTaskLogs(string, string, string, int) ([]*models.LogFile, error) } @@ -24,35 +28,26 @@ func NewL0TaskLogic(logic Logic) *L0TaskLogic { } func (this *L0TaskLogic) ListTasks() ([]*models.TaskSummary, error) { - tasks, err := this.Backend.ListTasks() + taskARNs, err := this.Backend.ListTasks() if err != nil { return nil, err } - summaries := make([]*models.TaskSummary, len(tasks)) - for i, task := range tasks { - if err := this.populateModel(task); err != nil { - return nil, err - } - - summaries[i] = &models.TaskSummary{ - TaskID: task.TaskID, - TaskName: task.TaskName, - EnvironmentID: task.EnvironmentID, - EnvironmentName: task.EnvironmentName, - } - } - - return summaries, nil + return this.makeTaskSummaryModels(taskARNs) } func (this *L0TaskLogic) GetTask(taskID string) (*models.Task, error) { - environmentID, err := this.getEnvironmentID(taskID) + environmentID, err := this.lookupTaskEnvironmentID(taskID) if err != nil { return nil, err } - task, err := this.Backend.GetTask(environmentID, taskID) + taskARN, err := this.lookupTaskARN(taskID) + if err != nil { + return nil, err + } + + taskModel, err := this.Backend.GetTask(environmentID, taskARN) if err != nil { if err, ok := err.(*errors.ServerError); ok && err.Code == errors.InvalidTaskID { return nil, errors.Newf(errors.InvalidTaskID, "Task %s does not exist", taskID) @@ -61,20 +56,48 @@ func (this *L0TaskLogic) GetTask(taskID string) (*models.Task, error) { return nil, err } - if err := this.populateModel(task); err != nil { + if err := this.populateModel(taskID, taskModel); err != nil { return nil, err } - return task, nil + return taskModel, nil +} + +func (this *L0TaskLogic) GetEnvironmentTasks(environmentID string) ([]*models.Task, error) { + taskARNModels, err := this.Backend.GetEnvironmentTasks(environmentID) + if err != nil { + return nil, err + } + + taskModels := []*models.Task{} + for taskARN, taskModel := range taskARNModels { + taskID, err := this.getTaskARNFromID(taskARN) + if err != nil { + return nil, err + } + + if err := this.populateModel(taskID, taskModel); err != nil { + return nil, err + } + + taskModels = append(taskModels, taskModel) + } + + return taskModels, nil } func (this *L0TaskLogic) DeleteTask(taskID string) error { - environmentID, err := this.getEnvironmentID(taskID) + environmentID, err := this.lookupTaskEnvironmentID(taskID) + if err != nil { + return err + } + + taskARN, err := this.lookupTaskARN(taskID) if err != nil { return err } - if err := this.Backend.DeleteTask(environmentID, taskID); err != nil { + if err := this.Backend.DeleteTask(environmentID, taskARN); err != nil { return err } @@ -85,57 +108,53 @@ func (this *L0TaskLogic) DeleteTask(taskID string) error { return nil } -func (this *L0TaskLogic) CreateTask(req models.CreateTaskRequest) (*models.Task, error) { +func (this *L0TaskLogic) CreateTask(req models.CreateTaskRequest) (string, error) { if req.EnvironmentID == "" { - return nil, errors.Newf(errors.MissingParameter, "EnvironmentID not specified") + return "", errors.Newf(errors.MissingParameter, "EnvironmentID not specified") } if req.DeployID == "" { - return nil, errors.Newf(errors.MissingParameter, "DeployID not specified") + return "", errors.Newf(errors.MissingParameter, "DeployID not specified") } if req.TaskName == "" { - return nil, errors.Newf(errors.MissingParameter, "TaskName not specified") + return "", errors.Newf(errors.MissingParameter, "TaskName not specified") } - task, err := this.Backend.CreateTask( - req.EnvironmentID, - req.TaskName, - req.DeployID, - req.ContainerOverrides) + taskARN, err := this.Backend.CreateTask(req.EnvironmentID, req.DeployID, req.ContainerOverrides) if err != nil { - return nil, err - } - - taskID := task.TaskID - if err := this.TagStore.Insert(models.Tag{EntityID: taskID, EntityType: "task", Key: "name", Value: req.TaskName}); err != nil { - return task, err - } - - environmentID := req.EnvironmentID - if err := this.TagStore.Insert(models.Tag{EntityID: taskID, EntityType: "task", Key: "environment_id", Value: environmentID}); err != nil { - return task, err + return "", err } - deployID := req.DeployID - if err := this.TagStore.Insert(models.Tag{EntityID: taskID, EntityType: "task", Key: "deploy_id", Value: deployID}); err != nil { - return task, err + taskID := id.GenerateHashedEntityID(req.TaskName) + tags := []models.Tag{ + {EntityID: taskID, EntityType: "task", Key: "name", Value: req.TaskName}, + {EntityID: taskID, EntityType: "task", Key: "environment_id", Value: req.EnvironmentID}, + {EntityID: taskID, EntityType: "task", Key: "deploy_id", Value: req.DeployID}, + {EntityID: taskID, EntityType: "task", Key: "arn", Value: taskARN}, } - if err := this.populateModel(task); err != nil { - return task, err + for _, tag := range tags { + if err := this.TagStore.Insert(tag); err != nil { + return "", err + } } - return task, nil + return taskID, nil } func (this *L0TaskLogic) GetTaskLogs(taskID, start, end string, tail int) ([]*models.LogFile, error) { - environmentID, err := this.getEnvironmentID(taskID) + environmentID, err := this.lookupTaskEnvironmentID(taskID) if err != nil { return nil, err } - logs, err := this.Backend.GetTaskLogs(environmentID, taskID, start, end, tail) + taskARN, err := this.lookupTaskARN(taskID) + if err != nil { + return nil, err + } + + logs, err := this.Backend.GetTaskLogs(environmentID, taskARN, start, end, tail) if err != nil { return nil, err } @@ -143,7 +162,20 @@ func (this *L0TaskLogic) GetTaskLogs(taskID, start, end string, tail int) ([]*mo return logs, nil } -func (this *L0TaskLogic) getEnvironmentID(taskID string) (string, error) { +func (t *L0TaskLogic) getTaskARNFromID(taskARN string) (string, error) { + tags, err := t.TagStore.SelectByType("task") + if err != nil { + return "", err + } + + if tag, ok := tags.WithKey("arn").WithValue(taskARN).First(); ok { + return tag.EntityID, nil + } + + return "", fmt.Errorf("Failed to find task id for ARN %s", taskARN) +} + +func (this *L0TaskLogic) lookupTaskEnvironmentID(taskID string) (string, error) { tags, err := this.TagStore.SelectByTypeAndID("task", taskID) if err != nil { return "", err @@ -153,22 +185,72 @@ func (this *L0TaskLogic) getEnvironmentID(taskID string) (string, error) { return tag.Value, nil } - tasks, err := this.ListTasks() + return "", errors.Newf(errors.TaskDoesNotExist, "Failed to find environment for task %s", taskID) +} + +func (t *L0TaskLogic) lookupTaskARN(taskID string) (string, error) { + tags, err := t.TagStore.SelectByTypeAndID("task", taskID) if err != nil { return "", err } - for _, task := range tasks { - if task.TaskID == taskID { - return task.EnvironmentID, nil + if len(tags) == 0 { + return "", errors.Newf(errors.TaskDoesNotExist, "Task '%s' does not exist", taskID) + } + + if tag, ok := tags.WithKey("arn").First(); ok { + return tag.Value, nil + } + + return "", fmt.Errorf("Failed to find ARN for task '%s'", taskID) +} + +func (t *L0TaskLogic) makeTaskSummaryModels(taskARNs []string) ([]*models.TaskSummary, error) { + environmentTags, err := t.TagStore.SelectByType("environment") + if err != nil { + return nil, err + } + + taskTags, err := t.TagStore.SelectByType("task") + if err != nil { + return nil, err + } + + taskARNMatches := map[string]bool{} + for _, taskARN := range taskARNs { + taskARNMatches[taskARN] = true + } + + taskModels := make([]*models.TaskSummary, 0, len(taskARNs)) + for _, tag := range taskTags.WithKey("arn") { + if taskARNMatches[tag.Value] { + model := &models.TaskSummary{ + TaskID: tag.EntityID, + } + + if tag, ok := taskTags.WithID(model.TaskID).WithKey("name").First(); ok { + model.TaskName = tag.Value + } + + if tag, ok := taskTags.WithID(model.TaskID).WithKey("environment_id").First(); ok { + model.EnvironmentID = tag.Value + + if t, ok := environmentTags.WithID(tag.Value).WithKey("name").First(); ok { + model.EnvironmentName = t.Value + } + } + + taskModels = append(taskModels, model) } } - return "", errors.Newf(errors.TaskDoesNotExist, "Task %s does not exist", taskID) + return taskModels, nil } -func (this *L0TaskLogic) populateModel(model *models.Task) error { - tags, err := this.TagStore.SelectByTypeAndID("task", model.TaskID) +func (this *L0TaskLogic) populateModel(taskID string, model *models.Task) error { + model.TaskID = taskID + + tags, err := this.TagStore.SelectByTypeAndID("task", taskID) if err != nil { return err } diff --git a/api/logic/task_logic_test.go b/api/logic/task_logic_test.go index 626506adf..5defff7c6 100644 --- a/api/logic/task_logic_test.go +++ b/api/logic/task_logic_test.go @@ -5,118 +5,98 @@ import ( "github.com/quintilesims/layer0/common/models" "github.com/quintilesims/layer0/common/testutils" + "github.com/stretchr/testify/assert" ) -func TestTaskPopulateModel(t *testing.T) { +func TestGetTask(t *testing.T) { testLogic, ctrl := NewTestLogic(t) defer ctrl.Finish() testLogic.AddTags(t, []*models.Tag{ - {EntityID: "t1", EntityType: "task", Key: "name", Value: "tsk_1"}, - {EntityID: "e1", EntityType: "environment", Key: "name", Value: "env_1"}, - {EntityID: "d1", EntityType: "deploy", Key: "name", Value: "dpl_1"}, - - {EntityID: "t2", EntityType: "task", Key: "name", Value: "tsk_2"}, - {EntityID: "t2", EntityType: "task", Key: "environment_id", Value: "e2"}, - {EntityID: "t2", EntityType: "task", Key: "deploy_id", Value: "d2"}, + {EntityID: "env_id", EntityType: "environment", Key: "name", Value: "env_name"}, + {EntityID: "tsk_id", EntityType: "task", Key: "name", Value: "tsk_name"}, + {EntityID: "tsk_id", EntityType: "task", Key: "environment_id", Value: "env_id"}, + {EntityID: "tsk_id", EntityType: "task", Key: "arn", Value: "tsk_arn"}, }) - cases := map[*models.Task]func(*models.Task){ - { - TaskID: "t1", - EnvironmentID: "e1", - DeployID: "d1", - }: func(m *models.Task) { - testutils.AssertEqual(t, m.TaskName, "tsk_1") - testutils.AssertEqual(t, m.EnvironmentName, "env_1") - testutils.AssertEqual(t, m.DeployName, "dpl_1") - }, - { - TaskID: "t2", - }: func(m *models.Task) { - testutils.AssertEqual(t, m.TaskName, "tsk_2") - testutils.AssertEqual(t, m.EnvironmentID, "e2") - testutils.AssertEqual(t, m.DeployID, "d2") - }, - } - - taskLogic := NewL0TaskLogic(testLogic.Logic()) - for model, fn := range cases { - if err := taskLogic.populateModel(model); err != nil { - t.Fatal(err) - } - - fn(model) - } -} - -func TestGetTask(t *testing.T) { - testLogic, ctrl := NewTestLogic(t) - defer ctrl.Finish() - testLogic.Backend.EXPECT(). - GetTask("e1", "t1"). - Return(&models.Task{TaskID: "t1"}, nil) - - testLogic.AddTags(t, []*models.Tag{ - {EntityID: "t1", EntityType: "task", Key: "environment_id", Value: "e1"}, - }) + GetTask("env_id", "tsk_arn"). + Return(&models.Task{RunningCount: 1}, nil) taskLogic := NewL0TaskLogic(testLogic.Logic()) - task, err := taskLogic.GetTask("t1") + result, err := taskLogic.GetTask("tsk_id") if err != nil { t.Fatal(err) } - testutils.AssertEqual(t, task.TaskID, "t1") - testutils.AssertEqual(t, task.EnvironmentID, "e1") + expected := &models.Task{ + EnvironmentID: "env_id", + EnvironmentName: "env_name", + TaskID: "tsk_id", + TaskName: "tsk_name", + RunningCount: 1, + PendingCount: 0, + } + + testutils.AssertEqual(t, expected, result) } func TestListTasks(t *testing.T) { testLogic, ctrl := NewTestLogic(t) defer ctrl.Finish() + taskARNs := []string{ + "arn1", + "arn2", + "extra", + } + testLogic.Backend.EXPECT(). ListTasks(). - Return([]*models.Task{ - {TaskID: "t1"}, - {TaskID: "t2"}, - }, nil) + Return(taskARNs, nil) testLogic.AddTags(t, []*models.Tag{ - {EntityID: "t1", EntityType: "task", Key: "environment_id", Value: "e1"}, - {EntityID: "t2", EntityType: "task", Key: "environment_id", Value: "e2"}, + {EntityID: "env_id1", EntityType: "environment", Key: "name", Value: "env_name1"}, + {EntityID: "env_id2", EntityType: "environment", Key: "name", Value: "env_name2"}, + {EntityID: "tsk_id1", EntityType: "task", Key: "name", Value: "tsk_name1"}, + {EntityID: "tsk_id1", EntityType: "task", Key: "environment_id", Value: "env_id1"}, + {EntityID: "tsk_id1", EntityType: "task", Key: "arn", Value: "arn1"}, + {EntityID: "tsk_id2", EntityType: "task", Key: "name", Value: "tsk_name2"}, + {EntityID: "tsk_id2", EntityType: "task", Key: "environment_id", Value: "env_id2"}, + {EntityID: "tsk_id2", EntityType: "task", Key: "arn", Value: "arn2"}, }) taskLogic := NewL0TaskLogic(testLogic.Logic()) - tasks, err := taskLogic.ListTasks() + result, err := taskLogic.ListTasks() if err != nil { t.Fatal(err) } - testutils.AssertEqual(t, len(tasks), 2) - testutils.AssertEqual(t, tasks[0].TaskID, "t1") - testutils.AssertEqual(t, tasks[0].EnvironmentID, "e1") - testutils.AssertEqual(t, tasks[1].TaskID, "t2") - testutils.AssertEqual(t, tasks[1].EnvironmentID, "e2") + expected := []*models.TaskSummary{ + {EnvironmentID: "env_id1", EnvironmentName: "env_name1", TaskID: "tsk_id1", TaskName: "tsk_name1"}, + {EnvironmentID: "env_id2", EnvironmentName: "env_name2", TaskID: "tsk_id2", TaskName: "tsk_name2"}, + } + + assert.Equal(t, expected, result) } func TestDeleteTask(t *testing.T) { testLogic, ctrl := NewTestLogic(t) defer ctrl.Finish() - testLogic.Backend.EXPECT(). - DeleteTask("e1", "t1"). - Return(nil) - testLogic.AddTags(t, []*models.Tag{ - {EntityID: "t1", EntityType: "task", Key: "name", Value: "tsk"}, - {EntityID: "t1", EntityType: "task", Key: "environment_id", Value: "e1"}, - {EntityID: "extra", EntityType: "task", Key: "name", Value: "extra"}, + {EntityID: "tsk_id", EntityType: "task", Key: "name", Value: "tsk_name"}, + {EntityID: "tsk_id", EntityType: "task", Key: "environment_id", Value: "env_id"}, + {EntityID: "tsk_id", EntityType: "task", Key: "arn", Value: "tsk_arn"}, + {EntityID: "extra", EntityType: "task"}, }) + testLogic.Backend.EXPECT(). + DeleteTask("env_id", "tsk_arn"). + Return(nil) + taskLogic := NewL0TaskLogic(testLogic.Logic()) - if err := taskLogic.DeleteTask("t1"); err != nil { + if err := taskLogic.DeleteTask("tsk_id"); err != nil { t.Fatal(err) } @@ -133,29 +113,32 @@ func TestCreateTask(t *testing.T) { testLogic, ctrl := NewTestLogic(t) defer ctrl.Finish() - testLogic.Backend.EXPECT(). - CreateTask("e1", "name", "d1", nil). - Return(&models.Task{TaskID: "t1"}, nil) - - request := models.CreateTaskRequest{ - TaskName: "name", - EnvironmentID: "e1", - DeployID: "d1", - Copies: 2, + req := models.CreateTaskRequest{ + TaskName: "tsk_name", + EnvironmentID: "env_id", + DeployID: "dpl_id", } + testLogic.Backend.EXPECT(). + CreateTask("env_id", "dpl_id", nil). + Return("tsk_arn", nil) + taskLogic := NewL0TaskLogic(testLogic.Logic()) - task, err := taskLogic.CreateTask(request) + taskID, err := taskLogic.CreateTask(req) if err != nil { t.Fatal(err) } - testutils.AssertEqual(t, task.TaskID, "t1") - testutils.AssertEqual(t, task.EnvironmentID, "e1") + expectedTags := []models.Tag{ + {EntityID: taskID, EntityType: "task", Key: "name", Value: req.TaskName}, + {EntityID: taskID, EntityType: "task", Key: "environment_id", Value: req.EnvironmentID}, + {EntityID: taskID, EntityType: "task", Key: "deploy_id", Value: req.DeployID}, + {EntityID: taskID, EntityType: "task", Key: "arn", Value: "tsk_arn"}, + } - testLogic.AssertTagExists(t, models.Tag{EntityID: "t1", EntityType: "task", Key: "name", Value: "name"}) - testLogic.AssertTagExists(t, models.Tag{EntityID: "t1", EntityType: "task", Key: "environment_id", Value: "e1"}) - testLogic.AssertTagExists(t, models.Tag{EntityID: "t1", EntityType: "task", Key: "deploy_id", Value: "d1"}) + for _, tag := range expectedTags { + testLogic.AssertTagExists(t, tag) + } } func TestCreateTaskError_missingRequiredParams(t *testing.T) { @@ -190,24 +173,25 @@ func TestGetTaskLogs(t *testing.T) { testLogic, ctrl := NewTestLogic(t) defer ctrl.Finish() - logs := []*models.LogFile{ + expected := []*models.LogFile{ {Name: "alpha", Lines: []string{"first", "second"}}, {Name: "beta", Lines: []string{"first", "second", "third"}}, } testLogic.Backend.EXPECT(). - GetTaskLogs("e1", "t1", "start", "end", 100). - Return(logs, nil) + GetTaskLogs("env_id", "tsk_arn", "start", "end", 100). + Return(expected, nil) testLogic.AddTags(t, []*models.Tag{ - {EntityID: "t1", EntityType: "task", Key: "environment_id", Value: "e1"}, + {EntityID: "tsk_id", EntityType: "task", Key: "environment_id", Value: "env_id"}, + {EntityID: "tsk_id", EntityType: "task", Key: "arn", Value: "tsk_arn"}, }) taskLogic := NewL0TaskLogic(testLogic.Logic()) - received, err := taskLogic.GetTaskLogs("t1", "start", "end", 100) + result, err := taskLogic.GetTaskLogs("tsk_id", "start", "end", 100) if err != nil { t.Fatal(err) } - testutils.AssertEqual(t, received, logs) + testutils.AssertEqual(t, expected, result) } diff --git a/api/main.go b/api/main.go index d1b525287..cb35b842b 100644 --- a/api/main.go +++ b/api/main.go @@ -17,7 +17,7 @@ import ( ) const ( - SCALER_SLEEP_DURATION = time.Minute * 5 + SCALER_SLEEP_DURATION = time.Hour ) func setupRestful(lgc logic.Logic) { @@ -166,8 +166,6 @@ func runEnvironmentScaler(environmentLogic *logic.L0EnvironmentLogic) { logger := logutils.NewStandardLogger("AUTO Environment Scaler") for { - time.Sleep(SCALER_SLEEP_DURATION) - environments, err := environmentLogic.ListEnvironments() if err != nil { logger.Errorf("Failed to list environments: %v", err) @@ -184,5 +182,7 @@ func runEnvironmentScaler(environmentLogic *logic.L0EnvironmentLogic) { logger.Infof("Finished scaling environment %s", environment.EnvironmentID) } + + time.Sleep(SCALER_SLEEP_DURATION) } } diff --git a/api/scheduler/environment_scaler.go b/api/scheduler/environment_scaler.go index 17cba8392..019a1893f 100644 --- a/api/scheduler/environment_scaler.go +++ b/api/scheduler/environment_scaler.go @@ -28,7 +28,7 @@ func NewL0EnvironmentScaler(c resource.ConsumerGetter, p resource.ProviderManage consumerGetter: c, providerManager: p, scheduledRuns: map[string]chan time.Duration{}, - logger: logutils.NewStandardLogger("Environment Scaler"), + logger: logutils.NewStandardLogger("Environment Scaler").Logger, } } diff --git a/api/scheduler/mock_scheduler/mock_environment_scaler.go b/api/scheduler/mock_scheduler/mock_environment_scaler.go index b0480e958..1c04c436e 100644 --- a/api/scheduler/mock_scheduler/mock_environment_scaler.go +++ b/api/scheduler/mock_scheduler/mock_environment_scaler.go @@ -1,51 +1,59 @@ -// Automatically generated by MockGen. DO NOT EDIT! +// Code generated by MockGen. DO NOT EDIT. // Source: github.com/quintilesims/layer0/api/scheduler (interfaces: EnvironmentScaler) +// Package mock_scheduler is a generated GoMock package. package mock_scheduler import ( + reflect "reflect" time "time" gomock "github.com/golang/mock/gomock" models "github.com/quintilesims/layer0/common/models" ) -// Mock of EnvironmentScaler interface +// MockEnvironmentScaler is a mock of EnvironmentScaler interface type MockEnvironmentScaler struct { ctrl *gomock.Controller - recorder *_MockEnvironmentScalerRecorder + recorder *MockEnvironmentScalerMockRecorder } -// Recorder for MockEnvironmentScaler (not exported) -type _MockEnvironmentScalerRecorder struct { +// MockEnvironmentScalerMockRecorder is the mock recorder for MockEnvironmentScaler +type MockEnvironmentScalerMockRecorder struct { mock *MockEnvironmentScaler } +// NewMockEnvironmentScaler creates a new mock instance func NewMockEnvironmentScaler(ctrl *gomock.Controller) *MockEnvironmentScaler { mock := &MockEnvironmentScaler{ctrl: ctrl} - mock.recorder = &_MockEnvironmentScalerRecorder{mock} + mock.recorder = &MockEnvironmentScalerMockRecorder{mock} return mock } -func (_m *MockEnvironmentScaler) EXPECT() *_MockEnvironmentScalerRecorder { - return _m.recorder +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockEnvironmentScaler) EXPECT() *MockEnvironmentScalerMockRecorder { + return m.recorder } -func (_m *MockEnvironmentScaler) Scale(_param0 string) (*models.ScalerRunInfo, error) { - ret := _m.ctrl.Call(_m, "Scale", _param0) +// Scale mocks base method +func (m *MockEnvironmentScaler) Scale(arg0 string) (*models.ScalerRunInfo, error) { + ret := m.ctrl.Call(m, "Scale", arg0) ret0, _ := ret[0].(*models.ScalerRunInfo) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockEnvironmentScalerRecorder) Scale(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "Scale", arg0) +// Scale indicates an expected call of Scale +func (mr *MockEnvironmentScalerMockRecorder) Scale(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Scale", reflect.TypeOf((*MockEnvironmentScaler)(nil).Scale), arg0) } -func (_m *MockEnvironmentScaler) ScheduleRun(_param0 string, _param1 time.Duration) { - _m.ctrl.Call(_m, "ScheduleRun", _param0, _param1) +// ScheduleRun mocks base method +func (m *MockEnvironmentScaler) ScheduleRun(arg0 string, arg1 time.Duration) { + m.ctrl.Call(m, "ScheduleRun", arg0, arg1) } -func (_mr *_MockEnvironmentScalerRecorder) ScheduleRun(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ScheduleRun", arg0, arg1) +// ScheduleRun indicates an expected call of ScheduleRun +func (mr *MockEnvironmentScalerMockRecorder) ScheduleRun(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ScheduleRun", reflect.TypeOf((*MockEnvironmentScaler)(nil).ScheduleRun), arg0, arg1) } diff --git a/api/scheduler/resource/mock_resource/mock_consumer_getter.go b/api/scheduler/resource/mock_resource/mock_consumer_getter.go index 3b326aa59..db57c4378 100644 --- a/api/scheduler/resource/mock_resource/mock_consumer_getter.go +++ b/api/scheduler/resource/mock_resource/mock_consumer_getter.go @@ -1,41 +1,48 @@ -// Automatically generated by MockGen. DO NOT EDIT! +// Code generated by MockGen. DO NOT EDIT. // Source: github.com/quintilesims/layer0/api/scheduler/resource (interfaces: ConsumerGetter) +// Package mock_resource is a generated GoMock package. package mock_resource import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" resource "github.com/quintilesims/layer0/api/scheduler/resource" ) -// Mock of ConsumerGetter interface +// MockConsumerGetter is a mock of ConsumerGetter interface type MockConsumerGetter struct { ctrl *gomock.Controller - recorder *_MockConsumerGetterRecorder + recorder *MockConsumerGetterMockRecorder } -// Recorder for MockConsumerGetter (not exported) -type _MockConsumerGetterRecorder struct { +// MockConsumerGetterMockRecorder is the mock recorder for MockConsumerGetter +type MockConsumerGetterMockRecorder struct { mock *MockConsumerGetter } +// NewMockConsumerGetter creates a new mock instance func NewMockConsumerGetter(ctrl *gomock.Controller) *MockConsumerGetter { mock := &MockConsumerGetter{ctrl: ctrl} - mock.recorder = &_MockConsumerGetterRecorder{mock} + mock.recorder = &MockConsumerGetterMockRecorder{mock} return mock } -func (_m *MockConsumerGetter) EXPECT() *_MockConsumerGetterRecorder { - return _m.recorder +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockConsumerGetter) EXPECT() *MockConsumerGetterMockRecorder { + return m.recorder } -func (_m *MockConsumerGetter) GetConsumers(_param0 string) ([]resource.ResourceConsumer, error) { - ret := _m.ctrl.Call(_m, "GetConsumers", _param0) +// GetConsumers mocks base method +func (m *MockConsumerGetter) GetConsumers(arg0 string) ([]resource.ResourceConsumer, error) { + ret := m.ctrl.Call(m, "GetConsumers", arg0) ret0, _ := ret[0].([]resource.ResourceConsumer) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockConsumerGetterRecorder) GetConsumers(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetConsumers", arg0) +// GetConsumers indicates an expected call of GetConsumers +func (mr *MockConsumerGetterMockRecorder) GetConsumers(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetConsumers", reflect.TypeOf((*MockConsumerGetter)(nil).GetConsumers), arg0) } diff --git a/api/scheduler/resource/mock_resource/mock_provider_manager.go b/api/scheduler/resource/mock_resource/mock_provider_manager.go index 5844c3510..4c6053e95 100644 --- a/api/scheduler/resource/mock_resource/mock_provider_manager.go +++ b/api/scheduler/resource/mock_resource/mock_provider_manager.go @@ -1,63 +1,74 @@ -// Automatically generated by MockGen. DO NOT EDIT! +// Code generated by MockGen. DO NOT EDIT. // Source: github.com/quintilesims/layer0/api/scheduler/resource (interfaces: ProviderManager) +// Package mock_resource is a generated GoMock package. package mock_resource import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" resource "github.com/quintilesims/layer0/api/scheduler/resource" ) -// Mock of ProviderManager interface +// MockProviderManager is a mock of ProviderManager interface type MockProviderManager struct { ctrl *gomock.Controller - recorder *_MockProviderManagerRecorder + recorder *MockProviderManagerMockRecorder } -// Recorder for MockProviderManager (not exported) -type _MockProviderManagerRecorder struct { +// MockProviderManagerMockRecorder is the mock recorder for MockProviderManager +type MockProviderManagerMockRecorder struct { mock *MockProviderManager } +// NewMockProviderManager creates a new mock instance func NewMockProviderManager(ctrl *gomock.Controller) *MockProviderManager { mock := &MockProviderManager{ctrl: ctrl} - mock.recorder = &_MockProviderManagerRecorder{mock} + mock.recorder = &MockProviderManagerMockRecorder{mock} return mock } -func (_m *MockProviderManager) EXPECT() *_MockProviderManagerRecorder { - return _m.recorder +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockProviderManager) EXPECT() *MockProviderManagerMockRecorder { + return m.recorder } -func (_m *MockProviderManager) CalculateNewProvider(_param0 string) (*resource.ResourceProvider, error) { - ret := _m.ctrl.Call(_m, "CalculateNewProvider", _param0) +// CalculateNewProvider mocks base method +func (m *MockProviderManager) CalculateNewProvider(arg0 string) (*resource.ResourceProvider, error) { + ret := m.ctrl.Call(m, "CalculateNewProvider", arg0) ret0, _ := ret[0].(*resource.ResourceProvider) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderManagerRecorder) CalculateNewProvider(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CalculateNewProvider", arg0) +// CalculateNewProvider indicates an expected call of CalculateNewProvider +func (mr *MockProviderManagerMockRecorder) CalculateNewProvider(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CalculateNewProvider", reflect.TypeOf((*MockProviderManager)(nil).CalculateNewProvider), arg0) } -func (_m *MockProviderManager) GetProviders(_param0 string) ([]*resource.ResourceProvider, error) { - ret := _m.ctrl.Call(_m, "GetProviders", _param0) +// GetProviders mocks base method +func (m *MockProviderManager) GetProviders(arg0 string) ([]*resource.ResourceProvider, error) { + ret := m.ctrl.Call(m, "GetProviders", arg0) ret0, _ := ret[0].([]*resource.ResourceProvider) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderManagerRecorder) GetProviders(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetProviders", arg0) +// GetProviders indicates an expected call of GetProviders +func (mr *MockProviderManagerMockRecorder) GetProviders(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetProviders", reflect.TypeOf((*MockProviderManager)(nil).GetProviders), arg0) } -func (_m *MockProviderManager) ScaleTo(_param0 string, _param1 int, _param2 []*resource.ResourceProvider) (int, error) { - ret := _m.ctrl.Call(_m, "ScaleTo", _param0, _param1, _param2) +// ScaleTo mocks base method +func (m *MockProviderManager) ScaleTo(arg0 string, arg1 int, arg2 []*resource.ResourceProvider) (int, error) { + ret := m.ctrl.Call(m, "ScaleTo", arg0, arg1, arg2) ret0, _ := ret[0].(int) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderManagerRecorder) ScaleTo(arg0, arg1, arg2 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ScaleTo", arg0, arg1, arg2) +// ScaleTo indicates an expected call of ScaleTo +func (mr *MockProviderManagerMockRecorder) ScaleTo(arg0, arg1, arg2 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ScaleTo", reflect.TypeOf((*MockProviderManager)(nil).ScaleTo), arg0, arg1, arg2) } diff --git a/cli/client/interface.go b/cli/client/interface.go index d5ec678bf..80f40f805 100644 --- a/cli/client/interface.go +++ b/cli/client/interface.go @@ -41,7 +41,7 @@ type Client interface { ScaleService(id string, scale int) (*models.Service, error) WaitForDeployment(serviceID string, timeout time.Duration) (*models.Service, error) - CreateTask(name, environmentID, deployID string, copies int, overrides []models.ContainerOverride) (string, error) + CreateTask(name, environmentID, deployID string, overrides []models.ContainerOverride) (string, error) DeleteTask(id string) error GetTask(id string) (*models.Task, error) GetTaskLogs(id, start, end string, tail int) ([]*models.LogFile, error) diff --git a/cli/client/mock_client/mock_client.go b/cli/client/mock_client/mock_client.go index 06a614fa0..b5aad9a50 100644 --- a/cli/client/mock_client/mock_client.go +++ b/cli/client/mock_client/mock_client.go @@ -1,454 +1,536 @@ -// Automatically generated by MockGen. DO NOT EDIT! +// Code generated by MockGen. DO NOT EDIT. // Source: github.com/quintilesims/layer0/cli/client (interfaces: Client) +// Package mock_client is a generated GoMock package. package mock_client import ( + reflect "reflect" time "time" gomock "github.com/golang/mock/gomock" models "github.com/quintilesims/layer0/common/models" ) -// Mock of Client interface +// MockClient is a mock of Client interface type MockClient struct { ctrl *gomock.Controller - recorder *_MockClientRecorder + recorder *MockClientMockRecorder } -// Recorder for MockClient (not exported) -type _MockClientRecorder struct { +// MockClientMockRecorder is the mock recorder for MockClient +type MockClientMockRecorder struct { mock *MockClient } +// NewMockClient creates a new mock instance func NewMockClient(ctrl *gomock.Controller) *MockClient { mock := &MockClient{ctrl: ctrl} - mock.recorder = &_MockClientRecorder{mock} + mock.recorder = &MockClientMockRecorder{mock} return mock } -func (_m *MockClient) EXPECT() *_MockClientRecorder { - return _m.recorder +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockClient) EXPECT() *MockClientMockRecorder { + return m.recorder } -func (_m *MockClient) CreateDeploy(_param0 string, _param1 []byte) (*models.Deploy, error) { - ret := _m.ctrl.Call(_m, "CreateDeploy", _param0, _param1) +// CreateDeploy mocks base method +func (m *MockClient) CreateDeploy(arg0 string, arg1 []byte) (*models.Deploy, error) { + ret := m.ctrl.Call(m, "CreateDeploy", arg0, arg1) ret0, _ := ret[0].(*models.Deploy) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) CreateDeploy(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateDeploy", arg0, arg1) +// CreateDeploy indicates an expected call of CreateDeploy +func (mr *MockClientMockRecorder) CreateDeploy(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateDeploy", reflect.TypeOf((*MockClient)(nil).CreateDeploy), arg0, arg1) } -func (_m *MockClient) CreateEnvironment(_param0 string, _param1 string, _param2 int, _param3 []byte, _param4 string, _param5 string) (*models.Environment, error) { - ret := _m.ctrl.Call(_m, "CreateEnvironment", _param0, _param1, _param2, _param3, _param4, _param5) +// CreateEnvironment mocks base method +func (m *MockClient) CreateEnvironment(arg0, arg1 string, arg2 int, arg3 []byte, arg4, arg5 string) (*models.Environment, error) { + ret := m.ctrl.Call(m, "CreateEnvironment", arg0, arg1, arg2, arg3, arg4, arg5) ret0, _ := ret[0].(*models.Environment) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) CreateEnvironment(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateEnvironment", arg0, arg1, arg2, arg3, arg4, arg5) +// CreateEnvironment indicates an expected call of CreateEnvironment +func (mr *MockClientMockRecorder) CreateEnvironment(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateEnvironment", reflect.TypeOf((*MockClient)(nil).CreateEnvironment), arg0, arg1, arg2, arg3, arg4, arg5) } -func (_m *MockClient) CreateLink(_param0 string, _param1 string) error { - ret := _m.ctrl.Call(_m, "CreateLink", _param0, _param1) +// CreateLink mocks base method +func (m *MockClient) CreateLink(arg0, arg1 string) error { + ret := m.ctrl.Call(m, "CreateLink", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockClientRecorder) CreateLink(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateLink", arg0, arg1) +// CreateLink indicates an expected call of CreateLink +func (mr *MockClientMockRecorder) CreateLink(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateLink", reflect.TypeOf((*MockClient)(nil).CreateLink), arg0, arg1) } -func (_m *MockClient) CreateLoadBalancer(_param0 string, _param1 string, _param2 models.HealthCheck, _param3 []models.Port, _param4 bool) (*models.LoadBalancer, error) { - ret := _m.ctrl.Call(_m, "CreateLoadBalancer", _param0, _param1, _param2, _param3, _param4) +// CreateLoadBalancer mocks base method +func (m *MockClient) CreateLoadBalancer(arg0, arg1 string, arg2 models.HealthCheck, arg3 []models.Port, arg4 bool) (*models.LoadBalancer, error) { + ret := m.ctrl.Call(m, "CreateLoadBalancer", arg0, arg1, arg2, arg3, arg4) ret0, _ := ret[0].(*models.LoadBalancer) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) CreateLoadBalancer(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateLoadBalancer", arg0, arg1, arg2, arg3, arg4) +// CreateLoadBalancer indicates an expected call of CreateLoadBalancer +func (mr *MockClientMockRecorder) CreateLoadBalancer(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateLoadBalancer", reflect.TypeOf((*MockClient)(nil).CreateLoadBalancer), arg0, arg1, arg2, arg3, arg4) } -func (_m *MockClient) CreateService(_param0 string, _param1 string, _param2 string, _param3 string) (*models.Service, error) { - ret := _m.ctrl.Call(_m, "CreateService", _param0, _param1, _param2, _param3) +// CreateService mocks base method +func (m *MockClient) CreateService(arg0, arg1, arg2, arg3 string) (*models.Service, error) { + ret := m.ctrl.Call(m, "CreateService", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(*models.Service) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) CreateService(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateService", arg0, arg1, arg2, arg3) +// CreateService indicates an expected call of CreateService +func (mr *MockClientMockRecorder) CreateService(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateService", reflect.TypeOf((*MockClient)(nil).CreateService), arg0, arg1, arg2, arg3) } -func (_m *MockClient) CreateTask(_param0 string, _param1 string, _param2 string, _param3 int, _param4 []models.ContainerOverride) (string, error) { - ret := _m.ctrl.Call(_m, "CreateTask", _param0, _param1, _param2, _param3, _param4) +// CreateTask mocks base method +func (m *MockClient) CreateTask(arg0, arg1, arg2 string, arg3 []models.ContainerOverride) (string, error) { + ret := m.ctrl.Call(m, "CreateTask", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) CreateTask(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateTask", arg0, arg1, arg2, arg3, arg4) +// CreateTask indicates an expected call of CreateTask +func (mr *MockClientMockRecorder) CreateTask(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateTask", reflect.TypeOf((*MockClient)(nil).CreateTask), arg0, arg1, arg2, arg3) } -func (_m *MockClient) Delete(_param0 string) error { - ret := _m.ctrl.Call(_m, "Delete", _param0) +// Delete mocks base method +func (m *MockClient) Delete(arg0 string) error { + ret := m.ctrl.Call(m, "Delete", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockClientRecorder) Delete(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "Delete", arg0) +// Delete indicates an expected call of Delete +func (mr *MockClientMockRecorder) Delete(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockClient)(nil).Delete), arg0) } -func (_m *MockClient) DeleteDeploy(_param0 string) error { - ret := _m.ctrl.Call(_m, "DeleteDeploy", _param0) +// DeleteDeploy mocks base method +func (m *MockClient) DeleteDeploy(arg0 string) error { + ret := m.ctrl.Call(m, "DeleteDeploy", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockClientRecorder) DeleteDeploy(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteDeploy", arg0) +// DeleteDeploy indicates an expected call of DeleteDeploy +func (mr *MockClientMockRecorder) DeleteDeploy(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteDeploy", reflect.TypeOf((*MockClient)(nil).DeleteDeploy), arg0) } -func (_m *MockClient) DeleteEnvironment(_param0 string) (string, error) { - ret := _m.ctrl.Call(_m, "DeleteEnvironment", _param0) +// DeleteEnvironment mocks base method +func (m *MockClient) DeleteEnvironment(arg0 string) (string, error) { + ret := m.ctrl.Call(m, "DeleteEnvironment", arg0) ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) DeleteEnvironment(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteEnvironment", arg0) +// DeleteEnvironment indicates an expected call of DeleteEnvironment +func (mr *MockClientMockRecorder) DeleteEnvironment(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteEnvironment", reflect.TypeOf((*MockClient)(nil).DeleteEnvironment), arg0) } -func (_m *MockClient) DeleteLink(_param0 string, _param1 string) error { - ret := _m.ctrl.Call(_m, "DeleteLink", _param0, _param1) +// DeleteLink mocks base method +func (m *MockClient) DeleteLink(arg0, arg1 string) error { + ret := m.ctrl.Call(m, "DeleteLink", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockClientRecorder) DeleteLink(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteLink", arg0, arg1) +// DeleteLink indicates an expected call of DeleteLink +func (mr *MockClientMockRecorder) DeleteLink(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteLink", reflect.TypeOf((*MockClient)(nil).DeleteLink), arg0, arg1) } -func (_m *MockClient) DeleteLoadBalancer(_param0 string) (string, error) { - ret := _m.ctrl.Call(_m, "DeleteLoadBalancer", _param0) +// DeleteLoadBalancer mocks base method +func (m *MockClient) DeleteLoadBalancer(arg0 string) (string, error) { + ret := m.ctrl.Call(m, "DeleteLoadBalancer", arg0) ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) DeleteLoadBalancer(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteLoadBalancer", arg0) +// DeleteLoadBalancer indicates an expected call of DeleteLoadBalancer +func (mr *MockClientMockRecorder) DeleteLoadBalancer(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteLoadBalancer", reflect.TypeOf((*MockClient)(nil).DeleteLoadBalancer), arg0) } -func (_m *MockClient) DeleteService(_param0 string) (string, error) { - ret := _m.ctrl.Call(_m, "DeleteService", _param0) +// DeleteService mocks base method +func (m *MockClient) DeleteService(arg0 string) (string, error) { + ret := m.ctrl.Call(m, "DeleteService", arg0) ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) DeleteService(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteService", arg0) +// DeleteService indicates an expected call of DeleteService +func (mr *MockClientMockRecorder) DeleteService(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteService", reflect.TypeOf((*MockClient)(nil).DeleteService), arg0) } -func (_m *MockClient) DeleteTask(_param0 string) error { - ret := _m.ctrl.Call(_m, "DeleteTask", _param0) +// DeleteTask mocks base method +func (m *MockClient) DeleteTask(arg0 string) error { + ret := m.ctrl.Call(m, "DeleteTask", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockClientRecorder) DeleteTask(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteTask", arg0) +// DeleteTask indicates an expected call of DeleteTask +func (mr *MockClientMockRecorder) DeleteTask(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteTask", reflect.TypeOf((*MockClient)(nil).DeleteTask), arg0) } -func (_m *MockClient) GetConfig() (*models.APIConfig, error) { - ret := _m.ctrl.Call(_m, "GetConfig") +// GetConfig mocks base method +func (m *MockClient) GetConfig() (*models.APIConfig, error) { + ret := m.ctrl.Call(m, "GetConfig") ret0, _ := ret[0].(*models.APIConfig) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) GetConfig() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetConfig") +// GetConfig indicates an expected call of GetConfig +func (mr *MockClientMockRecorder) GetConfig() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetConfig", reflect.TypeOf((*MockClient)(nil).GetConfig)) } -func (_m *MockClient) GetDeploy(_param0 string) (*models.Deploy, error) { - ret := _m.ctrl.Call(_m, "GetDeploy", _param0) +// GetDeploy mocks base method +func (m *MockClient) GetDeploy(arg0 string) (*models.Deploy, error) { + ret := m.ctrl.Call(m, "GetDeploy", arg0) ret0, _ := ret[0].(*models.Deploy) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) GetDeploy(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetDeploy", arg0) +// GetDeploy indicates an expected call of GetDeploy +func (mr *MockClientMockRecorder) GetDeploy(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDeploy", reflect.TypeOf((*MockClient)(nil).GetDeploy), arg0) } -func (_m *MockClient) GetEnvironment(_param0 string) (*models.Environment, error) { - ret := _m.ctrl.Call(_m, "GetEnvironment", _param0) +// GetEnvironment mocks base method +func (m *MockClient) GetEnvironment(arg0 string) (*models.Environment, error) { + ret := m.ctrl.Call(m, "GetEnvironment", arg0) ret0, _ := ret[0].(*models.Environment) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) GetEnvironment(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetEnvironment", arg0) +// GetEnvironment indicates an expected call of GetEnvironment +func (mr *MockClientMockRecorder) GetEnvironment(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEnvironment", reflect.TypeOf((*MockClient)(nil).GetEnvironment), arg0) } -func (_m *MockClient) GetJob(_param0 string) (*models.Job, error) { - ret := _m.ctrl.Call(_m, "GetJob", _param0) +// GetJob mocks base method +func (m *MockClient) GetJob(arg0 string) (*models.Job, error) { + ret := m.ctrl.Call(m, "GetJob", arg0) ret0, _ := ret[0].(*models.Job) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) GetJob(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetJob", arg0) +// GetJob indicates an expected call of GetJob +func (mr *MockClientMockRecorder) GetJob(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetJob", reflect.TypeOf((*MockClient)(nil).GetJob), arg0) } -func (_m *MockClient) GetLoadBalancer(_param0 string) (*models.LoadBalancer, error) { - ret := _m.ctrl.Call(_m, "GetLoadBalancer", _param0) +// GetLoadBalancer mocks base method +func (m *MockClient) GetLoadBalancer(arg0 string) (*models.LoadBalancer, error) { + ret := m.ctrl.Call(m, "GetLoadBalancer", arg0) ret0, _ := ret[0].(*models.LoadBalancer) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) GetLoadBalancer(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetLoadBalancer", arg0) +// GetLoadBalancer indicates an expected call of GetLoadBalancer +func (mr *MockClientMockRecorder) GetLoadBalancer(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLoadBalancer", reflect.TypeOf((*MockClient)(nil).GetLoadBalancer), arg0) } -func (_m *MockClient) GetService(_param0 string) (*models.Service, error) { - ret := _m.ctrl.Call(_m, "GetService", _param0) +// GetService mocks base method +func (m *MockClient) GetService(arg0 string) (*models.Service, error) { + ret := m.ctrl.Call(m, "GetService", arg0) ret0, _ := ret[0].(*models.Service) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) GetService(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetService", arg0) +// GetService indicates an expected call of GetService +func (mr *MockClientMockRecorder) GetService(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetService", reflect.TypeOf((*MockClient)(nil).GetService), arg0) } -func (_m *MockClient) GetServiceLogs(_param0 string, _param1 string, _param2 string, _param3 int) ([]*models.LogFile, error) { - ret := _m.ctrl.Call(_m, "GetServiceLogs", _param0, _param1, _param2, _param3) +// GetServiceLogs mocks base method +func (m *MockClient) GetServiceLogs(arg0, arg1, arg2 string, arg3 int) ([]*models.LogFile, error) { + ret := m.ctrl.Call(m, "GetServiceLogs", arg0, arg1, arg2, arg3) ret0, _ := ret[0].([]*models.LogFile) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) GetServiceLogs(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetServiceLogs", arg0, arg1, arg2, arg3) +// GetServiceLogs indicates an expected call of GetServiceLogs +func (mr *MockClientMockRecorder) GetServiceLogs(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetServiceLogs", reflect.TypeOf((*MockClient)(nil).GetServiceLogs), arg0, arg1, arg2, arg3) } -func (_m *MockClient) GetTask(_param0 string) (*models.Task, error) { - ret := _m.ctrl.Call(_m, "GetTask", _param0) +// GetTask mocks base method +func (m *MockClient) GetTask(arg0 string) (*models.Task, error) { + ret := m.ctrl.Call(m, "GetTask", arg0) ret0, _ := ret[0].(*models.Task) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) GetTask(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetTask", arg0) +// GetTask indicates an expected call of GetTask +func (mr *MockClientMockRecorder) GetTask(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTask", reflect.TypeOf((*MockClient)(nil).GetTask), arg0) } -func (_m *MockClient) GetTaskLogs(_param0 string, _param1 string, _param2 string, _param3 int) ([]*models.LogFile, error) { - ret := _m.ctrl.Call(_m, "GetTaskLogs", _param0, _param1, _param2, _param3) +// GetTaskLogs mocks base method +func (m *MockClient) GetTaskLogs(arg0, arg1, arg2 string, arg3 int) ([]*models.LogFile, error) { + ret := m.ctrl.Call(m, "GetTaskLogs", arg0, arg1, arg2, arg3) ret0, _ := ret[0].([]*models.LogFile) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) GetTaskLogs(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetTaskLogs", arg0, arg1, arg2, arg3) +// GetTaskLogs indicates an expected call of GetTaskLogs +func (mr *MockClientMockRecorder) GetTaskLogs(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTaskLogs", reflect.TypeOf((*MockClient)(nil).GetTaskLogs), arg0, arg1, arg2, arg3) } -func (_m *MockClient) GetVersion() (string, error) { - ret := _m.ctrl.Call(_m, "GetVersion") +// GetVersion mocks base method +func (m *MockClient) GetVersion() (string, error) { + ret := m.ctrl.Call(m, "GetVersion") ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) GetVersion() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetVersion") +// GetVersion indicates an expected call of GetVersion +func (mr *MockClientMockRecorder) GetVersion() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetVersion", reflect.TypeOf((*MockClient)(nil).GetVersion)) } -func (_m *MockClient) ListDeploys() ([]*models.DeploySummary, error) { - ret := _m.ctrl.Call(_m, "ListDeploys") +// ListDeploys mocks base method +func (m *MockClient) ListDeploys() ([]*models.DeploySummary, error) { + ret := m.ctrl.Call(m, "ListDeploys") ret0, _ := ret[0].([]*models.DeploySummary) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) ListDeploys() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListDeploys") +// ListDeploys indicates an expected call of ListDeploys +func (mr *MockClientMockRecorder) ListDeploys() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListDeploys", reflect.TypeOf((*MockClient)(nil).ListDeploys)) } -func (_m *MockClient) ListEnvironments() ([]*models.EnvironmentSummary, error) { - ret := _m.ctrl.Call(_m, "ListEnvironments") +// ListEnvironments mocks base method +func (m *MockClient) ListEnvironments() ([]*models.EnvironmentSummary, error) { + ret := m.ctrl.Call(m, "ListEnvironments") ret0, _ := ret[0].([]*models.EnvironmentSummary) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) ListEnvironments() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListEnvironments") +// ListEnvironments indicates an expected call of ListEnvironments +func (mr *MockClientMockRecorder) ListEnvironments() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListEnvironments", reflect.TypeOf((*MockClient)(nil).ListEnvironments)) } -func (_m *MockClient) ListJobs() ([]*models.Job, error) { - ret := _m.ctrl.Call(_m, "ListJobs") +// ListJobs mocks base method +func (m *MockClient) ListJobs() ([]*models.Job, error) { + ret := m.ctrl.Call(m, "ListJobs") ret0, _ := ret[0].([]*models.Job) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) ListJobs() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListJobs") +// ListJobs indicates an expected call of ListJobs +func (mr *MockClientMockRecorder) ListJobs() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListJobs", reflect.TypeOf((*MockClient)(nil).ListJobs)) } -func (_m *MockClient) ListLoadBalancers() ([]*models.LoadBalancerSummary, error) { - ret := _m.ctrl.Call(_m, "ListLoadBalancers") +// ListLoadBalancers mocks base method +func (m *MockClient) ListLoadBalancers() ([]*models.LoadBalancerSummary, error) { + ret := m.ctrl.Call(m, "ListLoadBalancers") ret0, _ := ret[0].([]*models.LoadBalancerSummary) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) ListLoadBalancers() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListLoadBalancers") +// ListLoadBalancers indicates an expected call of ListLoadBalancers +func (mr *MockClientMockRecorder) ListLoadBalancers() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListLoadBalancers", reflect.TypeOf((*MockClient)(nil).ListLoadBalancers)) } -func (_m *MockClient) ListServices() ([]*models.ServiceSummary, error) { - ret := _m.ctrl.Call(_m, "ListServices") +// ListServices mocks base method +func (m *MockClient) ListServices() ([]*models.ServiceSummary, error) { + ret := m.ctrl.Call(m, "ListServices") ret0, _ := ret[0].([]*models.ServiceSummary) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) ListServices() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListServices") +// ListServices indicates an expected call of ListServices +func (mr *MockClientMockRecorder) ListServices() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListServices", reflect.TypeOf((*MockClient)(nil).ListServices)) } -func (_m *MockClient) ListTasks() ([]*models.TaskSummary, error) { - ret := _m.ctrl.Call(_m, "ListTasks") +// ListTasks mocks base method +func (m *MockClient) ListTasks() ([]*models.TaskSummary, error) { + ret := m.ctrl.Call(m, "ListTasks") ret0, _ := ret[0].([]*models.TaskSummary) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) ListTasks() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListTasks") +// ListTasks indicates an expected call of ListTasks +func (mr *MockClientMockRecorder) ListTasks() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListTasks", reflect.TypeOf((*MockClient)(nil).ListTasks)) } -func (_m *MockClient) RunScaler(_param0 string) (*models.ScalerRunInfo, error) { - ret := _m.ctrl.Call(_m, "RunScaler", _param0) +// RunScaler mocks base method +func (m *MockClient) RunScaler(arg0 string) (*models.ScalerRunInfo, error) { + ret := m.ctrl.Call(m, "RunScaler", arg0) ret0, _ := ret[0].(*models.ScalerRunInfo) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) RunScaler(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "RunScaler", arg0) +// RunScaler indicates an expected call of RunScaler +func (mr *MockClientMockRecorder) RunScaler(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RunScaler", reflect.TypeOf((*MockClient)(nil).RunScaler), arg0) } -func (_m *MockClient) ScaleService(_param0 string, _param1 int) (*models.Service, error) { - ret := _m.ctrl.Call(_m, "ScaleService", _param0, _param1) +// ScaleService mocks base method +func (m *MockClient) ScaleService(arg0 string, arg1 int) (*models.Service, error) { + ret := m.ctrl.Call(m, "ScaleService", arg0, arg1) ret0, _ := ret[0].(*models.Service) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) ScaleService(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ScaleService", arg0, arg1) +// ScaleService indicates an expected call of ScaleService +func (mr *MockClientMockRecorder) ScaleService(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ScaleService", reflect.TypeOf((*MockClient)(nil).ScaleService), arg0, arg1) } -func (_m *MockClient) SelectByQuery(_param0 map[string]string) ([]*models.EntityWithTags, error) { - ret := _m.ctrl.Call(_m, "SelectByQuery", _param0) +// SelectByQuery mocks base method +func (m *MockClient) SelectByQuery(arg0 map[string]string) ([]*models.EntityWithTags, error) { + ret := m.ctrl.Call(m, "SelectByQuery", arg0) ret0, _ := ret[0].([]*models.EntityWithTags) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) SelectByQuery(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "SelectByQuery", arg0) +// SelectByQuery indicates an expected call of SelectByQuery +func (mr *MockClientMockRecorder) SelectByQuery(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SelectByQuery", reflect.TypeOf((*MockClient)(nil).SelectByQuery), arg0) } -func (_m *MockClient) UpdateEnvironment(_param0 string, _param1 int) (*models.Environment, error) { - ret := _m.ctrl.Call(_m, "UpdateEnvironment", _param0, _param1) +// UpdateEnvironment mocks base method +func (m *MockClient) UpdateEnvironment(arg0 string, arg1 int) (*models.Environment, error) { + ret := m.ctrl.Call(m, "UpdateEnvironment", arg0, arg1) ret0, _ := ret[0].(*models.Environment) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) UpdateEnvironment(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "UpdateEnvironment", arg0, arg1) +// UpdateEnvironment indicates an expected call of UpdateEnvironment +func (mr *MockClientMockRecorder) UpdateEnvironment(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateEnvironment", reflect.TypeOf((*MockClient)(nil).UpdateEnvironment), arg0, arg1) } -func (_m *MockClient) UpdateLoadBalancerHealthCheck(_param0 string, _param1 models.HealthCheck) (*models.LoadBalancer, error) { - ret := _m.ctrl.Call(_m, "UpdateLoadBalancerHealthCheck", _param0, _param1) +// UpdateLoadBalancerHealthCheck mocks base method +func (m *MockClient) UpdateLoadBalancerHealthCheck(arg0 string, arg1 models.HealthCheck) (*models.LoadBalancer, error) { + ret := m.ctrl.Call(m, "UpdateLoadBalancerHealthCheck", arg0, arg1) ret0, _ := ret[0].(*models.LoadBalancer) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) UpdateLoadBalancerHealthCheck(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "UpdateLoadBalancerHealthCheck", arg0, arg1) +// UpdateLoadBalancerHealthCheck indicates an expected call of UpdateLoadBalancerHealthCheck +func (mr *MockClientMockRecorder) UpdateLoadBalancerHealthCheck(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateLoadBalancerHealthCheck", reflect.TypeOf((*MockClient)(nil).UpdateLoadBalancerHealthCheck), arg0, arg1) } -func (_m *MockClient) UpdateLoadBalancerPorts(_param0 string, _param1 []models.Port) (*models.LoadBalancer, error) { - ret := _m.ctrl.Call(_m, "UpdateLoadBalancerPorts", _param0, _param1) +// UpdateLoadBalancerPorts mocks base method +func (m *MockClient) UpdateLoadBalancerPorts(arg0 string, arg1 []models.Port) (*models.LoadBalancer, error) { + ret := m.ctrl.Call(m, "UpdateLoadBalancerPorts", arg0, arg1) ret0, _ := ret[0].(*models.LoadBalancer) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) UpdateLoadBalancerPorts(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "UpdateLoadBalancerPorts", arg0, arg1) +// UpdateLoadBalancerPorts indicates an expected call of UpdateLoadBalancerPorts +func (mr *MockClientMockRecorder) UpdateLoadBalancerPorts(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateLoadBalancerPorts", reflect.TypeOf((*MockClient)(nil).UpdateLoadBalancerPorts), arg0, arg1) } -func (_m *MockClient) UpdateSQL() error { - ret := _m.ctrl.Call(_m, "UpdateSQL") +// UpdateSQL mocks base method +func (m *MockClient) UpdateSQL() error { + ret := m.ctrl.Call(m, "UpdateSQL") ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockClientRecorder) UpdateSQL() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "UpdateSQL") +// UpdateSQL indicates an expected call of UpdateSQL +func (mr *MockClientMockRecorder) UpdateSQL() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateSQL", reflect.TypeOf((*MockClient)(nil).UpdateSQL)) } -func (_m *MockClient) UpdateService(_param0 string, _param1 string) (*models.Service, error) { - ret := _m.ctrl.Call(_m, "UpdateService", _param0, _param1) +// UpdateService mocks base method +func (m *MockClient) UpdateService(arg0, arg1 string) (*models.Service, error) { + ret := m.ctrl.Call(m, "UpdateService", arg0, arg1) ret0, _ := ret[0].(*models.Service) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) UpdateService(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "UpdateService", arg0, arg1) +// UpdateService indicates an expected call of UpdateService +func (mr *MockClientMockRecorder) UpdateService(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateService", reflect.TypeOf((*MockClient)(nil).UpdateService), arg0, arg1) } -func (_m *MockClient) WaitForDeployment(_param0 string, _param1 time.Duration) (*models.Service, error) { - ret := _m.ctrl.Call(_m, "WaitForDeployment", _param0, _param1) +// WaitForDeployment mocks base method +func (m *MockClient) WaitForDeployment(arg0 string, arg1 time.Duration) (*models.Service, error) { + ret := m.ctrl.Call(m, "WaitForDeployment", arg0, arg1) ret0, _ := ret[0].(*models.Service) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockClientRecorder) WaitForDeployment(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "WaitForDeployment", arg0, arg1) +// WaitForDeployment indicates an expected call of WaitForDeployment +func (mr *MockClientMockRecorder) WaitForDeployment(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WaitForDeployment", reflect.TypeOf((*MockClient)(nil).WaitForDeployment), arg0, arg1) } -func (_m *MockClient) WaitForJob(_param0 string, _param1 time.Duration) error { - ret := _m.ctrl.Call(_m, "WaitForJob", _param0, _param1) +// WaitForJob mocks base method +func (m *MockClient) WaitForJob(arg0 string, arg1 time.Duration) error { + ret := m.ctrl.Call(m, "WaitForJob", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockClientRecorder) WaitForJob(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "WaitForJob", arg0, arg1) +// WaitForJob indicates an expected call of WaitForJob +func (mr *MockClientMockRecorder) WaitForJob(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WaitForJob", reflect.TypeOf((*MockClient)(nil).WaitForJob), arg0, arg1) } diff --git a/cli/client/task.go b/cli/client/task.go index b1d9bc7c3..682df5f2f 100644 --- a/cli/client/task.go +++ b/cli/client/task.go @@ -12,14 +12,12 @@ func (c *APIClient) CreateTask( name string, environmentID string, deployID string, - copies int, overrides []models.ContainerOverride, ) (string, error) { req := models.CreateTaskRequest{ TaskName: name, EnvironmentID: environmentID, DeployID: deployID, - Copies: copies, ContainerOverrides: overrides, } diff --git a/cli/client/task_test.go b/cli/client/task_test.go index cc316fcce..cd91478a0 100644 --- a/cli/client/task_test.go +++ b/cli/client/task_test.go @@ -24,7 +24,6 @@ func TestCreateTask(t *testing.T) { testutils.AssertEqual(t, req.TaskName, "name") testutils.AssertEqual(t, req.EnvironmentID, "environmentID") testutils.AssertEqual(t, req.DeployID, "deployID") - testutils.AssertEqual(t, req.Copies, 2) testutils.AssertEqual(t, req.ContainerOverrides, overrides) headers := map[string]string{ @@ -38,7 +37,7 @@ func TestCreateTask(t *testing.T) { client, server := newClientAndServer(handler) defer server.Close() - jobID, err := client.CreateTask("name", "environmentID", "deployID", 2, overrides) + jobID, err := client.CreateTask("name", "environmentID", "deployID", overrides) if err != nil { t.Fatal(err) } diff --git a/cli/command/task_command.go b/cli/command/task_command.go index f038f74f0..ac343297c 100644 --- a/cli/command/task_command.go +++ b/cli/command/task_command.go @@ -1,6 +1,7 @@ package command import ( + "fmt" "strings" log "github.com/Sirupsen/logrus" @@ -111,13 +112,22 @@ func (t *TaskCommand) Create(c *cli.Context) error { return err } - jobID, err := t.Client.CreateTask(args["NAME"], environmentID, deployID, c.Int("copies"), overrides) - if err != nil { - return err + if c.Int("copies") < 1 { + return fmt.Errorf("Copies param must be >= 1") + } + + jobIDs := []string{} + for i := 0; i < c.Int("copies"); i++ { + jobID, err := t.Client.CreateTask(args["NAME"], environmentID, deployID, overrides) + if err != nil { + return err + } + + jobIDs = append(jobIDs, jobID) } if !c.Bool("wait") { - t.Printer.Printf("This operation is running as a job. Run `l0 job get %s` to see progress\n", jobID) + t.Printer.Printf("This operation is running as a job. Run `l0 job get %s` to see progress\n", jobIDs[0]) return nil } @@ -127,19 +137,23 @@ func (t *TaskCommand) Create(c *cli.Context) error { } t.Printer.StartSpinner("Creating") - if err := t.Client.WaitForJob(jobID, timeout); err != nil { - return err - } - - job, err := t.Client.GetJob(jobID) - if err != nil { - return err - } taskIDs := []string{} - for key, val := range job.Meta { - if strings.HasPrefix(key, "task_") { - taskIDs = append(taskIDs, val) + for _, jobID := range jobIDs { + if err := t.Client.WaitForJob(jobID, timeout); err != nil { + return err + } + + job, err := t.Client.GetJob(jobID) + if err != nil { + return err + } + + for key, val := range job.Meta { + if key == "task_id" { + taskIDs = append(taskIDs, val) + break + } } } diff --git a/cli/command/task_command_test.go b/cli/command/task_command_test.go index 2b914e45f..6735564a0 100644 --- a/cli/command/task_command_test.go +++ b/cli/command/task_command_test.go @@ -69,12 +69,12 @@ func TestCreateTask(t *testing.T) { }} tc.Client.EXPECT(). - CreateTask("name", "environmentID", "deployID", 2, overrides). + CreateTask("name", "environmentID", "deployID", overrides). Return("jobid", nil) flags := map[string]interface{}{ - "copies": 2, "env": []string{"container:key=val"}, + "copies": 1, } c := testutils.GetCLIContext(t, []string{"environment", "name", "deploy"}, flags) @@ -97,28 +97,42 @@ func TestCreateTaskWait(t *testing.T) { Return([]string{"deployID"}, nil) tc.Client.EXPECT(). - CreateTask("name", "environmentID", "deployID", 0, []models.ContainerOverride{}). - Return("jobid", nil) + CreateTask("name", "environmentID", "deployID", []models.ContainerOverride{}). + Return("job_id1", nil) + + tc.Client.EXPECT(). + WaitForJob("job_id1", gomock.Any()). + Return(nil) tc.Client.EXPECT(). - WaitForJob("jobid", gomock.Any()). + CreateTask("name", "environmentID", "deployID", []models.ContainerOverride{}). + Return("job_id2", nil) + + tc.Client.EXPECT(). + WaitForJob("job_id2", gomock.Any()). Return(nil) - jobMeta := map[string]string{"task_0": "tid0", "task_1": "tid1"} + job1Meta := map[string]string{"task_id": "task_id1"} tc.Client.EXPECT(). - GetJob("jobid"). - Return(&models.Job{Meta: jobMeta}, nil) + GetJob("job_id1"). + Return(&models.Job{Meta: job1Meta}, nil) + job2Meta := map[string]string{"task_id": "task_id2"} tc.Client.EXPECT(). - GetTask("tid0"). + GetJob("job_id2"). + Return(&models.Job{Meta: job2Meta}, nil) + + tc.Client.EXPECT(). + GetTask("task_id1"). Return(&models.Task{}, nil) tc.Client.EXPECT(). - GetTask("tid1"). + GetTask("task_id2"). Return(&models.Task{}, nil) flags := map[string]interface{}{ - "wait": true, + "wait": true, + "copies": 2, } c := testutils.GetCLIContext(t, []string{"environment", "name", "deploy"}, flags) diff --git a/cli/printer/text.go b/cli/printer/text.go index f81fa89f1..b49a8ac6e 100644 --- a/cli/printer/text.go +++ b/cli/printer/text.go @@ -363,15 +363,6 @@ func (t *TextPrinter) PrintTasks(tasks ...*models.Task) error { return t.EnvironmentID } - getScale := func(t *models.Task) string { - scale := fmt.Sprintf("%d/%d", t.RunningCount, t.DesiredCount) - if t.PendingCount != 0 { - scale = fmt.Sprintf("%s (%d)", scale, t.PendingCount) - } - - return scale - } - getDeploy := func(t *models.Task) string { if t.DeployName != "" && t.DeployVersion != "" { return fmt.Sprintf("%s:%s", t.DeployName, t.DeployVersion) @@ -380,7 +371,16 @@ func (t *TextPrinter) PrintTasks(tasks ...*models.Task) error { return strings.Replace(t.DeployID, ".", ":", 1) } - rows := []string{"TASK ID | TASK NAME | ENVIRONMENT | DEPLOY | SCALE "} + getScale := func(t *models.Task) string { + scale := fmt.Sprintf("%d/1", t.RunningCount) + if t.PendingCount != 0 { + scale = fmt.Sprintf("%s (%d)", scale, t.PendingCount) + } + + return scale + } + + rows := []string{"TASK ID | TASK NAME | ENVIRONMENT | DEPLOY | COUNT "} for _, t := range tasks { row := fmt.Sprintf("%s | %s | %s | %s | %s", t.TaskID, diff --git a/cli/printer/text_test.go b/cli/printer/text_test.go index 06df30153..66bb45468 100644 --- a/cli/printer/text_test.go +++ b/cli/printer/text_test.go @@ -358,7 +358,6 @@ func ExampleTextPrintTasks() { EnvironmentID: "eid1", EnvironmentName: "ename1", RunningCount: 1, - DesiredCount: 1, DeployName: "d1", DeployVersion: "1", }, @@ -367,7 +366,6 @@ func ExampleTextPrintTasks() { TaskName: "tsk2", EnvironmentID: "eid2", RunningCount: 1, - DesiredCount: 1, DeployID: "d2.1", }, { @@ -375,7 +373,6 @@ func ExampleTextPrintTasks() { TaskName: "tsk3", EnvironmentID: "eid3", RunningCount: 0, - DesiredCount: 1, PendingCount: 1, DeployID: "d3.1", }, @@ -384,18 +381,17 @@ func ExampleTextPrintTasks() { TaskName: "tsk4", EnvironmentID: "eid4", RunningCount: 1, - DesiredCount: 0, DeployID: "d4.1", }, } printer.PrintTasks(tasks...) // Output: - // TASK ID TASK NAME ENVIRONMENT DEPLOY SCALE + // TASK ID TASK NAME ENVIRONMENT DEPLOY COUNT // id1 tsk1 ename1 d1:1 1/1 // id2 tsk2 eid2 d2:1 1/1 // id3 tsk3 eid3 d3:1 0/1 (1) - // id4 tsk4 eid4 d4:1 1/0 + // id4 tsk4 eid4 d4:1 1/1 } func ExampleTextPrintTaskSummaries() { diff --git a/common/aws/autoscaling/mock_autoscaling/mock_autoscaling.go b/common/aws/autoscaling/mock_autoscaling/mock_autoscaling.go index 7e827f791..03864dd09 100644 --- a/common/aws/autoscaling/mock_autoscaling/mock_autoscaling.go +++ b/common/aws/autoscaling/mock_autoscaling/mock_autoscaling.go @@ -1,165 +1,196 @@ -// Automatically generated by MockGen. DO NOT EDIT! +// Code generated by MockGen. DO NOT EDIT. // Source: github.com/quintilesims/layer0/common/aws/autoscaling (interfaces: Provider) +// Package mock_autoscaling is a generated GoMock package. package mock_autoscaling import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" autoscaling "github.com/quintilesims/layer0/common/aws/autoscaling" ) -// Mock of Provider interface +// MockProvider is a mock of Provider interface type MockProvider struct { ctrl *gomock.Controller - recorder *_MockProviderRecorder + recorder *MockProviderMockRecorder } -// Recorder for MockProvider (not exported) -type _MockProviderRecorder struct { +// MockProviderMockRecorder is the mock recorder for MockProvider +type MockProviderMockRecorder struct { mock *MockProvider } +// NewMockProvider creates a new mock instance func NewMockProvider(ctrl *gomock.Controller) *MockProvider { mock := &MockProvider{ctrl: ctrl} - mock.recorder = &_MockProviderRecorder{mock} + mock.recorder = &MockProviderMockRecorder{mock} return mock } -func (_m *MockProvider) EXPECT() *_MockProviderRecorder { - return _m.recorder +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockProvider) EXPECT() *MockProviderMockRecorder { + return m.recorder } -func (_m *MockProvider) AttachLoadBalancer(_param0 string, _param1 string) error { - ret := _m.ctrl.Call(_m, "AttachLoadBalancer", _param0, _param1) +// AttachLoadBalancer mocks base method +func (m *MockProvider) AttachLoadBalancer(arg0, arg1 string) error { + ret := m.ctrl.Call(m, "AttachLoadBalancer", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) AttachLoadBalancer(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "AttachLoadBalancer", arg0, arg1) +// AttachLoadBalancer indicates an expected call of AttachLoadBalancer +func (mr *MockProviderMockRecorder) AttachLoadBalancer(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AttachLoadBalancer", reflect.TypeOf((*MockProvider)(nil).AttachLoadBalancer), arg0, arg1) } -func (_m *MockProvider) CreateAutoScalingGroup(_param0 string, _param1 string, _param2 string, _param3 int, _param4 int) error { - ret := _m.ctrl.Call(_m, "CreateAutoScalingGroup", _param0, _param1, _param2, _param3, _param4) +// CreateAutoScalingGroup mocks base method +func (m *MockProvider) CreateAutoScalingGroup(arg0, arg1, arg2 string, arg3, arg4 int) error { + ret := m.ctrl.Call(m, "CreateAutoScalingGroup", arg0, arg1, arg2, arg3, arg4) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) CreateAutoScalingGroup(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateAutoScalingGroup", arg0, arg1, arg2, arg3, arg4) +// CreateAutoScalingGroup indicates an expected call of CreateAutoScalingGroup +func (mr *MockProviderMockRecorder) CreateAutoScalingGroup(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateAutoScalingGroup", reflect.TypeOf((*MockProvider)(nil).CreateAutoScalingGroup), arg0, arg1, arg2, arg3, arg4) } -func (_m *MockProvider) CreateLaunchConfiguration(_param0 *string, _param1 *string, _param2 *string, _param3 *string, _param4 *string, _param5 *string, _param6 []*string, _param7 map[string]int) error { - ret := _m.ctrl.Call(_m, "CreateLaunchConfiguration", _param0, _param1, _param2, _param3, _param4, _param5, _param6, _param7) +// CreateLaunchConfiguration mocks base method +func (m *MockProvider) CreateLaunchConfiguration(arg0, arg1, arg2, arg3, arg4, arg5 *string, arg6 []*string, arg7 map[string]int) error { + ret := m.ctrl.Call(m, "CreateLaunchConfiguration", arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) CreateLaunchConfiguration(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateLaunchConfiguration", arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) +// CreateLaunchConfiguration indicates an expected call of CreateLaunchConfiguration +func (mr *MockProviderMockRecorder) CreateLaunchConfiguration(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateLaunchConfiguration", reflect.TypeOf((*MockProvider)(nil).CreateLaunchConfiguration), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) } -func (_m *MockProvider) DeleteAutoScalingGroup(_param0 *string) error { - ret := _m.ctrl.Call(_m, "DeleteAutoScalingGroup", _param0) +// DeleteAutoScalingGroup mocks base method +func (m *MockProvider) DeleteAutoScalingGroup(arg0 *string) error { + ret := m.ctrl.Call(m, "DeleteAutoScalingGroup", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) DeleteAutoScalingGroup(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteAutoScalingGroup", arg0) +// DeleteAutoScalingGroup indicates an expected call of DeleteAutoScalingGroup +func (mr *MockProviderMockRecorder) DeleteAutoScalingGroup(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteAutoScalingGroup", reflect.TypeOf((*MockProvider)(nil).DeleteAutoScalingGroup), arg0) } -func (_m *MockProvider) DeleteLaunchConfiguration(_param0 *string) error { - ret := _m.ctrl.Call(_m, "DeleteLaunchConfiguration", _param0) +// DeleteLaunchConfiguration mocks base method +func (m *MockProvider) DeleteLaunchConfiguration(arg0 *string) error { + ret := m.ctrl.Call(m, "DeleteLaunchConfiguration", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) DeleteLaunchConfiguration(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteLaunchConfiguration", arg0) +// DeleteLaunchConfiguration indicates an expected call of DeleteLaunchConfiguration +func (mr *MockProviderMockRecorder) DeleteLaunchConfiguration(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteLaunchConfiguration", reflect.TypeOf((*MockProvider)(nil).DeleteLaunchConfiguration), arg0) } -func (_m *MockProvider) DescribeAutoScalingGroup(_param0 string) (*autoscaling.Group, error) { - ret := _m.ctrl.Call(_m, "DescribeAutoScalingGroup", _param0) +// DescribeAutoScalingGroup mocks base method +func (m *MockProvider) DescribeAutoScalingGroup(arg0 string) (*autoscaling.Group, error) { + ret := m.ctrl.Call(m, "DescribeAutoScalingGroup", arg0) ret0, _ := ret[0].(*autoscaling.Group) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) DescribeAutoScalingGroup(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DescribeAutoScalingGroup", arg0) +// DescribeAutoScalingGroup indicates an expected call of DescribeAutoScalingGroup +func (mr *MockProviderMockRecorder) DescribeAutoScalingGroup(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeAutoScalingGroup", reflect.TypeOf((*MockProvider)(nil).DescribeAutoScalingGroup), arg0) } -func (_m *MockProvider) DescribeAutoScalingGroups(_param0 []*string) ([]*autoscaling.Group, error) { - ret := _m.ctrl.Call(_m, "DescribeAutoScalingGroups", _param0) +// DescribeAutoScalingGroups mocks base method +func (m *MockProvider) DescribeAutoScalingGroups(arg0 []*string) ([]*autoscaling.Group, error) { + ret := m.ctrl.Call(m, "DescribeAutoScalingGroups", arg0) ret0, _ := ret[0].([]*autoscaling.Group) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) DescribeAutoScalingGroups(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DescribeAutoScalingGroups", arg0) +// DescribeAutoScalingGroups indicates an expected call of DescribeAutoScalingGroups +func (mr *MockProviderMockRecorder) DescribeAutoScalingGroups(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeAutoScalingGroups", reflect.TypeOf((*MockProvider)(nil).DescribeAutoScalingGroups), arg0) } -func (_m *MockProvider) DescribeLaunchConfiguration(_param0 string) (*autoscaling.LaunchConfiguration, error) { - ret := _m.ctrl.Call(_m, "DescribeLaunchConfiguration", _param0) +// DescribeLaunchConfiguration mocks base method +func (m *MockProvider) DescribeLaunchConfiguration(arg0 string) (*autoscaling.LaunchConfiguration, error) { + ret := m.ctrl.Call(m, "DescribeLaunchConfiguration", arg0) ret0, _ := ret[0].(*autoscaling.LaunchConfiguration) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) DescribeLaunchConfiguration(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DescribeLaunchConfiguration", arg0) +// DescribeLaunchConfiguration indicates an expected call of DescribeLaunchConfiguration +func (mr *MockProviderMockRecorder) DescribeLaunchConfiguration(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeLaunchConfiguration", reflect.TypeOf((*MockProvider)(nil).DescribeLaunchConfiguration), arg0) } -func (_m *MockProvider) DescribeLaunchConfigurations(_param0 []*string) ([]*autoscaling.LaunchConfiguration, error) { - ret := _m.ctrl.Call(_m, "DescribeLaunchConfigurations", _param0) +// DescribeLaunchConfigurations mocks base method +func (m *MockProvider) DescribeLaunchConfigurations(arg0 []*string) ([]*autoscaling.LaunchConfiguration, error) { + ret := m.ctrl.Call(m, "DescribeLaunchConfigurations", arg0) ret0, _ := ret[0].([]*autoscaling.LaunchConfiguration) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) DescribeLaunchConfigurations(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DescribeLaunchConfigurations", arg0) +// DescribeLaunchConfigurations indicates an expected call of DescribeLaunchConfigurations +func (mr *MockProviderMockRecorder) DescribeLaunchConfigurations(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeLaunchConfigurations", reflect.TypeOf((*MockProvider)(nil).DescribeLaunchConfigurations), arg0) } -func (_m *MockProvider) SetDesiredCapacity(_param0 string, _param1 int) error { - ret := _m.ctrl.Call(_m, "SetDesiredCapacity", _param0, _param1) +// SetDesiredCapacity mocks base method +func (m *MockProvider) SetDesiredCapacity(arg0 string, arg1 int) error { + ret := m.ctrl.Call(m, "SetDesiredCapacity", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) SetDesiredCapacity(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "SetDesiredCapacity", arg0, arg1) +// SetDesiredCapacity indicates an expected call of SetDesiredCapacity +func (mr *MockProviderMockRecorder) SetDesiredCapacity(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetDesiredCapacity", reflect.TypeOf((*MockProvider)(nil).SetDesiredCapacity), arg0, arg1) } -func (_m *MockProvider) TerminateInstanceInAutoScalingGroup(_param0 string, _param1 bool) (*autoscaling.Activity, error) { - ret := _m.ctrl.Call(_m, "TerminateInstanceInAutoScalingGroup", _param0, _param1) +// TerminateInstanceInAutoScalingGroup mocks base method +func (m *MockProvider) TerminateInstanceInAutoScalingGroup(arg0 string, arg1 bool) (*autoscaling.Activity, error) { + ret := m.ctrl.Call(m, "TerminateInstanceInAutoScalingGroup", arg0, arg1) ret0, _ := ret[0].(*autoscaling.Activity) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) TerminateInstanceInAutoScalingGroup(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "TerminateInstanceInAutoScalingGroup", arg0, arg1) +// TerminateInstanceInAutoScalingGroup indicates an expected call of TerminateInstanceInAutoScalingGroup +func (mr *MockProviderMockRecorder) TerminateInstanceInAutoScalingGroup(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TerminateInstanceInAutoScalingGroup", reflect.TypeOf((*MockProvider)(nil).TerminateInstanceInAutoScalingGroup), arg0, arg1) } -func (_m *MockProvider) UpdateAutoScalingGroupMaxSize(_param0 string, _param1 int) error { - ret := _m.ctrl.Call(_m, "UpdateAutoScalingGroupMaxSize", _param0, _param1) +// UpdateAutoScalingGroupMaxSize mocks base method +func (m *MockProvider) UpdateAutoScalingGroupMaxSize(arg0 string, arg1 int) error { + ret := m.ctrl.Call(m, "UpdateAutoScalingGroupMaxSize", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) UpdateAutoScalingGroupMaxSize(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "UpdateAutoScalingGroupMaxSize", arg0, arg1) +// UpdateAutoScalingGroupMaxSize indicates an expected call of UpdateAutoScalingGroupMaxSize +func (mr *MockProviderMockRecorder) UpdateAutoScalingGroupMaxSize(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateAutoScalingGroupMaxSize", reflect.TypeOf((*MockProvider)(nil).UpdateAutoScalingGroupMaxSize), arg0, arg1) } -func (_m *MockProvider) UpdateAutoScalingGroupMinSize(_param0 string, _param1 int) error { - ret := _m.ctrl.Call(_m, "UpdateAutoScalingGroupMinSize", _param0, _param1) +// UpdateAutoScalingGroupMinSize mocks base method +func (m *MockProvider) UpdateAutoScalingGroupMinSize(arg0 string, arg1 int) error { + ret := m.ctrl.Call(m, "UpdateAutoScalingGroupMinSize", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) UpdateAutoScalingGroupMinSize(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "UpdateAutoScalingGroupMinSize", arg0, arg1) +// UpdateAutoScalingGroupMinSize indicates an expected call of UpdateAutoScalingGroupMinSize +func (mr *MockProviderMockRecorder) UpdateAutoScalingGroupMinSize(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateAutoScalingGroupMinSize", reflect.TypeOf((*MockProvider)(nil).UpdateAutoScalingGroupMinSize), arg0, arg1) } diff --git a/common/aws/cloudwatchlogs/mock_cloudwatchlogs/mock_cloudwatchlogs.go b/common/aws/cloudwatchlogs/mock_cloudwatchlogs/mock_cloudwatchlogs.go index 1ba51970f..df128726c 100644 --- a/common/aws/cloudwatchlogs/mock_cloudwatchlogs/mock_cloudwatchlogs.go +++ b/common/aws/cloudwatchlogs/mock_cloudwatchlogs/mock_cloudwatchlogs.go @@ -1,95 +1,112 @@ -// Automatically generated by MockGen. DO NOT EDIT! +// Code generated by MockGen. DO NOT EDIT. // Source: github.com/quintilesims/layer0/common/aws/cloudwatchlogs (interfaces: Provider) +// Package mock_cloudwatchlogs is a generated GoMock package. package mock_cloudwatchlogs import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" cloudwatchlogs "github.com/quintilesims/layer0/common/aws/cloudwatchlogs" ) -// Mock of Provider interface +// MockProvider is a mock of Provider interface type MockProvider struct { ctrl *gomock.Controller - recorder *_MockProviderRecorder + recorder *MockProviderMockRecorder } -// Recorder for MockProvider (not exported) -type _MockProviderRecorder struct { +// MockProviderMockRecorder is the mock recorder for MockProvider +type MockProviderMockRecorder struct { mock *MockProvider } +// NewMockProvider creates a new mock instance func NewMockProvider(ctrl *gomock.Controller) *MockProvider { mock := &MockProvider{ctrl: ctrl} - mock.recorder = &_MockProviderRecorder{mock} + mock.recorder = &MockProviderMockRecorder{mock} return mock } -func (_m *MockProvider) EXPECT() *_MockProviderRecorder { - return _m.recorder +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockProvider) EXPECT() *MockProviderMockRecorder { + return m.recorder } -func (_m *MockProvider) CreateLogGroup(_param0 string) error { - ret := _m.ctrl.Call(_m, "CreateLogGroup", _param0) +// CreateLogGroup mocks base method +func (m *MockProvider) CreateLogGroup(arg0 string) error { + ret := m.ctrl.Call(m, "CreateLogGroup", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) CreateLogGroup(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateLogGroup", arg0) +// CreateLogGroup indicates an expected call of CreateLogGroup +func (mr *MockProviderMockRecorder) CreateLogGroup(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateLogGroup", reflect.TypeOf((*MockProvider)(nil).CreateLogGroup), arg0) } -func (_m *MockProvider) DeleteLogGroup(_param0 string) error { - ret := _m.ctrl.Call(_m, "DeleteLogGroup", _param0) +// DeleteLogGroup mocks base method +func (m *MockProvider) DeleteLogGroup(arg0 string) error { + ret := m.ctrl.Call(m, "DeleteLogGroup", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) DeleteLogGroup(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteLogGroup", arg0) +// DeleteLogGroup indicates an expected call of DeleteLogGroup +func (mr *MockProviderMockRecorder) DeleteLogGroup(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteLogGroup", reflect.TypeOf((*MockProvider)(nil).DeleteLogGroup), arg0) } -func (_m *MockProvider) DescribeLogGroups(_param0 string, _param1 *string) ([]*cloudwatchlogs.LogGroup, error) { - ret := _m.ctrl.Call(_m, "DescribeLogGroups", _param0, _param1) +// DescribeLogGroups mocks base method +func (m *MockProvider) DescribeLogGroups(arg0 string, arg1 *string) ([]*cloudwatchlogs.LogGroup, error) { + ret := m.ctrl.Call(m, "DescribeLogGroups", arg0, arg1) ret0, _ := ret[0].([]*cloudwatchlogs.LogGroup) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) DescribeLogGroups(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DescribeLogGroups", arg0, arg1) +// DescribeLogGroups indicates an expected call of DescribeLogGroups +func (mr *MockProviderMockRecorder) DescribeLogGroups(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeLogGroups", reflect.TypeOf((*MockProvider)(nil).DescribeLogGroups), arg0, arg1) } -func (_m *MockProvider) DescribeLogStreams(_param0 string, _param1 string) ([]*cloudwatchlogs.LogStream, error) { - ret := _m.ctrl.Call(_m, "DescribeLogStreams", _param0, _param1) +// DescribeLogStreams mocks base method +func (m *MockProvider) DescribeLogStreams(arg0, arg1 string) ([]*cloudwatchlogs.LogStream, error) { + ret := m.ctrl.Call(m, "DescribeLogStreams", arg0, arg1) ret0, _ := ret[0].([]*cloudwatchlogs.LogStream) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) DescribeLogStreams(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DescribeLogStreams", arg0, arg1) +// DescribeLogStreams indicates an expected call of DescribeLogStreams +func (mr *MockProviderMockRecorder) DescribeLogStreams(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeLogStreams", reflect.TypeOf((*MockProvider)(nil).DescribeLogStreams), arg0, arg1) } -func (_m *MockProvider) FilterLogEvents(_param0 *string, _param1 *string, _param2 *string, _param3 []*string, _param4 *int64, _param5 *int64, _param6 *bool) ([]*cloudwatchlogs.FilteredLogEvent, []*cloudwatchlogs.SearchedLogStream, error) { - ret := _m.ctrl.Call(_m, "FilterLogEvents", _param0, _param1, _param2, _param3, _param4, _param5, _param6) +// FilterLogEvents mocks base method +func (m *MockProvider) FilterLogEvents(arg0, arg1, arg2 *string, arg3 []*string, arg4, arg5 *int64, arg6 *bool) ([]*cloudwatchlogs.FilteredLogEvent, []*cloudwatchlogs.SearchedLogStream, error) { + ret := m.ctrl.Call(m, "FilterLogEvents", arg0, arg1, arg2, arg3, arg4, arg5, arg6) ret0, _ := ret[0].([]*cloudwatchlogs.FilteredLogEvent) ret1, _ := ret[1].([]*cloudwatchlogs.SearchedLogStream) ret2, _ := ret[2].(error) return ret0, ret1, ret2 } -func (_mr *_MockProviderRecorder) FilterLogEvents(arg0, arg1, arg2, arg3, arg4, arg5, arg6 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "FilterLogEvents", arg0, arg1, arg2, arg3, arg4, arg5, arg6) +// FilterLogEvents indicates an expected call of FilterLogEvents +func (mr *MockProviderMockRecorder) FilterLogEvents(arg0, arg1, arg2, arg3, arg4, arg5, arg6 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FilterLogEvents", reflect.TypeOf((*MockProvider)(nil).FilterLogEvents), arg0, arg1, arg2, arg3, arg4, arg5, arg6) } -func (_m *MockProvider) GetLogEvents(_param0 string, _param1 string, _param2 string, _param3 string, _param4 int64) ([]*cloudwatchlogs.OutputLogEvent, error) { - ret := _m.ctrl.Call(_m, "GetLogEvents", _param0, _param1, _param2, _param3, _param4) +// GetLogEvents mocks base method +func (m *MockProvider) GetLogEvents(arg0, arg1, arg2, arg3 string, arg4 int64) ([]*cloudwatchlogs.OutputLogEvent, error) { + ret := m.ctrl.Call(m, "GetLogEvents", arg0, arg1, arg2, arg3, arg4) ret0, _ := ret[0].([]*cloudwatchlogs.OutputLogEvent) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) GetLogEvents(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetLogEvents", arg0, arg1, arg2, arg3, arg4) +// GetLogEvents indicates an expected call of GetLogEvents +func (mr *MockProviderMockRecorder) GetLogEvents(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLogEvents", reflect.TypeOf((*MockProvider)(nil).GetLogEvents), arg0, arg1, arg2, arg3, arg4) } diff --git a/common/aws/ec2/mock_ec2/mock_ec2.go b/common/aws/ec2/mock_ec2/mock_ec2.go index a30d706c4..513782dc2 100644 --- a/common/aws/ec2/mock_ec2/mock_ec2.go +++ b/common/aws/ec2/mock_ec2/mock_ec2.go @@ -1,179 +1,212 @@ -// Automatically generated by MockGen. DO NOT EDIT! +// Code generated by MockGen. DO NOT EDIT. // Source: github.com/quintilesims/layer0/common/aws/ec2 (interfaces: Provider) +// Package mock_ec2 is a generated GoMock package. package mock_ec2 import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" ec2 "github.com/quintilesims/layer0/common/aws/ec2" ) -// Mock of Provider interface +// MockProvider is a mock of Provider interface type MockProvider struct { ctrl *gomock.Controller - recorder *_MockProviderRecorder + recorder *MockProviderMockRecorder } -// Recorder for MockProvider (not exported) -type _MockProviderRecorder struct { +// MockProviderMockRecorder is the mock recorder for MockProvider +type MockProviderMockRecorder struct { mock *MockProvider } +// NewMockProvider creates a new mock instance func NewMockProvider(ctrl *gomock.Controller) *MockProvider { mock := &MockProvider{ctrl: ctrl} - mock.recorder = &_MockProviderRecorder{mock} + mock.recorder = &MockProviderMockRecorder{mock} return mock } -func (_m *MockProvider) EXPECT() *_MockProviderRecorder { - return _m.recorder +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockProvider) EXPECT() *MockProviderMockRecorder { + return m.recorder } -func (_m *MockProvider) AuthorizeSecurityGroupIngress(_param0 []*ec2.SecurityGroupIngress) error { - ret := _m.ctrl.Call(_m, "AuthorizeSecurityGroupIngress", _param0) +// AuthorizeSecurityGroupIngress mocks base method +func (m *MockProvider) AuthorizeSecurityGroupIngress(arg0 []*ec2.SecurityGroupIngress) error { + ret := m.ctrl.Call(m, "AuthorizeSecurityGroupIngress", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) AuthorizeSecurityGroupIngress(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "AuthorizeSecurityGroupIngress", arg0) +// AuthorizeSecurityGroupIngress indicates an expected call of AuthorizeSecurityGroupIngress +func (mr *MockProviderMockRecorder) AuthorizeSecurityGroupIngress(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AuthorizeSecurityGroupIngress", reflect.TypeOf((*MockProvider)(nil).AuthorizeSecurityGroupIngress), arg0) } -func (_m *MockProvider) AuthorizeSecurityGroupIngressFromGroup(_param0 string, _param1 string) error { - ret := _m.ctrl.Call(_m, "AuthorizeSecurityGroupIngressFromGroup", _param0, _param1) +// AuthorizeSecurityGroupIngressFromGroup mocks base method +func (m *MockProvider) AuthorizeSecurityGroupIngressFromGroup(arg0, arg1 string) error { + ret := m.ctrl.Call(m, "AuthorizeSecurityGroupIngressFromGroup", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) AuthorizeSecurityGroupIngressFromGroup(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "AuthorizeSecurityGroupIngressFromGroup", arg0, arg1) +// AuthorizeSecurityGroupIngressFromGroup indicates an expected call of AuthorizeSecurityGroupIngressFromGroup +func (mr *MockProviderMockRecorder) AuthorizeSecurityGroupIngressFromGroup(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AuthorizeSecurityGroupIngressFromGroup", reflect.TypeOf((*MockProvider)(nil).AuthorizeSecurityGroupIngressFromGroup), arg0, arg1) } -func (_m *MockProvider) CreateSecurityGroup(_param0 string, _param1 string, _param2 string) (*string, error) { - ret := _m.ctrl.Call(_m, "CreateSecurityGroup", _param0, _param1, _param2) +// CreateSecurityGroup mocks base method +func (m *MockProvider) CreateSecurityGroup(arg0, arg1, arg2 string) (*string, error) { + ret := m.ctrl.Call(m, "CreateSecurityGroup", arg0, arg1, arg2) ret0, _ := ret[0].(*string) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) CreateSecurityGroup(arg0, arg1, arg2 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateSecurityGroup", arg0, arg1, arg2) +// CreateSecurityGroup indicates an expected call of CreateSecurityGroup +func (mr *MockProviderMockRecorder) CreateSecurityGroup(arg0, arg1, arg2 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateSecurityGroup", reflect.TypeOf((*MockProvider)(nil).CreateSecurityGroup), arg0, arg1, arg2) } -func (_m *MockProvider) DeleteSecurityGroup(_param0 *ec2.SecurityGroup) error { - ret := _m.ctrl.Call(_m, "DeleteSecurityGroup", _param0) +// DeleteSecurityGroup mocks base method +func (m *MockProvider) DeleteSecurityGroup(arg0 *ec2.SecurityGroup) error { + ret := m.ctrl.Call(m, "DeleteSecurityGroup", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) DeleteSecurityGroup(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteSecurityGroup", arg0) +// DeleteSecurityGroup indicates an expected call of DeleteSecurityGroup +func (mr *MockProviderMockRecorder) DeleteSecurityGroup(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteSecurityGroup", reflect.TypeOf((*MockProvider)(nil).DeleteSecurityGroup), arg0) } -func (_m *MockProvider) DescribeInstance(_param0 string) (*ec2.Instance, error) { - ret := _m.ctrl.Call(_m, "DescribeInstance", _param0) +// DescribeInstance mocks base method +func (m *MockProvider) DescribeInstance(arg0 string) (*ec2.Instance, error) { + ret := m.ctrl.Call(m, "DescribeInstance", arg0) ret0, _ := ret[0].(*ec2.Instance) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) DescribeInstance(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DescribeInstance", arg0) +// DescribeInstance indicates an expected call of DescribeInstance +func (mr *MockProviderMockRecorder) DescribeInstance(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeInstance", reflect.TypeOf((*MockProvider)(nil).DescribeInstance), arg0) } -func (_m *MockProvider) DescribeSecurityGroup(_param0 string) (*ec2.SecurityGroup, error) { - ret := _m.ctrl.Call(_m, "DescribeSecurityGroup", _param0) +// DescribeSecurityGroup mocks base method +func (m *MockProvider) DescribeSecurityGroup(arg0 string) (*ec2.SecurityGroup, error) { + ret := m.ctrl.Call(m, "DescribeSecurityGroup", arg0) ret0, _ := ret[0].(*ec2.SecurityGroup) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) DescribeSecurityGroup(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DescribeSecurityGroup", arg0) +// DescribeSecurityGroup indicates an expected call of DescribeSecurityGroup +func (mr *MockProviderMockRecorder) DescribeSecurityGroup(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeSecurityGroup", reflect.TypeOf((*MockProvider)(nil).DescribeSecurityGroup), arg0) } -func (_m *MockProvider) DescribeSubnet(_param0 string) (*ec2.Subnet, error) { - ret := _m.ctrl.Call(_m, "DescribeSubnet", _param0) +// DescribeSubnet mocks base method +func (m *MockProvider) DescribeSubnet(arg0 string) (*ec2.Subnet, error) { + ret := m.ctrl.Call(m, "DescribeSubnet", arg0) ret0, _ := ret[0].(*ec2.Subnet) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) DescribeSubnet(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DescribeSubnet", arg0) +// DescribeSubnet indicates an expected call of DescribeSubnet +func (mr *MockProviderMockRecorder) DescribeSubnet(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeSubnet", reflect.TypeOf((*MockProvider)(nil).DescribeSubnet), arg0) } -func (_m *MockProvider) DescribeVPC(_param0 string) (*ec2.VPC, error) { - ret := _m.ctrl.Call(_m, "DescribeVPC", _param0) +// DescribeVPC mocks base method +func (m *MockProvider) DescribeVPC(arg0 string) (*ec2.VPC, error) { + ret := m.ctrl.Call(m, "DescribeVPC", arg0) ret0, _ := ret[0].(*ec2.VPC) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) DescribeVPC(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DescribeVPC", arg0) +// DescribeVPC indicates an expected call of DescribeVPC +func (mr *MockProviderMockRecorder) DescribeVPC(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeVPC", reflect.TypeOf((*MockProvider)(nil).DescribeVPC), arg0) } -func (_m *MockProvider) DescribeVPCByName(_param0 string) (*ec2.VPC, error) { - ret := _m.ctrl.Call(_m, "DescribeVPCByName", _param0) +// DescribeVPCByName mocks base method +func (m *MockProvider) DescribeVPCByName(arg0 string) (*ec2.VPC, error) { + ret := m.ctrl.Call(m, "DescribeVPCByName", arg0) ret0, _ := ret[0].(*ec2.VPC) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) DescribeVPCByName(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DescribeVPCByName", arg0) +// DescribeVPCByName indicates an expected call of DescribeVPCByName +func (mr *MockProviderMockRecorder) DescribeVPCByName(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeVPCByName", reflect.TypeOf((*MockProvider)(nil).DescribeVPCByName), arg0) } -func (_m *MockProvider) DescribeVPCGateways(_param0 string) ([]*ec2.InternetGateway, error) { - ret := _m.ctrl.Call(_m, "DescribeVPCGateways", _param0) +// DescribeVPCGateways mocks base method +func (m *MockProvider) DescribeVPCGateways(arg0 string) ([]*ec2.InternetGateway, error) { + ret := m.ctrl.Call(m, "DescribeVPCGateways", arg0) ret0, _ := ret[0].([]*ec2.InternetGateway) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) DescribeVPCGateways(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DescribeVPCGateways", arg0) +// DescribeVPCGateways indicates an expected call of DescribeVPCGateways +func (mr *MockProviderMockRecorder) DescribeVPCGateways(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeVPCGateways", reflect.TypeOf((*MockProvider)(nil).DescribeVPCGateways), arg0) } -func (_m *MockProvider) DescribeVPCRoutes(_param0 string) ([]*ec2.RouteTable, error) { - ret := _m.ctrl.Call(_m, "DescribeVPCRoutes", _param0) +// DescribeVPCRoutes mocks base method +func (m *MockProvider) DescribeVPCRoutes(arg0 string) ([]*ec2.RouteTable, error) { + ret := m.ctrl.Call(m, "DescribeVPCRoutes", arg0) ret0, _ := ret[0].([]*ec2.RouteTable) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) DescribeVPCRoutes(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DescribeVPCRoutes", arg0) +// DescribeVPCRoutes indicates an expected call of DescribeVPCRoutes +func (mr *MockProviderMockRecorder) DescribeVPCRoutes(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeVPCRoutes", reflect.TypeOf((*MockProvider)(nil).DescribeVPCRoutes), arg0) } -func (_m *MockProvider) DescribeVPCSubnets(_param0 string) ([]*ec2.Subnet, error) { - ret := _m.ctrl.Call(_m, "DescribeVPCSubnets", _param0) +// DescribeVPCSubnets mocks base method +func (m *MockProvider) DescribeVPCSubnets(arg0 string) ([]*ec2.Subnet, error) { + ret := m.ctrl.Call(m, "DescribeVPCSubnets", arg0) ret0, _ := ret[0].([]*ec2.Subnet) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) DescribeVPCSubnets(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DescribeVPCSubnets", arg0) +// DescribeVPCSubnets indicates an expected call of DescribeVPCSubnets +func (mr *MockProviderMockRecorder) DescribeVPCSubnets(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeVPCSubnets", reflect.TypeOf((*MockProvider)(nil).DescribeVPCSubnets), arg0) } -func (_m *MockProvider) RevokeSecurityGroupIngress(_param0 []*ec2.SecurityGroupIngress) error { - ret := _m.ctrl.Call(_m, "RevokeSecurityGroupIngress", _param0) +// RevokeSecurityGroupIngress mocks base method +func (m *MockProvider) RevokeSecurityGroupIngress(arg0 []*ec2.SecurityGroupIngress) error { + ret := m.ctrl.Call(m, "RevokeSecurityGroupIngress", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) RevokeSecurityGroupIngress(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "RevokeSecurityGroupIngress", arg0) +// RevokeSecurityGroupIngress indicates an expected call of RevokeSecurityGroupIngress +func (mr *MockProviderMockRecorder) RevokeSecurityGroupIngress(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RevokeSecurityGroupIngress", reflect.TypeOf((*MockProvider)(nil).RevokeSecurityGroupIngress), arg0) } -func (_m *MockProvider) RevokeSecurityGroupIngressHelper(_param0 string, _param1 ec2.IpPermission) error { - ret := _m.ctrl.Call(_m, "RevokeSecurityGroupIngressHelper", _param0, _param1) +// RevokeSecurityGroupIngressHelper mocks base method +func (m *MockProvider) RevokeSecurityGroupIngressHelper(arg0 string, arg1 ec2.IpPermission) error { + ret := m.ctrl.Call(m, "RevokeSecurityGroupIngressHelper", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) RevokeSecurityGroupIngressHelper(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "RevokeSecurityGroupIngressHelper", arg0, arg1) +// RevokeSecurityGroupIngressHelper indicates an expected call of RevokeSecurityGroupIngressHelper +func (mr *MockProviderMockRecorder) RevokeSecurityGroupIngressHelper(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RevokeSecurityGroupIngressHelper", reflect.TypeOf((*MockProvider)(nil).RevokeSecurityGroupIngressHelper), arg0, arg1) } diff --git a/common/aws/ecs/ecs.go b/common/aws/ecs/ecs.go index 24a1ce28a..c69a877bf 100644 --- a/common/aws/ecs/ecs.go +++ b/common/aws/ecs/ecs.go @@ -5,11 +5,15 @@ import ( "strings" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/ecs" "github.com/quintilesims/layer0/common/aws/provider" ) -const MAX_DESCRIBE_SERVICE_IDS = 10 +const ( + MAX_DESCRIBE_SERVICE_IDS = 10 + MAX_DESCRIBE_TASK_ARNS = 100 +) type Provider interface { CreateCluster(clusterName string) (*Cluster, error) @@ -25,18 +29,25 @@ type Provider interface { Helper_DescribeClusters() ([]*Cluster, error) DescribeService(cluster, service string) (*Service, error) - DescribeServices(cluster string, service []*string) ([]*Service, error) + DescribeClusterServices(clusterName, prefix string) ([]*Service, error) + DescribeServices(cluster string, service []string) ([]*Service, error) Helper_DescribeServices(prefix string) ([]*Service, error) DescribeTaskDefinition(familyAndRevision string) (*TaskDefinition, error) Helper_DescribeTaskDefinitions(prefix string) ([]*TaskDefinition, error) - DescribeTasks(cluster string, taskArns []*string) ([]*Task, error) + DescribeTask(cluster string, taskARN string) (*Task, error) + DescribeTasks(clusterName string, taskARNs []*string) ([]*Task, error) + DescribeEnvironmentTasks(clusterName, prefix string) ([]*Task, error) ListClusters() ([]*string, error) + ListClusterNames(prefix string) ([]string, error) ListContainerInstances(clusterName string) ([]*string, error) ListServices(clusterName string) ([]*string, error) Helper_ListServices(prefix string) ([]*string, error) + + ListClusterTaskARNs(clusterName, startedBy string) ([]string, error) + ListClusterServiceNames(clusterName, prefix string) ([]string, error) ListTasks(clusterName string, serviceName, desiredStatus, startedBy, containerInstance *string) ([]*string, error) ListTaskDefinitions(familyName string, nextToken *string) ([]*string, *string, error) @@ -47,9 +58,9 @@ type Provider interface { ListTaskDefinitionFamiliesPages(prefix string) ([]*string, error) RegisterTaskDefinition(family string, roleARN string, networkMode string, containerDefinitions []*ContainerDefinition, volumes []*Volume, placementConstraints []*PlacementConstraint) (*TaskDefinition, error) - RunTask(cluster, taskDefinition string, count int64, startedBy *string, overrides []*ContainerOverride) ([]*Task, []*FailedTask, error) + RunTask(clusterName, taskDefinition, startedBy string, overrides []*ContainerOverride) (*Task, error) StartTask(cluster, taskDefinition string, overrides *TaskOverride, containerInstanceIDs []*string, startedBy *string) error - StopTask(cluster, reason, task string) error + StopTask(clusterName, taskARN, reason string) error UpdateService(cluster, service string, taskDefinition *string, desiredCount *int64) error } @@ -247,10 +258,12 @@ func NewTask(clusterARN, taskID, deployARN string) *Task { }, } } + func (this *TaskDefinition) AddContainerDefinition(def *ContainerDefinition) { if this.ContainerDefinitions == nil { this.ContainerDefinitions = []*ecs.ContainerDefinition{} } + this.ContainerDefinitions = append(this.ContainerDefinitions, def.ContainerDefinition) } @@ -375,53 +388,49 @@ func (this *ECS) RegisterTaskDefinition(family string, roleARN string, networkMo return &TaskDefinition{output.TaskDefinition}, err } -func (this *ECS) RunTask(cluster, taskDefinition string, count int64, startedBy *string, overrides []*ContainerOverride) ([]*Task, []*FailedTask, error) { - var taskOverride *ecs.TaskOverride - if overrides != nil { - containerOverrides := []*ecs.ContainerOverride{} - for _, c := range overrides { - containerOverrides = append(containerOverrides, c.ContainerOverride) - } - taskOverride = &ecs.TaskOverride{ - ContainerOverrides: containerOverrides, - } +func (this *ECS) RunTask( + clusterName string, + taskDefinition string, + startedBy string, + overrides []*ContainerOverride, +) (*Task, error) { + connection, err := this.Connect() + if err != nil { + return nil, err } + placementStrategy := []*ecs.PlacementStrategy{{ + Type: aws.String(ecs.PlacementStrategyTypeBinpack), + Field: aws.String("memory"), + }} + input := &ecs.RunTaskInput{ - Cluster: aws.String(cluster), - TaskDefinition: aws.String(taskDefinition), - Count: aws.Int64(count), - StartedBy: startedBy, - Overrides: taskOverride, - PlacementStrategy: []*ecs.PlacementStrategy{ - { - Type: aws.String(ecs.PlacementStrategyTypeBinpack), - Field: aws.String("memory"), - }, - }, + Cluster: aws.String(clusterName), + TaskDefinition: aws.String(taskDefinition), + Count: aws.Int64(1), + StartedBy: aws.String(startedBy), + PlacementStrategy: placementStrategy, } - connection, err := this.Connect() - if err != nil { - return nil, nil, err + if overrides != nil { + cos := make([]*ecs.ContainerOverride, len(overrides)) + for i, o := range overrides { + cos[i] = o.ContainerOverride + } + + input.Overrides = &ecs.TaskOverride{ContainerOverrides: cos} } result, err := connection.RunTask(input) if err != nil { - return nil, nil, err - } - - failures := []*FailedTask{} - for _, f := range result.Failures { - failures = append(failures, &FailedTask{f}) + return nil, err } - tasks := []*Task{} - for _, task := range result.Tasks { - tasks = append(tasks, &Task{task}) + if len(result.Failures) > 0 { + return nil, fmt.Errorf("Failed to start task: %s", aws.StringValue(result.Failures[0].Reason)) } - return tasks, failures, nil + return &Task{result.Tasks[0]}, nil } func (this *ECS) StartTask(cluster, taskDefinition string, overrides *TaskOverride, containerInstanceIDs []*string, startedBy *string) (err error) { @@ -445,20 +454,23 @@ func (this *ECS) StartTask(cluster, taskDefinition string, overrides *TaskOverri return err } -func (this *ECS) StopTask(cluster, reason, task string) (err error) { +func (this *ECS) StopTask(clusterName, taskARN, reason string) error { + connection, err := this.Connect() + if err != nil { + return err + } + input := &ecs.StopTaskInput{ - Cluster: aws.String(cluster), + Cluster: aws.String(clusterName), + Task: aws.String(taskARN), Reason: aws.String(reason), - Task: aws.String(task), } - connection, err := this.Connect() - if err != nil { + if _, err := connection.StopTask(input); err != nil { return err } - _, err = connection.StopTask(input) - return err + return nil } func (this *ECS) CreateService(cluster, serviceName, taskDefinition string, desiredCount int64, loadBalancers []*LoadBalancer, loadBalancerRole *string) (*Service, error) { @@ -525,20 +537,31 @@ func (this *ECS) DeleteService(cluster, service string) error { return err } -func (this *ECS) DescribeService(cluster, service string) (*Service, error) { - services, err := this.DescribeServices(cluster, []*string{&service}) +func (this *ECS) DescribeService(clusterName, serviceName string) (*Service, error) { + connection, err := this.Connect() + if err != nil { + return nil, err + } + + input := &ecs.DescribeServicesInput{} + input.SetCluster(clusterName) + input.SetServices([]*string{ + aws.String(serviceName), + }) + + output, err := connection.DescribeServices(input) if err != nil { return nil, err } - if len(services) > 0 { - return services[0], nil + if len(output.Services) == 0 { + return nil, awserr.New("ServiceNotFoundException", "", nil) } - return nil, fmt.Errorf("Service Not Found") + return &Service{output.Services[0]}, nil } -func (this *ECS) DescribeServices(cluster string, serviceIDs []*string) ([]*Service, error) { +func (this *ECS) DescribeServices(cluster string, serviceIDs []string) ([]*Service, error) { connection, err := this.Connect() if err != nil { return nil, err @@ -552,7 +575,7 @@ func (this *ECS) DescribeServices(cluster string, serviceIDs []*string) ([]*Serv input := &ecs.DescribeServicesInput{ Cluster: aws.String(cluster), - Services: serviceIDs[:i], + Services: aws.StringSlice(serviceIDs[:i]), } output, err := connection.DescribeServices(input) @@ -570,6 +593,27 @@ func (this *ECS) DescribeServices(cluster string, serviceIDs []*string) ([]*Serv return services, nil } +func (this *ECS) ListClusters() ([]*string, error) { + input := &ecs.ListClustersInput{} + + connection, err := this.Connect() + if err != nil { + return nil, err + } + + output := []*string{} + save := func(p *ecs.ListClustersOutput, lastPage bool) (shouldContinue bool) { + output = append(output, p.ClusterArns...) + return !lastPage + } + + if err := connection.ListClustersPages(input, save); err != nil { + return nil, err + } + + return output, nil +} + func (this *ECS) Helper_ListServices(prefix string) ([]*string, error) { clusterARNs, err := this.ListClusters() if err != nil { @@ -621,7 +665,7 @@ func (this *ECS) Helper_DescribeServices(prefix string) ([]*Service, error) { services := []*Service{} for clusterARN, serviceARNs := range clusterServices { - svcs, err := this.DescribeServices(clusterARN, serviceARNs) + svcs, err := this.DescribeServices(clusterARN, aws.StringValueSlice(serviceARNs)) if err != nil { return nil, err } @@ -650,43 +694,167 @@ func (this *ECS) CreateCluster(clusterName string) (*Cluster, error) { return &Cluster{output.Cluster}, err } -func (this *ECS) ListClusters() ([]*string, error) { - input := &ecs.ListClustersInput{} +func (this *ECS) ListClusterNames(prefix string) ([]string, error) { + connection, err := this.Connect() + if err != nil { + return nil, err + } + clusterNames := []string{} + fn := func(output *ecs.ListClustersOutput, lastPage bool) bool { + for _, arn := range output.ClusterArns { + // cluster arn format: arn:aws:ecs:region:012345678910:cluster/name + clusterName := strings.Split(aws.StringValue(arn), "/")[1] + + if strings.HasPrefix(clusterName, prefix) { + clusterNames = append(clusterNames, clusterName) + } + } + + return !lastPage + } + + if err := connection.ListClustersPages(&ecs.ListClustersInput{}, fn); err != nil { + return nil, err + } + + return clusterNames, nil +} + +func (this *ECS) ListClusterTaskARNs(clusterName, startedBy string) ([]string, error) { connection, err := this.Connect() if err != nil { return nil, err } - output := []*string{} - save := func(p *ecs.ListClustersOutput, lastPage bool) (shouldContinue bool) { - output = append(output, p.ClusterArns...) + taskARNs := []string{} + fn := func(output *ecs.ListTasksOutput, lastPage bool) bool { + for _, taskARN := range output.TaskArns { + taskARNs = append(taskARNs, aws.StringValue(taskARN)) + } + return !lastPage } - if err := connection.ListClustersPages(input, save); err != nil { + for _, status := range []string{ecs.DesiredStatusRunning, ecs.DesiredStatusStopped} { + input := &ecs.ListTasksInput{} + input.SetCluster(clusterName) + input.SetDesiredStatus(status) + input.SetStartedBy(startedBy) + + if err := connection.ListTasksPages(input, fn); err != nil { + return nil, err + } + } + + return taskARNs, nil +} + +func (this *ECS) ListClusterServiceNames(clusterName, prefix string) ([]string, error) { + connection, err := this.Connect() + if err != nil { return nil, err } - return output, nil + var serviceNames []string + fn := func(output *ecs.ListServicesOutput, lastPage bool) bool { + for _, serviceARN := range output.ServiceArns { + // sample service ARN: + // arn:aws:ecs:us-west-2:856306994068:service/l0-tlakedev-guestbo80d9d + serviceName := strings.Split(aws.StringValue(serviceARN), "/")[1] + if strings.HasPrefix(serviceName, prefix) { + serviceNames = append(serviceNames, serviceName) + } + } + + return !lastPage + } + + input := &ecs.ListServicesInput{} + input.SetCluster(clusterName) + if err := connection.ListServicesPages(input, fn); err != nil { + return nil, err + } + + return serviceNames, nil } -func (this *ECS) DescribeCluster(cluster string) (*Cluster, error) { - clusters, err := this.DescribeClusters([]string{cluster}) +func (this *ECS) DescribeCluster(clusterName string) (*Cluster, error) { + connection, err := this.Connect() if err != nil { return nil, err } - if len(clusters) > 0 { - cluster := clusters[0] - if *cluster.Status != "INACTIVE" { - return cluster, nil + input := &ecs.DescribeClustersInput{ + Clusters: []*string{aws.String(clusterName)}, + } + + output, err := connection.DescribeClusters(input) + if err != nil { + return nil, err + } + + if len(output.Failures) > 0 { + reason := aws.StringValue(output.Failures[0].Reason) + if strings.Contains(reason, "MISSING") { + return nil, fmt.Errorf("Cluster Not Found") } + + return nil, fmt.Errorf("Failed to describe Cluster: %s", reason) + } + + cluster := output.Clusters[0] + if aws.StringValue(cluster.Status) == "ACTIVE" { + return &Cluster{cluster}, nil } return nil, fmt.Errorf("Cluster Not Found") } +func (this *ECS) DescribeClusterServices(clusterName, prefix string) ([]*Service, error) { + serviceNames, err := this.ListClusterServiceNames(clusterName, prefix) + if err != nil { + return nil, err + } + + connection, err := this.Connect() + if err != nil { + return nil, err + } + + services := []*Service{} + if len(serviceNames) > 0 { + for i := len(serviceNames); i > 0; i = len(serviceNames) { + if i > MAX_DESCRIBE_SERVICE_IDS { + i = MAX_DESCRIBE_SERVICE_IDS + } + + serviceNamesPtrs := make([]*string, len(serviceNames[:i])) + for i, serviceName := range serviceNames[:i] { + serviceNamesPtrs[i] = aws.String(serviceName) + } + + input := &ecs.DescribeServicesInput{ + Cluster: aws.String(clusterName), + Services: serviceNamesPtrs, + } + + output, err := connection.DescribeServices(input) + if err != nil { + return nil, err + } + + for _, svc := range output.Services { + services = append(services, &Service{svc}) + } + + serviceNames = serviceNames[i:] + } + } + + return services, nil +} + func (this *ECS) DescribeClusters(cluster []string) ([]*Cluster, error) { input_list := make([]*string, 0, len(cluster)) for _, svc := range cluster { @@ -1005,6 +1173,78 @@ func (this *ECS) DescribeTasks(clusterName string, tasks []*string) ([]*Task, er return ret, nil } +func (this *ECS) DescribeTask(clusterName string, taskARN string) (*Task, error) { + connection, err := this.Connect() + if err != nil { + return nil, err + } + + input := &ecs.DescribeTasksInput{ + Cluster: aws.String(clusterName), + Tasks: []*string{aws.String(taskARN)}, + } + + output, err := connection.DescribeTasks(input) + if err != nil { + return nil, err + } + + if len(output.Failures) > 0 { + reason := aws.StringValue(output.Failures[0].Reason) + if strings.Contains(reason, "MISSING") { + return nil, fmt.Errorf("The specified task does not exist") + } + + return nil, fmt.Errorf("Failed to describe task: %s", reason) + } + + return &Task{output.Tasks[0]}, nil +} + +func (this *ECS) DescribeEnvironmentTasks(clusterName, prefix string) ([]*Task, error) { + taskARNs, err := this.ListClusterTaskARNs(clusterName, prefix) + if err != nil { + return nil, err + } + + connection, err := this.Connect() + if err != nil { + return nil, err + } + + tasks := []*Task{} + if len(taskARNs) > 0 { + for i := len(taskARNs); i > 0; i = len(taskARNs) { + if i > MAX_DESCRIBE_TASK_ARNS { + i = MAX_DESCRIBE_TASK_ARNS + } + + taskARNPtrs := make([]*string, len(taskARNs[:i])) + for i, taskARN := range taskARNs[:i] { + taskARNPtrs[i] = aws.String(taskARN) + } + + input := &ecs.DescribeTasksInput{ + Cluster: aws.String(clusterName), + Tasks: taskARNPtrs, + } + + output, err := connection.DescribeTasks(input) + if err != nil { + return nil, err + } + + for _, task := range output.Tasks { + tasks = append(tasks, &Task{task}) + } + + taskARNs = taskARNs[i:] + } + } + + return tasks, nil +} + func (this *ECS) DeleteTaskDefinition(taskName string) error { input := &ecs.DeregisterTaskDefinitionInput{ TaskDefinition: &taskName, diff --git a/common/aws/ecs/ecs_provider_decorator.go b/common/aws/ecs/ecs_provider_decorator.go index 2ca0c96b2..3217c8751 100644 --- a/common/aws/ecs/ecs_provider_decorator.go +++ b/common/aws/ecs/ecs_provider_decorator.go @@ -87,7 +87,16 @@ func (this *ProviderDecorator) DescribeService(p0 string, p1 string) (v0 *Servic err = this.Decorator("DescribeService", call) return v0, err } -func (this *ProviderDecorator) DescribeServices(p0 string, p1 []*string) (v0 []*Service, err error) { +func (this *ProviderDecorator) DescribeClusterServices(p0 string, p1 string) (v0 []*Service, err error) { + call := func() error { + var err error + v0, err = this.Inner.DescribeClusterServices(p0, p1) + return err + } + err = this.Decorator("DescribeClusterServices", call) + return v0, err +} +func (this *ProviderDecorator) DescribeServices(p0 string, p1 []string) (v0 []*Service, err error) { call := func() error { var err error v0, err = this.Inner.DescribeServices(p0, p1) @@ -123,6 +132,15 @@ func (this *ProviderDecorator) Helper_DescribeTaskDefinitions(p0 string) (v0 []* err = this.Decorator("Helper_DescribeTaskDefinitions", call) return v0, err } +func (this *ProviderDecorator) DescribeTask(p0 string, p1 string) (v0 *Task, err error) { + call := func() error { + var err error + v0, err = this.Inner.DescribeTask(p0, p1) + return err + } + err = this.Decorator("DescribeTask", call) + return v0, err +} func (this *ProviderDecorator) DescribeTasks(p0 string, p1 []*string) (v0 []*Task, err error) { call := func() error { var err error @@ -132,6 +150,15 @@ func (this *ProviderDecorator) DescribeTasks(p0 string, p1 []*string) (v0 []*Tas err = this.Decorator("DescribeTasks", call) return v0, err } +func (this *ProviderDecorator) DescribeEnvironmentTasks(p0 string, p1 string) (v0 []*Task, err error) { + call := func() error { + var err error + v0, err = this.Inner.DescribeEnvironmentTasks(p0, p1) + return err + } + err = this.Decorator("DescribeEnvironmentTasks", call) + return v0, err +} func (this *ProviderDecorator) ListClusters() (v0 []*string, err error) { call := func() error { var err error @@ -141,6 +168,15 @@ func (this *ProviderDecorator) ListClusters() (v0 []*string, err error) { err = this.Decorator("ListClusters", call) return v0, err } +func (this *ProviderDecorator) ListClusterNames(p0 string) (v0 []string, err error) { + call := func() error { + var err error + v0, err = this.Inner.ListClusterNames(p0) + return err + } + err = this.Decorator("ListClusterNames", call) + return v0, err +} func (this *ProviderDecorator) ListContainerInstances(p0 string) (v0 []*string, err error) { call := func() error { var err error @@ -168,6 +204,24 @@ func (this *ProviderDecorator) Helper_ListServices(p0 string) (v0 []*string, err err = this.Decorator("Helper_ListServices", call) return v0, err } +func (this *ProviderDecorator) ListClusterTaskARNs(p0 string, p1 string) (v0 []string, err error) { + call := func() error { + var err error + v0, err = this.Inner.ListClusterTaskARNs(p0, p1) + return err + } + err = this.Decorator("ListClusterTaskARNs", call) + return v0, err +} +func (this *ProviderDecorator) ListClusterServiceNames(p0 string, p1 string) (v0 []string, err error) { + call := func() error { + var err error + v0, err = this.Inner.ListClusterServiceNames(p0, p1) + return err + } + err = this.Decorator("ListClusterServiceNames", call) + return v0, err +} func (this *ProviderDecorator) ListTasks(p0 string, p1 *string, p2 *string, p3 *string, p4 *string) (v0 []*string, err error) { call := func() error { var err error @@ -231,14 +285,14 @@ func (this *ProviderDecorator) RegisterTaskDefinition(p0 string, p1 string, p2 s err = this.Decorator("RegisterTaskDefinition", call) return v0, err } -func (this *ProviderDecorator) RunTask(p0 string, p1 string, p2 int64, p3 *string, p4 []*ContainerOverride) (v0 []*Task, v1 []*FailedTask, err error) { +func (this *ProviderDecorator) RunTask(p0 string, p1 string, p2 string, p3 []*ContainerOverride) (v0 *Task, err error) { call := func() error { var err error - v0, v1, err = this.Inner.RunTask(p0, p1, p2, p3, p4) + v0, err = this.Inner.RunTask(p0, p1, p2, p3) return err } err = this.Decorator("RunTask", call) - return v0, v1, err + return v0, err } func (this *ProviderDecorator) StartTask(p0 string, p1 string, p2 *TaskOverride, p3 []*string, p4 *string) (err error) { call := func() error { diff --git a/common/aws/ecs/mock_ecs/mock_ecs.go b/common/aws/ecs/mock_ecs/mock_ecs.go index 26d0490f6..af42bd5cc 100644 --- a/common/aws/ecs/mock_ecs/mock_ecs.go +++ b/common/aws/ecs/mock_ecs/mock_ecs.go @@ -1,346 +1,486 @@ -// Automatically generated by MockGen. DO NOT EDIT! +// Code generated by MockGen. DO NOT EDIT. // Source: github.com/quintilesims/layer0/common/aws/ecs (interfaces: Provider) +// Package mock_ecs is a generated GoMock package. package mock_ecs import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" ecs "github.com/quintilesims/layer0/common/aws/ecs" ) -// Mock of Provider interface +// MockProvider is a mock of Provider interface type MockProvider struct { ctrl *gomock.Controller - recorder *_MockProviderRecorder + recorder *MockProviderMockRecorder } -// Recorder for MockProvider (not exported) -type _MockProviderRecorder struct { +// MockProviderMockRecorder is the mock recorder for MockProvider +type MockProviderMockRecorder struct { mock *MockProvider } +// NewMockProvider creates a new mock instance func NewMockProvider(ctrl *gomock.Controller) *MockProvider { mock := &MockProvider{ctrl: ctrl} - mock.recorder = &_MockProviderRecorder{mock} + mock.recorder = &MockProviderMockRecorder{mock} return mock } -func (_m *MockProvider) EXPECT() *_MockProviderRecorder { - return _m.recorder +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockProvider) EXPECT() *MockProviderMockRecorder { + return m.recorder } -func (_m *MockProvider) CreateCluster(_param0 string) (*ecs.Cluster, error) { - ret := _m.ctrl.Call(_m, "CreateCluster", _param0) +// CreateCluster mocks base method +func (m *MockProvider) CreateCluster(arg0 string) (*ecs.Cluster, error) { + ret := m.ctrl.Call(m, "CreateCluster", arg0) ret0, _ := ret[0].(*ecs.Cluster) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) CreateCluster(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateCluster", arg0) +// CreateCluster indicates an expected call of CreateCluster +func (mr *MockProviderMockRecorder) CreateCluster(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateCluster", reflect.TypeOf((*MockProvider)(nil).CreateCluster), arg0) } -func (_m *MockProvider) CreateService(_param0 string, _param1 string, _param2 string, _param3 int64, _param4 []*ecs.LoadBalancer, _param5 *string) (*ecs.Service, error) { - ret := _m.ctrl.Call(_m, "CreateService", _param0, _param1, _param2, _param3, _param4, _param5) +// CreateService mocks base method +func (m *MockProvider) CreateService(arg0, arg1, arg2 string, arg3 int64, arg4 []*ecs.LoadBalancer, arg5 *string) (*ecs.Service, error) { + ret := m.ctrl.Call(m, "CreateService", arg0, arg1, arg2, arg3, arg4, arg5) ret0, _ := ret[0].(*ecs.Service) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) CreateService(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateService", arg0, arg1, arg2, arg3, arg4, arg5) +// CreateService indicates an expected call of CreateService +func (mr *MockProviderMockRecorder) CreateService(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateService", reflect.TypeOf((*MockProvider)(nil).CreateService), arg0, arg1, arg2, arg3, arg4, arg5) } -func (_m *MockProvider) DeleteCluster(_param0 string) error { - ret := _m.ctrl.Call(_m, "DeleteCluster", _param0) +// DeleteCluster mocks base method +func (m *MockProvider) DeleteCluster(arg0 string) error { + ret := m.ctrl.Call(m, "DeleteCluster", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) DeleteCluster(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteCluster", arg0) +// DeleteCluster indicates an expected call of DeleteCluster +func (mr *MockProviderMockRecorder) DeleteCluster(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteCluster", reflect.TypeOf((*MockProvider)(nil).DeleteCluster), arg0) } -func (_m *MockProvider) DeleteService(_param0 string, _param1 string) error { - ret := _m.ctrl.Call(_m, "DeleteService", _param0, _param1) +// DeleteService mocks base method +func (m *MockProvider) DeleteService(arg0, arg1 string) error { + ret := m.ctrl.Call(m, "DeleteService", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) DeleteService(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteService", arg0, arg1) +// DeleteService indicates an expected call of DeleteService +func (mr *MockProviderMockRecorder) DeleteService(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteService", reflect.TypeOf((*MockProvider)(nil).DeleteService), arg0, arg1) } -func (_m *MockProvider) DeleteTaskDefinition(_param0 string) error { - ret := _m.ctrl.Call(_m, "DeleteTaskDefinition", _param0) +// DeleteTaskDefinition mocks base method +func (m *MockProvider) DeleteTaskDefinition(arg0 string) error { + ret := m.ctrl.Call(m, "DeleteTaskDefinition", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) DeleteTaskDefinition(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteTaskDefinition", arg0) +// DeleteTaskDefinition indicates an expected call of DeleteTaskDefinition +func (mr *MockProviderMockRecorder) DeleteTaskDefinition(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteTaskDefinition", reflect.TypeOf((*MockProvider)(nil).DeleteTaskDefinition), arg0) } -func (_m *MockProvider) DescribeCluster(_param0 string) (*ecs.Cluster, error) { - ret := _m.ctrl.Call(_m, "DescribeCluster", _param0) +// DescribeCluster mocks base method +func (m *MockProvider) DescribeCluster(arg0 string) (*ecs.Cluster, error) { + ret := m.ctrl.Call(m, "DescribeCluster", arg0) ret0, _ := ret[0].(*ecs.Cluster) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) DescribeCluster(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DescribeCluster", arg0) +// DescribeCluster indicates an expected call of DescribeCluster +func (mr *MockProviderMockRecorder) DescribeCluster(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeCluster", reflect.TypeOf((*MockProvider)(nil).DescribeCluster), arg0) +} + +// DescribeClusterServices mocks base method +func (m *MockProvider) DescribeClusterServices(arg0, arg1 string) ([]*ecs.Service, error) { + ret := m.ctrl.Call(m, "DescribeClusterServices", arg0, arg1) + ret0, _ := ret[0].([]*ecs.Service) + ret1, _ := ret[1].(error) + return ret0, ret1 } -func (_m *MockProvider) DescribeContainerInstances(_param0 string, _param1 []*string) ([]*ecs.ContainerInstance, error) { - ret := _m.ctrl.Call(_m, "DescribeContainerInstances", _param0, _param1) +// DescribeClusterServices indicates an expected call of DescribeClusterServices +func (mr *MockProviderMockRecorder) DescribeClusterServices(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeClusterServices", reflect.TypeOf((*MockProvider)(nil).DescribeClusterServices), arg0, arg1) +} + +// DescribeContainerInstances mocks base method +func (m *MockProvider) DescribeContainerInstances(arg0 string, arg1 []*string) ([]*ecs.ContainerInstance, error) { + ret := m.ctrl.Call(m, "DescribeContainerInstances", arg0, arg1) ret0, _ := ret[0].([]*ecs.ContainerInstance) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) DescribeContainerInstances(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DescribeContainerInstances", arg0, arg1) +// DescribeContainerInstances indicates an expected call of DescribeContainerInstances +func (mr *MockProviderMockRecorder) DescribeContainerInstances(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeContainerInstances", reflect.TypeOf((*MockProvider)(nil).DescribeContainerInstances), arg0, arg1) +} + +// DescribeEnvironmentTasks mocks base method +func (m *MockProvider) DescribeEnvironmentTasks(arg0, arg1 string) ([]*ecs.Task, error) { + ret := m.ctrl.Call(m, "DescribeEnvironmentTasks", arg0, arg1) + ret0, _ := ret[0].([]*ecs.Task) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DescribeEnvironmentTasks indicates an expected call of DescribeEnvironmentTasks +func (mr *MockProviderMockRecorder) DescribeEnvironmentTasks(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeEnvironmentTasks", reflect.TypeOf((*MockProvider)(nil).DescribeEnvironmentTasks), arg0, arg1) } -func (_m *MockProvider) DescribeService(_param0 string, _param1 string) (*ecs.Service, error) { - ret := _m.ctrl.Call(_m, "DescribeService", _param0, _param1) +// DescribeService mocks base method +func (m *MockProvider) DescribeService(arg0, arg1 string) (*ecs.Service, error) { + ret := m.ctrl.Call(m, "DescribeService", arg0, arg1) ret0, _ := ret[0].(*ecs.Service) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) DescribeService(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DescribeService", arg0, arg1) +// DescribeService indicates an expected call of DescribeService +func (mr *MockProviderMockRecorder) DescribeService(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeService", reflect.TypeOf((*MockProvider)(nil).DescribeService), arg0, arg1) } -func (_m *MockProvider) DescribeServices(_param0 string, _param1 []*string) ([]*ecs.Service, error) { - ret := _m.ctrl.Call(_m, "DescribeServices", _param0, _param1) +// DescribeServices mocks base method +func (m *MockProvider) DescribeServices(arg0 string, arg1 []string) ([]*ecs.Service, error) { + ret := m.ctrl.Call(m, "DescribeServices", arg0, arg1) ret0, _ := ret[0].([]*ecs.Service) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) DescribeServices(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DescribeServices", arg0, arg1) +// DescribeServices indicates an expected call of DescribeServices +func (mr *MockProviderMockRecorder) DescribeServices(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeServices", reflect.TypeOf((*MockProvider)(nil).DescribeServices), arg0, arg1) } -func (_m *MockProvider) DescribeTaskDefinition(_param0 string) (*ecs.TaskDefinition, error) { - ret := _m.ctrl.Call(_m, "DescribeTaskDefinition", _param0) +// DescribeTask mocks base method +func (m *MockProvider) DescribeTask(arg0, arg1 string) (*ecs.Task, error) { + ret := m.ctrl.Call(m, "DescribeTask", arg0, arg1) + ret0, _ := ret[0].(*ecs.Task) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// DescribeTask indicates an expected call of DescribeTask +func (mr *MockProviderMockRecorder) DescribeTask(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeTask", reflect.TypeOf((*MockProvider)(nil).DescribeTask), arg0, arg1) +} + +// DescribeTaskDefinition mocks base method +func (m *MockProvider) DescribeTaskDefinition(arg0 string) (*ecs.TaskDefinition, error) { + ret := m.ctrl.Call(m, "DescribeTaskDefinition", arg0) ret0, _ := ret[0].(*ecs.TaskDefinition) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) DescribeTaskDefinition(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DescribeTaskDefinition", arg0) +// DescribeTaskDefinition indicates an expected call of DescribeTaskDefinition +func (mr *MockProviderMockRecorder) DescribeTaskDefinition(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeTaskDefinition", reflect.TypeOf((*MockProvider)(nil).DescribeTaskDefinition), arg0) } -func (_m *MockProvider) DescribeTasks(_param0 string, _param1 []*string) ([]*ecs.Task, error) { - ret := _m.ctrl.Call(_m, "DescribeTasks", _param0, _param1) +// DescribeTasks mocks base method +func (m *MockProvider) DescribeTasks(arg0 string, arg1 []*string) ([]*ecs.Task, error) { + ret := m.ctrl.Call(m, "DescribeTasks", arg0, arg1) ret0, _ := ret[0].([]*ecs.Task) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) DescribeTasks(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DescribeTasks", arg0, arg1) +// DescribeTasks indicates an expected call of DescribeTasks +func (mr *MockProviderMockRecorder) DescribeTasks(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeTasks", reflect.TypeOf((*MockProvider)(nil).DescribeTasks), arg0, arg1) } -func (_m *MockProvider) Helper_DescribeClusters() ([]*ecs.Cluster, error) { - ret := _m.ctrl.Call(_m, "Helper_DescribeClusters") +// Helper_DescribeClusters mocks base method +func (m *MockProvider) Helper_DescribeClusters() ([]*ecs.Cluster, error) { + ret := m.ctrl.Call(m, "Helper_DescribeClusters") ret0, _ := ret[0].([]*ecs.Cluster) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) Helper_DescribeClusters() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "Helper_DescribeClusters") +// Helper_DescribeClusters indicates an expected call of Helper_DescribeClusters +func (mr *MockProviderMockRecorder) Helper_DescribeClusters() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Helper_DescribeClusters", reflect.TypeOf((*MockProvider)(nil).Helper_DescribeClusters)) } -func (_m *MockProvider) Helper_DescribeServices(_param0 string) ([]*ecs.Service, error) { - ret := _m.ctrl.Call(_m, "Helper_DescribeServices", _param0) +// Helper_DescribeServices mocks base method +func (m *MockProvider) Helper_DescribeServices(arg0 string) ([]*ecs.Service, error) { + ret := m.ctrl.Call(m, "Helper_DescribeServices", arg0) ret0, _ := ret[0].([]*ecs.Service) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) Helper_DescribeServices(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "Helper_DescribeServices", arg0) +// Helper_DescribeServices indicates an expected call of Helper_DescribeServices +func (mr *MockProviderMockRecorder) Helper_DescribeServices(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Helper_DescribeServices", reflect.TypeOf((*MockProvider)(nil).Helper_DescribeServices), arg0) } -func (_m *MockProvider) Helper_DescribeTaskDefinitions(_param0 string) ([]*ecs.TaskDefinition, error) { - ret := _m.ctrl.Call(_m, "Helper_DescribeTaskDefinitions", _param0) +// Helper_DescribeTaskDefinitions mocks base method +func (m *MockProvider) Helper_DescribeTaskDefinitions(arg0 string) ([]*ecs.TaskDefinition, error) { + ret := m.ctrl.Call(m, "Helper_DescribeTaskDefinitions", arg0) ret0, _ := ret[0].([]*ecs.TaskDefinition) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) Helper_DescribeTaskDefinitions(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "Helper_DescribeTaskDefinitions", arg0) +// Helper_DescribeTaskDefinitions indicates an expected call of Helper_DescribeTaskDefinitions +func (mr *MockProviderMockRecorder) Helper_DescribeTaskDefinitions(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Helper_DescribeTaskDefinitions", reflect.TypeOf((*MockProvider)(nil).Helper_DescribeTaskDefinitions), arg0) } -func (_m *MockProvider) Helper_ListServices(_param0 string) ([]*string, error) { - ret := _m.ctrl.Call(_m, "Helper_ListServices", _param0) +// Helper_ListServices mocks base method +func (m *MockProvider) Helper_ListServices(arg0 string) ([]*string, error) { + ret := m.ctrl.Call(m, "Helper_ListServices", arg0) ret0, _ := ret[0].([]*string) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) Helper_ListServices(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "Helper_ListServices", arg0) +// Helper_ListServices indicates an expected call of Helper_ListServices +func (mr *MockProviderMockRecorder) Helper_ListServices(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Helper_ListServices", reflect.TypeOf((*MockProvider)(nil).Helper_ListServices), arg0) } -func (_m *MockProvider) Helper_ListTaskDefinitions(_param0 string) ([]*string, error) { - ret := _m.ctrl.Call(_m, "Helper_ListTaskDefinitions", _param0) +// Helper_ListTaskDefinitions mocks base method +func (m *MockProvider) Helper_ListTaskDefinitions(arg0 string) ([]*string, error) { + ret := m.ctrl.Call(m, "Helper_ListTaskDefinitions", arg0) ret0, _ := ret[0].([]*string) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) Helper_ListTaskDefinitions(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "Helper_ListTaskDefinitions", arg0) +// Helper_ListTaskDefinitions indicates an expected call of Helper_ListTaskDefinitions +func (mr *MockProviderMockRecorder) Helper_ListTaskDefinitions(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Helper_ListTaskDefinitions", reflect.TypeOf((*MockProvider)(nil).Helper_ListTaskDefinitions), arg0) +} + +// ListClusterNames mocks base method +func (m *MockProvider) ListClusterNames(arg0 string) ([]string, error) { + ret := m.ctrl.Call(m, "ListClusterNames", arg0) + ret0, _ := ret[0].([]string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListClusterNames indicates an expected call of ListClusterNames +func (mr *MockProviderMockRecorder) ListClusterNames(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListClusterNames", reflect.TypeOf((*MockProvider)(nil).ListClusterNames), arg0) +} + +// ListClusterServiceNames mocks base method +func (m *MockProvider) ListClusterServiceNames(arg0, arg1 string) ([]string, error) { + ret := m.ctrl.Call(m, "ListClusterServiceNames", arg0, arg1) + ret0, _ := ret[0].([]string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListClusterServiceNames indicates an expected call of ListClusterServiceNames +func (mr *MockProviderMockRecorder) ListClusterServiceNames(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListClusterServiceNames", reflect.TypeOf((*MockProvider)(nil).ListClusterServiceNames), arg0, arg1) } -func (_m *MockProvider) ListClusters() ([]*string, error) { - ret := _m.ctrl.Call(_m, "ListClusters") +// ListClusterTaskARNs mocks base method +func (m *MockProvider) ListClusterTaskARNs(arg0, arg1 string) ([]string, error) { + ret := m.ctrl.Call(m, "ListClusterTaskARNs", arg0, arg1) + ret0, _ := ret[0].([]string) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ListClusterTaskARNs indicates an expected call of ListClusterTaskARNs +func (mr *MockProviderMockRecorder) ListClusterTaskARNs(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListClusterTaskARNs", reflect.TypeOf((*MockProvider)(nil).ListClusterTaskARNs), arg0, arg1) +} + +// ListClusters mocks base method +func (m *MockProvider) ListClusters() ([]*string, error) { + ret := m.ctrl.Call(m, "ListClusters") ret0, _ := ret[0].([]*string) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) ListClusters() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListClusters") +// ListClusters indicates an expected call of ListClusters +func (mr *MockProviderMockRecorder) ListClusters() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListClusters", reflect.TypeOf((*MockProvider)(nil).ListClusters)) } -func (_m *MockProvider) ListContainerInstances(_param0 string) ([]*string, error) { - ret := _m.ctrl.Call(_m, "ListContainerInstances", _param0) +// ListContainerInstances mocks base method +func (m *MockProvider) ListContainerInstances(arg0 string) ([]*string, error) { + ret := m.ctrl.Call(m, "ListContainerInstances", arg0) ret0, _ := ret[0].([]*string) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) ListContainerInstances(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListContainerInstances", arg0) +// ListContainerInstances indicates an expected call of ListContainerInstances +func (mr *MockProviderMockRecorder) ListContainerInstances(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListContainerInstances", reflect.TypeOf((*MockProvider)(nil).ListContainerInstances), arg0) } -func (_m *MockProvider) ListServices(_param0 string) ([]*string, error) { - ret := _m.ctrl.Call(_m, "ListServices", _param0) +// ListServices mocks base method +func (m *MockProvider) ListServices(arg0 string) ([]*string, error) { + ret := m.ctrl.Call(m, "ListServices", arg0) ret0, _ := ret[0].([]*string) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) ListServices(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListServices", arg0) +// ListServices indicates an expected call of ListServices +func (mr *MockProviderMockRecorder) ListServices(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListServices", reflect.TypeOf((*MockProvider)(nil).ListServices), arg0) } -func (_m *MockProvider) ListTaskDefinitionFamilies(_param0 string, _param1 *string) ([]*string, *string, error) { - ret := _m.ctrl.Call(_m, "ListTaskDefinitionFamilies", _param0, _param1) +// ListTaskDefinitionFamilies mocks base method +func (m *MockProvider) ListTaskDefinitionFamilies(arg0 string, arg1 *string) ([]*string, *string, error) { + ret := m.ctrl.Call(m, "ListTaskDefinitionFamilies", arg0, arg1) ret0, _ := ret[0].([]*string) ret1, _ := ret[1].(*string) ret2, _ := ret[2].(error) return ret0, ret1, ret2 } -func (_mr *_MockProviderRecorder) ListTaskDefinitionFamilies(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListTaskDefinitionFamilies", arg0, arg1) +// ListTaskDefinitionFamilies indicates an expected call of ListTaskDefinitionFamilies +func (mr *MockProviderMockRecorder) ListTaskDefinitionFamilies(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListTaskDefinitionFamilies", reflect.TypeOf((*MockProvider)(nil).ListTaskDefinitionFamilies), arg0, arg1) } -func (_m *MockProvider) ListTaskDefinitionFamiliesPages(_param0 string) ([]*string, error) { - ret := _m.ctrl.Call(_m, "ListTaskDefinitionFamiliesPages", _param0) +// ListTaskDefinitionFamiliesPages mocks base method +func (m *MockProvider) ListTaskDefinitionFamiliesPages(arg0 string) ([]*string, error) { + ret := m.ctrl.Call(m, "ListTaskDefinitionFamiliesPages", arg0) ret0, _ := ret[0].([]*string) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) ListTaskDefinitionFamiliesPages(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListTaskDefinitionFamiliesPages", arg0) +// ListTaskDefinitionFamiliesPages indicates an expected call of ListTaskDefinitionFamiliesPages +func (mr *MockProviderMockRecorder) ListTaskDefinitionFamiliesPages(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListTaskDefinitionFamiliesPages", reflect.TypeOf((*MockProvider)(nil).ListTaskDefinitionFamiliesPages), arg0) } -func (_m *MockProvider) ListTaskDefinitions(_param0 string, _param1 *string) ([]*string, *string, error) { - ret := _m.ctrl.Call(_m, "ListTaskDefinitions", _param0, _param1) +// ListTaskDefinitions mocks base method +func (m *MockProvider) ListTaskDefinitions(arg0 string, arg1 *string) ([]*string, *string, error) { + ret := m.ctrl.Call(m, "ListTaskDefinitions", arg0, arg1) ret0, _ := ret[0].([]*string) ret1, _ := ret[1].(*string) ret2, _ := ret[2].(error) return ret0, ret1, ret2 } -func (_mr *_MockProviderRecorder) ListTaskDefinitions(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListTaskDefinitions", arg0, arg1) +// ListTaskDefinitions indicates an expected call of ListTaskDefinitions +func (mr *MockProviderMockRecorder) ListTaskDefinitions(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListTaskDefinitions", reflect.TypeOf((*MockProvider)(nil).ListTaskDefinitions), arg0, arg1) } -func (_m *MockProvider) ListTaskDefinitionsPages(_param0 string) ([]*string, error) { - ret := _m.ctrl.Call(_m, "ListTaskDefinitionsPages", _param0) +// ListTaskDefinitionsPages mocks base method +func (m *MockProvider) ListTaskDefinitionsPages(arg0 string) ([]*string, error) { + ret := m.ctrl.Call(m, "ListTaskDefinitionsPages", arg0) ret0, _ := ret[0].([]*string) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) ListTaskDefinitionsPages(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListTaskDefinitionsPages", arg0) +// ListTaskDefinitionsPages indicates an expected call of ListTaskDefinitionsPages +func (mr *MockProviderMockRecorder) ListTaskDefinitionsPages(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListTaskDefinitionsPages", reflect.TypeOf((*MockProvider)(nil).ListTaskDefinitionsPages), arg0) } -func (_m *MockProvider) ListTasks(_param0 string, _param1 *string, _param2 *string, _param3 *string, _param4 *string) ([]*string, error) { - ret := _m.ctrl.Call(_m, "ListTasks", _param0, _param1, _param2, _param3, _param4) +// ListTasks mocks base method +func (m *MockProvider) ListTasks(arg0 string, arg1, arg2, arg3, arg4 *string) ([]*string, error) { + ret := m.ctrl.Call(m, "ListTasks", arg0, arg1, arg2, arg3, arg4) ret0, _ := ret[0].([]*string) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) ListTasks(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListTasks", arg0, arg1, arg2, arg3, arg4) +// ListTasks indicates an expected call of ListTasks +func (mr *MockProviderMockRecorder) ListTasks(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListTasks", reflect.TypeOf((*MockProvider)(nil).ListTasks), arg0, arg1, arg2, arg3, arg4) } -func (_m *MockProvider) RegisterTaskDefinition(_param0 string, _param1 string, _param2 string, _param3 []*ecs.ContainerDefinition, _param4 []*ecs.Volume, _param5 []*ecs.PlacementConstraint) (*ecs.TaskDefinition, error) { - ret := _m.ctrl.Call(_m, "RegisterTaskDefinition", _param0, _param1, _param2, _param3, _param4, _param5) +// RegisterTaskDefinition mocks base method +func (m *MockProvider) RegisterTaskDefinition(arg0, arg1, arg2 string, arg3 []*ecs.ContainerDefinition, arg4 []*ecs.Volume, arg5 []*ecs.PlacementConstraint) (*ecs.TaskDefinition, error) { + ret := m.ctrl.Call(m, "RegisterTaskDefinition", arg0, arg1, arg2, arg3, arg4, arg5) ret0, _ := ret[0].(*ecs.TaskDefinition) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) RegisterTaskDefinition(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "RegisterTaskDefinition", arg0, arg1, arg2, arg3, arg4, arg5) +// RegisterTaskDefinition indicates an expected call of RegisterTaskDefinition +func (mr *MockProviderMockRecorder) RegisterTaskDefinition(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterTaskDefinition", reflect.TypeOf((*MockProvider)(nil).RegisterTaskDefinition), arg0, arg1, arg2, arg3, arg4, arg5) } -func (_m *MockProvider) RunTask(_param0 string, _param1 string, _param2 int64, _param3 *string, _param4 []*ecs.ContainerOverride) ([]*ecs.Task, []*ecs.FailedTask, error) { - ret := _m.ctrl.Call(_m, "RunTask", _param0, _param1, _param2, _param3, _param4) - ret0, _ := ret[0].([]*ecs.Task) - ret1, _ := ret[1].([]*ecs.FailedTask) - ret2, _ := ret[2].(error) - return ret0, ret1, ret2 +// RunTask mocks base method +func (m *MockProvider) RunTask(arg0, arg1, arg2 string, arg3 []*ecs.ContainerOverride) (*ecs.Task, error) { + ret := m.ctrl.Call(m, "RunTask", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].(*ecs.Task) + ret1, _ := ret[1].(error) + return ret0, ret1 } -func (_mr *_MockProviderRecorder) RunTask(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "RunTask", arg0, arg1, arg2, arg3, arg4) +// RunTask indicates an expected call of RunTask +func (mr *MockProviderMockRecorder) RunTask(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RunTask", reflect.TypeOf((*MockProvider)(nil).RunTask), arg0, arg1, arg2, arg3) } -func (_m *MockProvider) StartTask(_param0 string, _param1 string, _param2 *ecs.TaskOverride, _param3 []*string, _param4 *string) error { - ret := _m.ctrl.Call(_m, "StartTask", _param0, _param1, _param2, _param3, _param4) +// StartTask mocks base method +func (m *MockProvider) StartTask(arg0, arg1 string, arg2 *ecs.TaskOverride, arg3 []*string, arg4 *string) error { + ret := m.ctrl.Call(m, "StartTask", arg0, arg1, arg2, arg3, arg4) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) StartTask(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "StartTask", arg0, arg1, arg2, arg3, arg4) +// StartTask indicates an expected call of StartTask +func (mr *MockProviderMockRecorder) StartTask(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StartTask", reflect.TypeOf((*MockProvider)(nil).StartTask), arg0, arg1, arg2, arg3, arg4) } -func (_m *MockProvider) StopTask(_param0 string, _param1 string, _param2 string) error { - ret := _m.ctrl.Call(_m, "StopTask", _param0, _param1, _param2) +// StopTask mocks base method +func (m *MockProvider) StopTask(arg0, arg1, arg2 string) error { + ret := m.ctrl.Call(m, "StopTask", arg0, arg1, arg2) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) StopTask(arg0, arg1, arg2 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "StopTask", arg0, arg1, arg2) +// StopTask indicates an expected call of StopTask +func (mr *MockProviderMockRecorder) StopTask(arg0, arg1, arg2 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StopTask", reflect.TypeOf((*MockProvider)(nil).StopTask), arg0, arg1, arg2) } -func (_m *MockProvider) UpdateService(_param0 string, _param1 string, _param2 *string, _param3 *int64) error { - ret := _m.ctrl.Call(_m, "UpdateService", _param0, _param1, _param2, _param3) +// UpdateService mocks base method +func (m *MockProvider) UpdateService(arg0, arg1 string, arg2 *string, arg3 *int64) error { + ret := m.ctrl.Call(m, "UpdateService", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) UpdateService(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "UpdateService", arg0, arg1, arg2, arg3) +// UpdateService indicates an expected call of UpdateService +func (mr *MockProviderMockRecorder) UpdateService(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateService", reflect.TypeOf((*MockProvider)(nil).UpdateService), arg0, arg1, arg2, arg3) } diff --git a/common/aws/elb/mock_elb/mock_elb.go b/common/aws/elb/mock_elb/mock_elb.go index 1e875bb77..33b5eda08 100644 --- a/common/aws/elb/mock_elb/mock_elb.go +++ b/common/aws/elb/mock_elb/mock_elb.go @@ -1,134 +1,159 @@ -// Automatically generated by MockGen. DO NOT EDIT! +// Code generated by MockGen. DO NOT EDIT. // Source: github.com/quintilesims/layer0/common/aws/elb (interfaces: Provider) +// Package mock_elb is a generated GoMock package. package mock_elb import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" elb "github.com/quintilesims/layer0/common/aws/elb" ) -// Mock of Provider interface +// MockProvider is a mock of Provider interface type MockProvider struct { ctrl *gomock.Controller - recorder *_MockProviderRecorder + recorder *MockProviderMockRecorder } -// Recorder for MockProvider (not exported) -type _MockProviderRecorder struct { +// MockProviderMockRecorder is the mock recorder for MockProvider +type MockProviderMockRecorder struct { mock *MockProvider } +// NewMockProvider creates a new mock instance func NewMockProvider(ctrl *gomock.Controller) *MockProvider { mock := &MockProvider{ctrl: ctrl} - mock.recorder = &_MockProviderRecorder{mock} + mock.recorder = &MockProviderMockRecorder{mock} return mock } -func (_m *MockProvider) EXPECT() *_MockProviderRecorder { - return _m.recorder +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockProvider) EXPECT() *MockProviderMockRecorder { + return m.recorder } -func (_m *MockProvider) ConfigureHealthCheck(_param0 string, _param1 *elb.HealthCheck) error { - ret := _m.ctrl.Call(_m, "ConfigureHealthCheck", _param0, _param1) +// ConfigureHealthCheck mocks base method +func (m *MockProvider) ConfigureHealthCheck(arg0 string, arg1 *elb.HealthCheck) error { + ret := m.ctrl.Call(m, "ConfigureHealthCheck", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) ConfigureHealthCheck(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ConfigureHealthCheck", arg0, arg1) +// ConfigureHealthCheck indicates an expected call of ConfigureHealthCheck +func (mr *MockProviderMockRecorder) ConfigureHealthCheck(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ConfigureHealthCheck", reflect.TypeOf((*MockProvider)(nil).ConfigureHealthCheck), arg0, arg1) } -func (_m *MockProvider) CreateLoadBalancer(_param0 string, _param1 string, _param2 []*string, _param3 []*string, _param4 []*elb.Listener) (*string, error) { - ret := _m.ctrl.Call(_m, "CreateLoadBalancer", _param0, _param1, _param2, _param3, _param4) +// CreateLoadBalancer mocks base method +func (m *MockProvider) CreateLoadBalancer(arg0, arg1 string, arg2, arg3 []*string, arg4 []*elb.Listener) (*string, error) { + ret := m.ctrl.Call(m, "CreateLoadBalancer", arg0, arg1, arg2, arg3, arg4) ret0, _ := ret[0].(*string) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) CreateLoadBalancer(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateLoadBalancer", arg0, arg1, arg2, arg3, arg4) +// CreateLoadBalancer indicates an expected call of CreateLoadBalancer +func (mr *MockProviderMockRecorder) CreateLoadBalancer(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateLoadBalancer", reflect.TypeOf((*MockProvider)(nil).CreateLoadBalancer), arg0, arg1, arg2, arg3, arg4) } -func (_m *MockProvider) CreateLoadBalancerListeners(_param0 string, _param1 []*elb.Listener) error { - ret := _m.ctrl.Call(_m, "CreateLoadBalancerListeners", _param0, _param1) +// CreateLoadBalancerListeners mocks base method +func (m *MockProvider) CreateLoadBalancerListeners(arg0 string, arg1 []*elb.Listener) error { + ret := m.ctrl.Call(m, "CreateLoadBalancerListeners", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) CreateLoadBalancerListeners(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateLoadBalancerListeners", arg0, arg1) +// CreateLoadBalancerListeners indicates an expected call of CreateLoadBalancerListeners +func (mr *MockProviderMockRecorder) CreateLoadBalancerListeners(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateLoadBalancerListeners", reflect.TypeOf((*MockProvider)(nil).CreateLoadBalancerListeners), arg0, arg1) } -func (_m *MockProvider) DeleteLoadBalancer(_param0 string) error { - ret := _m.ctrl.Call(_m, "DeleteLoadBalancer", _param0) +// DeleteLoadBalancer mocks base method +func (m *MockProvider) DeleteLoadBalancer(arg0 string) error { + ret := m.ctrl.Call(m, "DeleteLoadBalancer", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) DeleteLoadBalancer(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteLoadBalancer", arg0) +// DeleteLoadBalancer indicates an expected call of DeleteLoadBalancer +func (mr *MockProviderMockRecorder) DeleteLoadBalancer(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteLoadBalancer", reflect.TypeOf((*MockProvider)(nil).DeleteLoadBalancer), arg0) } -func (_m *MockProvider) DeleteLoadBalancerListeners(_param0 string, _param1 []*elb.Listener) error { - ret := _m.ctrl.Call(_m, "DeleteLoadBalancerListeners", _param0, _param1) +// DeleteLoadBalancerListeners mocks base method +func (m *MockProvider) DeleteLoadBalancerListeners(arg0 string, arg1 []*elb.Listener) error { + ret := m.ctrl.Call(m, "DeleteLoadBalancerListeners", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) DeleteLoadBalancerListeners(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteLoadBalancerListeners", arg0, arg1) +// DeleteLoadBalancerListeners indicates an expected call of DeleteLoadBalancerListeners +func (mr *MockProviderMockRecorder) DeleteLoadBalancerListeners(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteLoadBalancerListeners", reflect.TypeOf((*MockProvider)(nil).DeleteLoadBalancerListeners), arg0, arg1) } -func (_m *MockProvider) DeregisterInstancesFromLoadBalancer(_param0 string, _param1 []string) error { - ret := _m.ctrl.Call(_m, "DeregisterInstancesFromLoadBalancer", _param0, _param1) +// DeregisterInstancesFromLoadBalancer mocks base method +func (m *MockProvider) DeregisterInstancesFromLoadBalancer(arg0 string, arg1 []string) error { + ret := m.ctrl.Call(m, "DeregisterInstancesFromLoadBalancer", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) DeregisterInstancesFromLoadBalancer(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeregisterInstancesFromLoadBalancer", arg0, arg1) +// DeregisterInstancesFromLoadBalancer indicates an expected call of DeregisterInstancesFromLoadBalancer +func (mr *MockProviderMockRecorder) DeregisterInstancesFromLoadBalancer(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeregisterInstancesFromLoadBalancer", reflect.TypeOf((*MockProvider)(nil).DeregisterInstancesFromLoadBalancer), arg0, arg1) } -func (_m *MockProvider) DescribeInstanceHealth(_param0 string) ([]*elb.InstanceState, error) { - ret := _m.ctrl.Call(_m, "DescribeInstanceHealth", _param0) +// DescribeInstanceHealth mocks base method +func (m *MockProvider) DescribeInstanceHealth(arg0 string) ([]*elb.InstanceState, error) { + ret := m.ctrl.Call(m, "DescribeInstanceHealth", arg0) ret0, _ := ret[0].([]*elb.InstanceState) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) DescribeInstanceHealth(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DescribeInstanceHealth", arg0) +// DescribeInstanceHealth indicates an expected call of DescribeInstanceHealth +func (mr *MockProviderMockRecorder) DescribeInstanceHealth(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeInstanceHealth", reflect.TypeOf((*MockProvider)(nil).DescribeInstanceHealth), arg0) } -func (_m *MockProvider) DescribeLoadBalancer(_param0 string) (*elb.LoadBalancerDescription, error) { - ret := _m.ctrl.Call(_m, "DescribeLoadBalancer", _param0) +// DescribeLoadBalancer mocks base method +func (m *MockProvider) DescribeLoadBalancer(arg0 string) (*elb.LoadBalancerDescription, error) { + ret := m.ctrl.Call(m, "DescribeLoadBalancer", arg0) ret0, _ := ret[0].(*elb.LoadBalancerDescription) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) DescribeLoadBalancer(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DescribeLoadBalancer", arg0) +// DescribeLoadBalancer indicates an expected call of DescribeLoadBalancer +func (mr *MockProviderMockRecorder) DescribeLoadBalancer(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeLoadBalancer", reflect.TypeOf((*MockProvider)(nil).DescribeLoadBalancer), arg0) } -func (_m *MockProvider) DescribeLoadBalancers() ([]*elb.LoadBalancerDescription, error) { - ret := _m.ctrl.Call(_m, "DescribeLoadBalancers") +// DescribeLoadBalancers mocks base method +func (m *MockProvider) DescribeLoadBalancers() ([]*elb.LoadBalancerDescription, error) { + ret := m.ctrl.Call(m, "DescribeLoadBalancers") ret0, _ := ret[0].([]*elb.LoadBalancerDescription) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) DescribeLoadBalancers() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DescribeLoadBalancers") +// DescribeLoadBalancers indicates an expected call of DescribeLoadBalancers +func (mr *MockProviderMockRecorder) DescribeLoadBalancers() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DescribeLoadBalancers", reflect.TypeOf((*MockProvider)(nil).DescribeLoadBalancers)) } -func (_m *MockProvider) RegisterInstancesWithLoadBalancer(_param0 string, _param1 []string) error { - ret := _m.ctrl.Call(_m, "RegisterInstancesWithLoadBalancer", _param0, _param1) +// RegisterInstancesWithLoadBalancer mocks base method +func (m *MockProvider) RegisterInstancesWithLoadBalancer(arg0 string, arg1 []string) error { + ret := m.ctrl.Call(m, "RegisterInstancesWithLoadBalancer", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) RegisterInstancesWithLoadBalancer(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "RegisterInstancesWithLoadBalancer", arg0, arg1) +// RegisterInstancesWithLoadBalancer indicates an expected call of RegisterInstancesWithLoadBalancer +func (mr *MockProviderMockRecorder) RegisterInstancesWithLoadBalancer(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterInstancesWithLoadBalancer", reflect.TypeOf((*MockProvider)(nil).RegisterInstancesWithLoadBalancer), arg0, arg1) } diff --git a/common/aws/iam/mock_iam/mock_iam.go b/common/aws/iam/mock_iam/mock_iam.go index 9acabf1b6..a730f39a5 100644 --- a/common/aws/iam/mock_iam/mock_iam.go +++ b/common/aws/iam/mock_iam/mock_iam.go @@ -1,158 +1,187 @@ -// Automatically generated by MockGen. DO NOT EDIT! +// Code generated by MockGen. DO NOT EDIT. // Source: github.com/quintilesims/layer0/common/aws/iam (interfaces: Provider) +// Package mock_iam is a generated GoMock package. package mock_iam import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" iam "github.com/quintilesims/layer0/common/aws/iam" ) -// Mock of Provider interface +// MockProvider is a mock of Provider interface type MockProvider struct { ctrl *gomock.Controller - recorder *_MockProviderRecorder + recorder *MockProviderMockRecorder } -// Recorder for MockProvider (not exported) -type _MockProviderRecorder struct { +// MockProviderMockRecorder is the mock recorder for MockProvider +type MockProviderMockRecorder struct { mock *MockProvider } +// NewMockProvider creates a new mock instance func NewMockProvider(ctrl *gomock.Controller) *MockProvider { mock := &MockProvider{ctrl: ctrl} - mock.recorder = &_MockProviderRecorder{mock} + mock.recorder = &MockProviderMockRecorder{mock} return mock } -func (_m *MockProvider) EXPECT() *_MockProviderRecorder { - return _m.recorder +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockProvider) EXPECT() *MockProviderMockRecorder { + return m.recorder } -func (_m *MockProvider) CreateRole(_param0 string, _param1 string) (*iam.Role, error) { - ret := _m.ctrl.Call(_m, "CreateRole", _param0, _param1) +// CreateRole mocks base method +func (m *MockProvider) CreateRole(arg0, arg1 string) (*iam.Role, error) { + ret := m.ctrl.Call(m, "CreateRole", arg0, arg1) ret0, _ := ret[0].(*iam.Role) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) CreateRole(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateRole", arg0, arg1) +// CreateRole indicates an expected call of CreateRole +func (mr *MockProviderMockRecorder) CreateRole(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateRole", reflect.TypeOf((*MockProvider)(nil).CreateRole), arg0, arg1) } -func (_m *MockProvider) DeleteRole(_param0 string) error { - ret := _m.ctrl.Call(_m, "DeleteRole", _param0) +// DeleteRole mocks base method +func (m *MockProvider) DeleteRole(arg0 string) error { + ret := m.ctrl.Call(m, "DeleteRole", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) DeleteRole(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteRole", arg0) +// DeleteRole indicates an expected call of DeleteRole +func (mr *MockProviderMockRecorder) DeleteRole(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteRole", reflect.TypeOf((*MockProvider)(nil).DeleteRole), arg0) } -func (_m *MockProvider) DeleteRolePolicy(_param0 string, _param1 string) error { - ret := _m.ctrl.Call(_m, "DeleteRolePolicy", _param0, _param1) +// DeleteRolePolicy mocks base method +func (m *MockProvider) DeleteRolePolicy(arg0, arg1 string) error { + ret := m.ctrl.Call(m, "DeleteRolePolicy", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) DeleteRolePolicy(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteRolePolicy", arg0, arg1) +// DeleteRolePolicy indicates an expected call of DeleteRolePolicy +func (mr *MockProviderMockRecorder) DeleteRolePolicy(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteRolePolicy", reflect.TypeOf((*MockProvider)(nil).DeleteRolePolicy), arg0, arg1) } -func (_m *MockProvider) DeleteServerCertificate(_param0 string) error { - ret := _m.ctrl.Call(_m, "DeleteServerCertificate", _param0) +// DeleteServerCertificate mocks base method +func (m *MockProvider) DeleteServerCertificate(arg0 string) error { + ret := m.ctrl.Call(m, "DeleteServerCertificate", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) DeleteServerCertificate(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteServerCertificate", arg0) +// DeleteServerCertificate indicates an expected call of DeleteServerCertificate +func (mr *MockProviderMockRecorder) DeleteServerCertificate(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteServerCertificate", reflect.TypeOf((*MockProvider)(nil).DeleteServerCertificate), arg0) } -func (_m *MockProvider) GetAccountId() (string, error) { - ret := _m.ctrl.Call(_m, "GetAccountId") +// GetAccountId mocks base method +func (m *MockProvider) GetAccountId() (string, error) { + ret := m.ctrl.Call(m, "GetAccountId") ret0, _ := ret[0].(string) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) GetAccountId() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetAccountId") +// GetAccountId indicates an expected call of GetAccountId +func (mr *MockProviderMockRecorder) GetAccountId() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccountId", reflect.TypeOf((*MockProvider)(nil).GetAccountId)) } -func (_m *MockProvider) GetRole(_param0 string) (*iam.Role, error) { - ret := _m.ctrl.Call(_m, "GetRole", _param0) +// GetRole mocks base method +func (m *MockProvider) GetRole(arg0 string) (*iam.Role, error) { + ret := m.ctrl.Call(m, "GetRole", arg0) ret0, _ := ret[0].(*iam.Role) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) GetRole(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetRole", arg0) +// GetRole indicates an expected call of GetRole +func (mr *MockProviderMockRecorder) GetRole(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRole", reflect.TypeOf((*MockProvider)(nil).GetRole), arg0) } -func (_m *MockProvider) GetUser(_param0 *string) (*iam.User, error) { - ret := _m.ctrl.Call(_m, "GetUser", _param0) +// GetUser mocks base method +func (m *MockProvider) GetUser(arg0 *string) (*iam.User, error) { + ret := m.ctrl.Call(m, "GetUser", arg0) ret0, _ := ret[0].(*iam.User) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) GetUser(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetUser", arg0) +// GetUser indicates an expected call of GetUser +func (mr *MockProviderMockRecorder) GetUser(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUser", reflect.TypeOf((*MockProvider)(nil).GetUser), arg0) } -func (_m *MockProvider) ListCertificates() ([]*iam.ServerCertificateMetadata, error) { - ret := _m.ctrl.Call(_m, "ListCertificates") +// ListCertificates mocks base method +func (m *MockProvider) ListCertificates() ([]*iam.ServerCertificateMetadata, error) { + ret := m.ctrl.Call(m, "ListCertificates") ret0, _ := ret[0].([]*iam.ServerCertificateMetadata) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) ListCertificates() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListCertificates") +// ListCertificates indicates an expected call of ListCertificates +func (mr *MockProviderMockRecorder) ListCertificates() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListCertificates", reflect.TypeOf((*MockProvider)(nil).ListCertificates)) } -func (_m *MockProvider) ListRolePolicies(_param0 string) ([]*string, error) { - ret := _m.ctrl.Call(_m, "ListRolePolicies", _param0) +// ListRolePolicies mocks base method +func (m *MockProvider) ListRolePolicies(arg0 string) ([]*string, error) { + ret := m.ctrl.Call(m, "ListRolePolicies", arg0) ret0, _ := ret[0].([]*string) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) ListRolePolicies(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListRolePolicies", arg0) +// ListRolePolicies indicates an expected call of ListRolePolicies +func (mr *MockProviderMockRecorder) ListRolePolicies(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListRolePolicies", reflect.TypeOf((*MockProvider)(nil).ListRolePolicies), arg0) } -func (_m *MockProvider) ListRoles() ([]*string, error) { - ret := _m.ctrl.Call(_m, "ListRoles") +// ListRoles mocks base method +func (m *MockProvider) ListRoles() ([]*string, error) { + ret := m.ctrl.Call(m, "ListRoles") ret0, _ := ret[0].([]*string) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) ListRoles() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListRoles") +// ListRoles indicates an expected call of ListRoles +func (mr *MockProviderMockRecorder) ListRoles() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListRoles", reflect.TypeOf((*MockProvider)(nil).ListRoles)) } -func (_m *MockProvider) PutRolePolicy(_param0 string, _param1 string) error { - ret := _m.ctrl.Call(_m, "PutRolePolicy", _param0, _param1) +// PutRolePolicy mocks base method +func (m *MockProvider) PutRolePolicy(arg0, arg1 string) error { + ret := m.ctrl.Call(m, "PutRolePolicy", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) PutRolePolicy(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "PutRolePolicy", arg0, arg1) +// PutRolePolicy indicates an expected call of PutRolePolicy +func (mr *MockProviderMockRecorder) PutRolePolicy(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutRolePolicy", reflect.TypeOf((*MockProvider)(nil).PutRolePolicy), arg0, arg1) } -func (_m *MockProvider) UploadServerCertificate(_param0 string, _param1 string, _param2 string, _param3 string, _param4 *string) (*iam.ServerCertificateMetadata, error) { - ret := _m.ctrl.Call(_m, "UploadServerCertificate", _param0, _param1, _param2, _param3, _param4) +// UploadServerCertificate mocks base method +func (m *MockProvider) UploadServerCertificate(arg0, arg1, arg2, arg3 string, arg4 *string) (*iam.ServerCertificateMetadata, error) { + ret := m.ctrl.Call(m, "UploadServerCertificate", arg0, arg1, arg2, arg3, arg4) ret0, _ := ret[0].(*iam.ServerCertificateMetadata) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) UploadServerCertificate(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "UploadServerCertificate", arg0, arg1, arg2, arg3, arg4) +// UploadServerCertificate indicates an expected call of UploadServerCertificate +func (mr *MockProviderMockRecorder) UploadServerCertificate(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UploadServerCertificate", reflect.TypeOf((*MockProvider)(nil).UploadServerCertificate), arg0, arg1, arg2, arg3, arg4) } diff --git a/common/aws/provider/connection.go b/common/aws/provider/connection.go index 51aba364e..0a6572393 100644 --- a/common/aws/provider/connection.go +++ b/common/aws/provider/connection.go @@ -2,9 +2,10 @@ package provider import ( "fmt" + "time" - "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/credentials" + "github.com/aws/aws-sdk-go/aws/request" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/autoscaling" "github.com/aws/aws-sdk-go/service/cloudformation" @@ -16,6 +17,7 @@ import ( "github.com/aws/aws-sdk-go/service/elb" "github.com/aws/aws-sdk-go/service/iam" "github.com/aws/aws-sdk-go/service/s3" + "github.com/quintilesims/layer0/common/config" ) const ( @@ -70,12 +72,17 @@ var getConfig = func(credProvider CredProvider, region string) (sess *session.Se } creds := credentials.NewStaticCredentials(access_key, secret_key, "") - - awsConfig := &aws.Config{ - Credentials: creds, - Region: aws.String(region), + sess = session.New(config.GetAWSConfig(creds, config.AWSRegion())) + delay, err := time.ParseDuration(config.AWSTimeBetweenRequests()) + if err != nil { + return } - sess = session.New(awsConfig) + + ticker := time.Tick(delay) + sess.Handlers.Send.PushBack(func(r *request.Request) { + <-ticker + }) + return } diff --git a/common/aws/s3/mock_s3/mock_s3.go b/common/aws/s3/mock_s3/mock_s3.go index e83d72871..894ac80c9 100644 --- a/common/aws/s3/mock_s3/mock_s3.go +++ b/common/aws/s3/mock_s3/mock_s3.go @@ -1,93 +1,109 @@ -// Automatically generated by MockGen. DO NOT EDIT! +// Code generated by MockGen. DO NOT EDIT. // Source: github.com/quintilesims/layer0/common/aws/s3 (interfaces: Provider) +// Package mock_s3 is a generated GoMock package. package mock_s3 import ( os "os" + reflect "reflect" gomock "github.com/golang/mock/gomock" ) -// Mock of Provider interface +// MockProvider is a mock of Provider interface type MockProvider struct { ctrl *gomock.Controller - recorder *_MockProviderRecorder + recorder *MockProviderMockRecorder } -// Recorder for MockProvider (not exported) -type _MockProviderRecorder struct { +// MockProviderMockRecorder is the mock recorder for MockProvider +type MockProviderMockRecorder struct { mock *MockProvider } +// NewMockProvider creates a new mock instance func NewMockProvider(ctrl *gomock.Controller) *MockProvider { mock := &MockProvider{ctrl: ctrl} - mock.recorder = &_MockProviderRecorder{mock} + mock.recorder = &MockProviderMockRecorder{mock} return mock } -func (_m *MockProvider) EXPECT() *_MockProviderRecorder { - return _m.recorder +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockProvider) EXPECT() *MockProviderMockRecorder { + return m.recorder } -func (_m *MockProvider) DeleteObject(_param0 string, _param1 string) error { - ret := _m.ctrl.Call(_m, "DeleteObject", _param0, _param1) +// DeleteObject mocks base method +func (m *MockProvider) DeleteObject(arg0, arg1 string) error { + ret := m.ctrl.Call(m, "DeleteObject", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) DeleteObject(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteObject", arg0, arg1) +// DeleteObject indicates an expected call of DeleteObject +func (mr *MockProviderMockRecorder) DeleteObject(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteObject", reflect.TypeOf((*MockProvider)(nil).DeleteObject), arg0, arg1) } -func (_m *MockProvider) GetObject(_param0 string, _param1 string) ([]byte, error) { - ret := _m.ctrl.Call(_m, "GetObject", _param0, _param1) +// GetObject mocks base method +func (m *MockProvider) GetObject(arg0, arg1 string) ([]byte, error) { + ret := m.ctrl.Call(m, "GetObject", arg0, arg1) ret0, _ := ret[0].([]byte) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) GetObject(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetObject", arg0, arg1) +// GetObject indicates an expected call of GetObject +func (mr *MockProviderMockRecorder) GetObject(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetObject", reflect.TypeOf((*MockProvider)(nil).GetObject), arg0, arg1) } -func (_m *MockProvider) GetObjectToFile(_param0 string, _param1 string, _param2 string, _param3 os.FileMode) error { - ret := _m.ctrl.Call(_m, "GetObjectToFile", _param0, _param1, _param2, _param3) +// GetObjectToFile mocks base method +func (m *MockProvider) GetObjectToFile(arg0, arg1, arg2 string, arg3 os.FileMode) error { + ret := m.ctrl.Call(m, "GetObjectToFile", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) GetObjectToFile(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "GetObjectToFile", arg0, arg1, arg2, arg3) +// GetObjectToFile indicates an expected call of GetObjectToFile +func (mr *MockProviderMockRecorder) GetObjectToFile(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetObjectToFile", reflect.TypeOf((*MockProvider)(nil).GetObjectToFile), arg0, arg1, arg2, arg3) } -func (_m *MockProvider) ListObjects(_param0 string, _param1 string) ([]string, error) { - ret := _m.ctrl.Call(_m, "ListObjects", _param0, _param1) +// ListObjects mocks base method +func (m *MockProvider) ListObjects(arg0, arg1 string) ([]string, error) { + ret := m.ctrl.Call(m, "ListObjects", arg0, arg1) ret0, _ := ret[0].([]string) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockProviderRecorder) ListObjects(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "ListObjects", arg0, arg1) +// ListObjects indicates an expected call of ListObjects +func (mr *MockProviderMockRecorder) ListObjects(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListObjects", reflect.TypeOf((*MockProvider)(nil).ListObjects), arg0, arg1) } -func (_m *MockProvider) PutObject(_param0 string, _param1 string, _param2 []byte) error { - ret := _m.ctrl.Call(_m, "PutObject", _param0, _param1, _param2) +// PutObject mocks base method +func (m *MockProvider) PutObject(arg0, arg1 string, arg2 []byte) error { + ret := m.ctrl.Call(m, "PutObject", arg0, arg1, arg2) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) PutObject(arg0, arg1, arg2 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "PutObject", arg0, arg1, arg2) +// PutObject indicates an expected call of PutObject +func (mr *MockProviderMockRecorder) PutObject(arg0, arg1, arg2 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutObject", reflect.TypeOf((*MockProvider)(nil).PutObject), arg0, arg1, arg2) } -func (_m *MockProvider) PutObjectFromFile(_param0 string, _param1 string, _param2 string) error { - ret := _m.ctrl.Call(_m, "PutObjectFromFile", _param0, _param1, _param2) +// PutObjectFromFile mocks base method +func (m *MockProvider) PutObjectFromFile(arg0, arg1, arg2 string) error { + ret := m.ctrl.Call(m, "PutObjectFromFile", arg0, arg1, arg2) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockProviderRecorder) PutObjectFromFile(arg0, arg1, arg2 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "PutObjectFromFile", arg0, arg1, arg2) +// PutObjectFromFile indicates an expected call of PutObjectFromFile +func (mr *MockProviderMockRecorder) PutObjectFromFile(arg0, arg1, arg2 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PutObjectFromFile", reflect.TypeOf((*MockProvider)(nil).PutObjectFromFile), arg0, arg1, arg2) } diff --git a/common/config/aws.go b/common/config/aws.go new file mode 100644 index 000000000..3df3f4281 --- /dev/null +++ b/common/config/aws.go @@ -0,0 +1,15 @@ +package config + +import ( + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/credentials" +) + +func GetAWSConfig(creds *credentials.Credentials, region string) *aws.Config { + awsConfig := &aws.Config{} + awsConfig.WithCredentials(creds) + awsConfig.WithRegion(region) + awsConfig.WithMaxRetries(DEFAULT_MAX_RETRIES) + + return awsConfig +} diff --git a/common/config/config.go b/common/config/config.go index 6c5c8061c..fd61c616b 100644 --- a/common/config/config.go +++ b/common/config/config.go @@ -38,15 +38,17 @@ const ( SKIP_VERSION_VERIFY = "LAYER0_SKIP_VERSION_VERIFY" TEST_AWS_TAG_DYNAMO_TABLE = "LAYER0_TEST_AWS_TAG_DYNAMO_TABLE" TEST_AWS_JOB_DYNAMO_TABLE = "LAYER0_TEST_AWS_JOB_DYNAMO_TABLE" + AWS_TIME_BETWEEN_REQUESTS = "LAYER0_AWS_TIME_BETWEEN_REQUESTS" ) // defaults // bGF5ZXIwOm5vaGF4cGx6 = layer0:nohaxplz, base64 encoded (basic http auth) const ( - DEFAULT_AUTH_TOKEN = "bGF5ZXIwOm5vaGF4cGx6" - DEFAULT_API_ENDPOINT = "http://localhost:9090/" - DEFAULT_API_PORT = "9090" - DEFAULT_AWS_REGION = "us-west-2" + DEFAULT_AUTH_TOKEN = "bGF5ZXIwOm5vaGF4cGx6" + DEFAULT_API_ENDPOINT = "http://localhost:9090/" + DEFAULT_API_PORT = "9090" + DEFAULT_TIME_BETWEEN_REQUESTS = "10ms" + DEFAULT_MAX_RETRIES = 999 ) // api resource tags @@ -72,6 +74,7 @@ var RequiredAPIVariables = []string{ AWS_ECS_INSTANCE_PROFILE, AWS_LINUX_SERVICE_AMI, AWS_WINDOWS_SERVICE_AMI, + AWS_REGION, } var RequiredCLIVariables = []string{} @@ -151,7 +154,7 @@ func AWSSecretKey() string { } func AWSRegion() string { - return getOr(AWS_REGION, DEFAULT_AWS_REGION) + return get(AWS_REGION) } func AWSVPCID() string { @@ -214,6 +217,10 @@ func TestDynamoJobTableName() string { return get(TEST_AWS_JOB_DYNAMO_TABLE) } +func AWSTimeBetweenRequests() string { + return getOr(AWS_TIME_BETWEEN_REQUESTS, DEFAULT_TIME_BETWEEN_REQUESTS) +} + func Prefix() string { return getOr(PREFIX, "l0") } diff --git a/common/db/job_store/mock_job_store/mock_job_store.go b/common/db/job_store/mock_job_store/mock_job_store.go index 623fd2228..e74767a47 100644 --- a/common/db/job_store/mock_job_store/mock_job_store.go +++ b/common/db/job_store/mock_job_store/mock_job_store.go @@ -1,103 +1,122 @@ -// Automatically generated by MockGen. DO NOT EDIT! +// Code generated by MockGen. DO NOT EDIT. // Source: github.com/quintilesims/layer0/common/db/job_store (interfaces: JobStore) +// Package mock_job_store is a generated GoMock package. package mock_job_store import ( + reflect "reflect" + gomock "github.com/golang/mock/gomock" models "github.com/quintilesims/layer0/common/models" types "github.com/quintilesims/layer0/common/types" ) -// Mock of JobStore interface +// MockJobStore is a mock of JobStore interface type MockJobStore struct { ctrl *gomock.Controller - recorder *_MockJobStoreRecorder + recorder *MockJobStoreMockRecorder } -// Recorder for MockJobStore (not exported) -type _MockJobStoreRecorder struct { +// MockJobStoreMockRecorder is the mock recorder for MockJobStore +type MockJobStoreMockRecorder struct { mock *MockJobStore } +// NewMockJobStore creates a new mock instance func NewMockJobStore(ctrl *gomock.Controller) *MockJobStore { mock := &MockJobStore{ctrl: ctrl} - mock.recorder = &_MockJobStoreRecorder{mock} + mock.recorder = &MockJobStoreMockRecorder{mock} return mock } -func (_m *MockJobStore) EXPECT() *_MockJobStoreRecorder { - return _m.recorder +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockJobStore) EXPECT() *MockJobStoreMockRecorder { + return m.recorder } -func (_m *MockJobStore) Delete(_param0 string) error { - ret := _m.ctrl.Call(_m, "Delete", _param0) +// Delete mocks base method +func (m *MockJobStore) Delete(arg0 string) error { + ret := m.ctrl.Call(m, "Delete", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockJobStoreRecorder) Delete(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "Delete", arg0) +// Delete indicates an expected call of Delete +func (mr *MockJobStoreMockRecorder) Delete(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockJobStore)(nil).Delete), arg0) } -func (_m *MockJobStore) Init() error { - ret := _m.ctrl.Call(_m, "Init") +// Init mocks base method +func (m *MockJobStore) Init() error { + ret := m.ctrl.Call(m, "Init") ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockJobStoreRecorder) Init() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "Init") +// Init indicates an expected call of Init +func (mr *MockJobStoreMockRecorder) Init() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Init", reflect.TypeOf((*MockJobStore)(nil).Init)) } -func (_m *MockJobStore) Insert(_param0 *models.Job) error { - ret := _m.ctrl.Call(_m, "Insert", _param0) +// Insert mocks base method +func (m *MockJobStore) Insert(arg0 *models.Job) error { + ret := m.ctrl.Call(m, "Insert", arg0) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockJobStoreRecorder) Insert(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "Insert", arg0) +// Insert indicates an expected call of Insert +func (mr *MockJobStoreMockRecorder) Insert(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Insert", reflect.TypeOf((*MockJobStore)(nil).Insert), arg0) } -func (_m *MockJobStore) SelectAll() ([]*models.Job, error) { - ret := _m.ctrl.Call(_m, "SelectAll") +// SelectAll mocks base method +func (m *MockJobStore) SelectAll() ([]*models.Job, error) { + ret := m.ctrl.Call(m, "SelectAll") ret0, _ := ret[0].([]*models.Job) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockJobStoreRecorder) SelectAll() *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "SelectAll") +// SelectAll indicates an expected call of SelectAll +func (mr *MockJobStoreMockRecorder) SelectAll() *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SelectAll", reflect.TypeOf((*MockJobStore)(nil).SelectAll)) } -func (_m *MockJobStore) SelectByID(_param0 string) (*models.Job, error) { - ret := _m.ctrl.Call(_m, "SelectByID", _param0) +// SelectByID mocks base method +func (m *MockJobStore) SelectByID(arg0 string) (*models.Job, error) { + ret := m.ctrl.Call(m, "SelectByID", arg0) ret0, _ := ret[0].(*models.Job) ret1, _ := ret[1].(error) return ret0, ret1 } -func (_mr *_MockJobStoreRecorder) SelectByID(arg0 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "SelectByID", arg0) +// SelectByID indicates an expected call of SelectByID +func (mr *MockJobStoreMockRecorder) SelectByID(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SelectByID", reflect.TypeOf((*MockJobStore)(nil).SelectByID), arg0) } -func (_m *MockJobStore) SetJobMeta(_param0 string, _param1 map[string]string) error { - ret := _m.ctrl.Call(_m, "SetJobMeta", _param0, _param1) +// SetJobMeta mocks base method +func (m *MockJobStore) SetJobMeta(arg0 string, arg1 map[string]string) error { + ret := m.ctrl.Call(m, "SetJobMeta", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockJobStoreRecorder) SetJobMeta(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "SetJobMeta", arg0, arg1) +// SetJobMeta indicates an expected call of SetJobMeta +func (mr *MockJobStoreMockRecorder) SetJobMeta(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetJobMeta", reflect.TypeOf((*MockJobStore)(nil).SetJobMeta), arg0, arg1) } -func (_m *MockJobStore) UpdateJobStatus(_param0 string, _param1 types.JobStatus) error { - ret := _m.ctrl.Call(_m, "UpdateJobStatus", _param0, _param1) +// UpdateJobStatus mocks base method +func (m *MockJobStore) UpdateJobStatus(arg0 string, arg1 types.JobStatus) error { + ret := m.ctrl.Call(m, "UpdateJobStatus", arg0, arg1) ret0, _ := ret[0].(error) return ret0 } -func (_mr *_MockJobStoreRecorder) UpdateJobStatus(arg0, arg1 interface{}) *gomock.Call { - return _mr.mock.ctrl.RecordCall(_mr.mock, "UpdateJobStatus", arg0, arg1) +// UpdateJobStatus indicates an expected call of UpdateJobStatus +func (mr *MockJobStoreMockRecorder) UpdateJobStatus(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateJobStatus", reflect.TypeOf((*MockJobStore)(nil).UpdateJobStatus), arg0, arg1) } diff --git a/common/logutils/loggers.go b/common/logutils/loggers.go index 47dfb1414..a71a28c25 100644 --- a/common/logutils/loggers.go +++ b/common/logutils/loggers.go @@ -19,17 +19,6 @@ type StandardFormatter struct { Name string } -func NewStandardLogger(name string) *logrus.Logger { - logger := &logrus.Logger{ - Out: os.Stderr, - Formatter: &StandardFormatter{Name: name}, - Hooks: make(logrus.LevelHooks), - Level: logrus.GetLevel(), - } - - return logger -} - func (this *StandardFormatter) Format(entry *logrus.Entry) ([]byte, error) { time := entry.Time.Format(TIME_FORMAT) level := strings.ToUpper(entry.Level.String()) @@ -41,6 +30,29 @@ func (this *StandardFormatter) Format(entry *logrus.Entry) ([]byte, error) { return []byte(content), nil } +type StandardLogger struct { + *logrus.Logger +} + +func NewStandardLogger(name string) *StandardLogger { + return &StandardLogger{ + &logrus.Logger{ + Out: os.Stderr, + Formatter: &StandardFormatter{Name: name}, + Hooks: make(logrus.LevelHooks), + Level: logrus.GetLevel(), + }, + } +} + +func (s *StandardLogger) Log(tokens ...interface{}) { + s.Logger.Info(tokens...) +} + +func (s *StandardLogger) Logf(format string, tokens ...interface{}) { + s.Logger.Infof(format, tokens...) +} + type CLIFormatter struct{} func (c *CLIFormatter) Format(entry *logrus.Entry) ([]byte, error) { @@ -57,7 +69,7 @@ func NewStackTraceLogger(name string) *logrus.Logger { logger := NewStandardLogger(name) logger.Formatter = &StackTraceFormatter{logger.Formatter.(*StandardFormatter)} - return logger + return logger.Logger } func (this *StackTraceFormatter) Format(entry *logrus.Entry) ([]byte, error) { diff --git a/common/models/create_task_request.go b/common/models/create_task_request.go index 6a3a5a8d9..609d77af1 100644 --- a/common/models/create_task_request.go +++ b/common/models/create_task_request.go @@ -2,7 +2,6 @@ package models type CreateTaskRequest struct { ContainerOverrides []ContainerOverride `json:"container_overrides"` - Copies int `json:"copies"` DeployID string `json:"deploy_id"` EnvironmentID string `json:"environment_id"` TaskName string `json:"task_name"` diff --git a/common/models/task.go b/common/models/task.go index 261c8d5a0..d437dba80 100644 --- a/common/models/task.go +++ b/common/models/task.go @@ -5,7 +5,6 @@ type Task struct { DeployID string `json:"deploy_id"` DeployName string `json:"deploy_name"` DeployVersion string `json:"deploy_version"` - DesiredCount int64 `json:"desired_count"` EnvironmentID string `json:"environment_id"` EnvironmentName string `json:"environment_name"` PendingCount int64 `json:"pending_count"` diff --git a/common/startup/startup.go b/common/startup/startup.go index 59740f9a6..0bdd6e535 100644 --- a/common/startup/startup.go +++ b/common/startup/startup.go @@ -1,8 +1,10 @@ package startup import ( - "github.com/aws/aws-sdk-go/aws" + "time" + "github.com/aws/aws-sdk-go/aws/credentials" + "github.com/aws/aws-sdk-go/aws/request" "github.com/aws/aws-sdk-go/aws/session" "github.com/quintilesims/layer0/api/backend/ecs" "github.com/quintilesims/layer0/api/logic" @@ -126,12 +128,11 @@ func GetLogic(backend *ecsbackend.ECSBackend) (*logic.Logic, error) { func getNewTagStore() (tag_store.TagStore, error) { creds := credentials.NewStaticCredentials(config.AWSAccessKey(), config.AWSSecretKey(), "") - awsConfig := &aws.Config{ - Credentials: creds, - Region: aws.String(config.AWSRegion()), + session := session.New(config.GetAWSConfig(creds, config.AWSRegion())) + if err := sessionTimeDelay(session); err != nil { + return nil, err } - session := session.New(awsConfig) store := tag_store.NewDynamoTagStore(session, config.DynamoTagTableName()) if err := store.Init(); err != nil { @@ -143,12 +144,11 @@ func getNewTagStore() (tag_store.TagStore, error) { func getNewJobStore() (job_store.JobStore, error) { creds := credentials.NewStaticCredentials(config.AWSAccessKey(), config.AWSSecretKey(), "") - awsConfig := &aws.Config{ - Credentials: creds, - Region: aws.String(config.AWSRegion()), + session := session.New(config.GetAWSConfig(creds, config.AWSRegion())) + if err := sessionTimeDelay(session); err != nil { + return nil, err } - session := session.New(awsConfig) store := job_store.NewDynamoJobStore(session, config.DynamoJobTableName()) if err := store.Init(); err != nil { @@ -158,6 +158,20 @@ func getNewJobStore() (job_store.JobStore, error) { return store, nil } +func sessionTimeDelay(session *session.Session) error { + delay, err := time.ParseDuration(config.AWSTimeBetweenRequests()) + if err != nil { + return err + } + + ticker := time.Tick(delay) + session.Handlers.Send.PushBack(func(r *request.Request) { + <-ticker + }) + + return nil +} + func wrapECS(e ecs.Provider) ecs.Provider { retry := &decorators.Retry{ Clock: waitutils.RealClock{}, diff --git a/common/testutils/functions.go b/common/testutils/functions.go index 10441d306..b053efab5 100644 --- a/common/testutils/functions.go +++ b/common/testutils/functions.go @@ -2,11 +2,10 @@ package testutils import ( "reflect" - "testing" "time" ) -func AssertEqual(t *testing.T, result, expected interface{}) { +func AssertEqual(t Tester, result, expected interface{}) { if !reflect.DeepEqual(result, expected) { t.Fatalf( "\n\tObserved: %#v (%v) \n\tExpected: %#v (%v)", @@ -17,11 +16,11 @@ func AssertEqual(t *testing.T, result, expected interface{}) { } } -func AssertAny(t *testing.T, result interface{}, expected ...interface{}) { +func AssertAny(t Tester, result interface{}, expected ...interface{}) { AssertInSlice(t, result, expected) } -func AssertInSlice(t *testing.T, expected, slice interface{}) { +func AssertInSlice(t Tester, expected, slice interface{}) { if reflect.TypeOf(slice).Kind() != reflect.Slice { t.Fatalf("\n\t%v (%v) is not a slice", slice, reflect.TypeOf(slice)) return @@ -43,7 +42,7 @@ func AssertInSlice(t *testing.T, expected, slice interface{}) { reflect.TypeOf(slice)) } -func WaitFor(t *testing.T, interval, timeout time.Duration, conditionSatisfied func() bool) { +func WaitFor(t Tester, interval, timeout time.Duration, conditionSatisfied func() bool) { for start := time.Now(); time.Since(start) < timeout; time.Sleep(interval) { if conditionSatisfied() { return diff --git a/common/testutils/tester_interface.go b/common/testutils/tester_interface.go new file mode 100644 index 000000000..1cddcc9d4 --- /dev/null +++ b/common/testutils/tester_interface.go @@ -0,0 +1,6 @@ +package testutils + +type Tester interface { + Fatal(tokens ...interface{}) + Fatalf(format string, tokens ...interface{}) +} diff --git a/runner/job/task.go b/runner/job/task.go index 888d12663..0c969330b 100644 --- a/runner/job/task.go +++ b/runner/job/task.go @@ -40,22 +40,20 @@ func CreateTask(quit chan bool, context *JobContext) error { return err } - for i := 0; i < createTaskRequest.Copies; i++ { - if err := runAndRetry(quit, time.Second*10, func() error { - log.Infof("Running Action: CreateTask '%s', copy %d", createTaskRequest.TaskName, i) - task, err := context.TaskLogic.CreateTask(createTaskRequest) - if err != nil { - log.Infof("Failed CreateTask '%s', copy %d", createTaskRequest.TaskName, i) - return err - } - - return runAndRetry(quit, time.Second*10, func() error { - key := fmt.Sprintf("task_%d", i) - return context.AddJobMeta(key, task.TaskID) - }) - }); err != nil { + if err := runAndRetry(quit, time.Second*10, func() error { + log.Infof("Running Action: CreateTask '%s'", createTaskRequest.TaskName) + taskID, err := context.TaskLogic.CreateTask(createTaskRequest) + if err != nil { + log.Infof("Failed CreateTask '%s'", createTaskRequest.TaskName) return err } + + return runAndRetry(quit, time.Second*10, func() error { + key := fmt.Sprintf("task_id") + return context.AddJobMeta(key, taskID) + }) + }); err != nil { + return err } return nil diff --git a/scripts/Makefile.decorators b/scripts/Makefile.decorators index 07a7e5433..e430d70d1 100644 --- a/scripts/Makefile.decorators +++ b/scripts/Makefile.decorators @@ -1,6 +1,6 @@ deps: - go get github.com/imshealth/go-decorator - go install github.com/imshealth/go-decorator + go get github.com/quintilesims/go-decorator + go install github.com/quintilesims/go-decorator all: autoscaling ec2 ecs elb cloudwatchlogs diff --git a/scripts/flow.sh b/scripts/flow.sh index 1bb38e75a..5ff45602f 100755 --- a/scripts/flow.sh +++ b/scripts/flow.sh @@ -4,7 +4,7 @@ set -e # kill all subprocesses on exit trap 'if [ ! -z "$(jobs -pr)" ]; then kill $(jobs -pr); fi' EXIT -BULLET='\u2713' +BULLET='-' GIT_HASH=$(git describe --tags) LAYER0_PATH=$GOPATH/src/github.com/quintilesims/layer0 diff --git a/setup/command/endpoint.go b/setup/command/endpoint.go index aacc85ff7..eadb6c54b 100644 --- a/setup/command/endpoint.go +++ b/setup/command/endpoint.go @@ -55,6 +55,7 @@ func (f *CommandFactory) Endpoint() cli.Command { outputEnvvars[instance.OUTPUT_WINDOWS_SERVICE_AMI] = config.AWS_WINDOWS_SERVICE_AMI outputEnvvars[instance.OUTPUT_AWS_DYNAMO_TAG_TABLE] = config.AWS_DYNAMO_TAG_TABLE outputEnvvars[instance.OUTPUT_AWS_DYNAMO_JOB_TABLE] = config.AWS_DYNAMO_JOB_TABLE + outputEnvvars[instance.OUTPUT_AWS_REGION] = config.AWS_REGION } fmt.Println("# set the following environment variables in your current session: ") diff --git a/setup/command/endpoint_test.go b/setup/command/endpoint_test.go index a3df4762f..ed0fa602f 100644 --- a/setup/command/endpoint_test.go +++ b/setup/command/endpoint_test.go @@ -68,6 +68,7 @@ func TestEndpointDev(t *testing.T) { instance.OUTPUT_WINDOWS_SERVICE_AMI, instance.OUTPUT_AWS_DYNAMO_TAG_TABLE, instance.OUTPUT_AWS_DYNAMO_JOB_TABLE, + instance.OUTPUT_AWS_REGION, } for _, output := range outputs { diff --git a/setup/command/init.go b/setup/command/init.go index 009202f0f..b5db175aa 100644 --- a/setup/command/init.go +++ b/setup/command/init.go @@ -24,7 +24,7 @@ func (f *CommandFactory) Init() cli.Command { }, cli.StringFlag{ Name: "version", - Usage: instance.INPUT_VERSION_DESCRIPTION, + Usage: instance.INPUT_LAYER0_VERSION_DESCRIPTION, }, cli.StringFlag{ Name: "aws-access-key", diff --git a/setup/instance/init.go b/setup/instance/init.go index 3cc3a181e..67ba9ef1f 100644 --- a/setup/instance/init.go +++ b/setup/instance/init.go @@ -45,6 +45,11 @@ func (l *LocalInstance) Init(dockerInputPath string, inputOverrides map[string]i return err } + // run `terraform init` to initialize terraform + if err := l.Terraform.Init(l.Dir); err != nil { + return err + } + // validate the terraform configuration if err := l.Terraform.Validate(l.Dir); err != nil { return err diff --git a/setup/instance/inputs.go b/setup/instance/inputs.go index a547154ef..a84110e5a 100644 --- a/setup/instance/inputs.go +++ b/setup/instance/inputs.go @@ -11,7 +11,7 @@ const LAYER0_MODULE_SOURCE = "github.com/quintilesims/layer0//setup/module" const ( INPUT_SOURCE = "source" - INPUT_VERSION = "version" + INPUT_LAYER0_VERSION = "layer0_version" INPUT_AWS_ACCESS_KEY = "access_key" INPUT_AWS_SECRET_KEY = "secret_key" INPUT_AWS_REGION = "region" @@ -29,7 +29,7 @@ as this l0-setup binary. Using values other than the default may result in undesired consequences (the double slash is intentional). ` -const INPUT_VERSION_DESCRIPTION = ` +const INPUT_LAYER0_VERSION_DESCRIPTION = ` Version: The version input variable specifies the tag to use for the Layer0 Docker images 'quintilesims/l0-api' and 'quintilesims/l0-runner'. This value should match the version specified in the 'source' input variable. For example, @@ -56,12 +56,12 @@ Layer0 API will use its own key with limited permissions to provision AWS resour const INPUT_AWS_REGION_DESCRIPTION = ` AWS Region: The region input variable specifies which region to provision the -AWS resources required for Layer0. The following regions can be used: +AWS resources required for Layer0. Regions that support the following services can be used: - - us-west-1 - - us-west-2 - - us-east-1 - - eu-west-1 + - ECS + - VPC + - S3 + - DynamoDB Note that changing this value will destroy and recreate any existing resources. ` @@ -116,7 +116,7 @@ func InitializeLayer0ModuleInputs(version string) { switch input.Name { case INPUT_SOURCE: input.Default = fmt.Sprintf("%s?ref=%s", LAYER0_MODULE_SOURCE, version) - case INPUT_VERSION: + case INPUT_LAYER0_VERSION: input.Default = version } } @@ -130,8 +130,8 @@ var Layer0ModuleInputs = []*ModuleInput{ prompter: RequiredStringPrompter, }, { - Name: INPUT_VERSION, - Description: INPUT_VERSION_DESCRIPTION, + Name: INPUT_LAYER0_VERSION, + Description: INPUT_LAYER0_VERSION_DESCRIPTION, Default: "latest", prompter: RequiredStringPrompter, }, diff --git a/setup/instance/outputs.go b/setup/instance/outputs.go index 8b3d9a6b5..57e5d5cff 100644 --- a/setup/instance/outputs.go +++ b/setup/instance/outputs.go @@ -19,4 +19,5 @@ const ( OUTPUT_WINDOWS_SERVICE_AMI = "windows_service_ami" OUTPUT_AWS_DYNAMO_TAG_TABLE = "dynamo_tag_table" OUTPUT_AWS_DYNAMO_JOB_TABLE = "dynamo_job_table" + OUTPUT_AWS_REGION = "region" ) diff --git a/setup/instance/upgrade.go b/setup/instance/upgrade.go index 17499b4b9..e7760c233 100644 --- a/setup/instance/upgrade.go +++ b/setup/instance/upgrade.go @@ -27,7 +27,7 @@ func (l *LocalInstance) Upgrade(version string, force bool) error { module := config.Modules["layer0"] // only patch upgrades are allowed - if current, ok := module["version"]; ok && !force { + if current, ok := module["layer0_version"]; ok && !force { if err := assertPatchUpgrade(current.(string), version); err != nil { return err } @@ -35,8 +35,8 @@ func (l *LocalInstance) Upgrade(version string, force bool) error { // set new input values for 'source' and 'version' inputValues := map[string]string{ - INPUT_SOURCE: fmt.Sprintf("%s?ref=%v", LAYER0_MODULE_SOURCE, version), - INPUT_VERSION: version, + INPUT_SOURCE: fmt.Sprintf("%s?ref=%v", LAYER0_MODULE_SOURCE, version), + INPUT_LAYER0_VERSION: version, } for input, value := range inputValues { @@ -76,7 +76,9 @@ func assertPatchUpgrade(currentVersion, desiredVersion string) error { current, err := semver.Make(currentVersion) if err != nil { - return fmt.Errorf("Failed to parse current version: %v", err) + text := fmt.Sprintf("Failed to parse current version ('%s'): %v\n", currentVersion, err) + text += "Use --force to disable semantic version checking" + return fmt.Errorf(text) } desired, err := semver.Make(desiredVersion) diff --git a/setup/main.go b/setup/main.go index 6a9418d8b..82e53035c 100644 --- a/setup/main.go +++ b/setup/main.go @@ -67,7 +67,7 @@ func main() { logger := logutils.NewStandardLogger("") logger.Formatter = &logutils.CLIFormatter{} - logutils.SetGlobalLogger(logger) + logutils.SetGlobalLogger(logger.Logger) instance.InitializeLayer0ModuleInputs(Version) diff --git a/setup/module/README.md b/setup/module/README.md index d876d4af6..dbe6b7bb2 100644 --- a/setup/module/README.md +++ b/setup/module/README.md @@ -7,7 +7,7 @@ Module Input Variables ---------------------- - `name` - Layer0 instance name -- `version` - Version of Layer0 to use +- `layer0_version` - Version of Layer0 to use - `access_key` - AWS Access Key ID to manage resources - `secret_key` - AWS Secret Access Key to manage resources - `region` - AWS Region to manage resources @@ -26,7 +26,7 @@ Usage module "layer0" { source = "https://github.com/quintilesims/layer0/setup//layer0?ref=v1.0.0" name = "foobar" - version = "v1.0.0" + layer0_version = "v1.0.0" access_key = "ABC123" secret_key = "ABC123" region = "us-west-2" diff --git a/setup/module/api/Dockerrun.aws.json b/setup/module/api/Dockerrun.aws.json index c847bd415..486696a4a 100644 --- a/setup/module/api/Dockerrun.aws.json +++ b/setup/module/api/Dockerrun.aws.json @@ -1,7 +1,7 @@ [ { "name": "api", - "image": "quintilesims/l0-api:${version}", + "image": "quintilesims/l0-api:${layer0_version}", "essential": true, "memory": 500, "portMappings": [ @@ -33,7 +33,7 @@ { "name": "LAYER0_AWS_DYNAMO_TAG_TABLE", "value": "${dynamo_tag_table}" }, { "name": "LAYER0_AWS_DYNAMO_JOB_TABLE", "value": "${dynamo_job_table}" }, { "name": "LAYER0_AUTH_TOKEN", "value": "${api_auth_token}" }, - { "name": "LAYER0_RUNNER_VERSION_TAG", "value": "${version}" }, + { "name": "LAYER0_RUNNER_VERSION_TAG", "value": "${layer0_version}" }, { "name": "LAYER0_AWS_ECS_ROLE", "value": "${ecs_role}" }, { "name": "LAYER0_AWS_SSH_KEY_PAIR", "value": "${ssh_key_pair}" }, { "name": "LAYER0_AWS_ACCOUNT_ID", "value": "${account_id}" }, diff --git a/setup/module/api/core.tf b/setup/module/api/core.tf index 2346dd031..cc0f0b630 100644 --- a/setup/module/api/core.tf +++ b/setup/module/api/core.tf @@ -104,3 +104,31 @@ resource "aws_iam_group_policy" "mod" { group = "${aws_iam_group.mod.id}" policy = "${element(data.template_file.group_policy.*.rendered, count.index)}" } + +data "aws_ami" "linux" { + most_recent = true + + filter { + name = "owner-alias" + values = ["amazon"] + } + + filter { + name = "name" + values = ["amzn-ami-2017.09.d-amazon-ecs-optimized"] + } +} + +data "aws_ami" "windows" { + most_recent = true + + filter { + name = "owner-alias" + values = ["amazon"] + } + + filter { + name = "name" + values = ["Windows_Server-2016-English-Full-ECS_Optimized-2017.11.24"] + } +} diff --git a/setup/module/api/deploy.tf b/setup/module/api/deploy.tf index c566798e2..7e9eb3c23 100644 --- a/setup/module/api/deploy.tf +++ b/setup/module/api/deploy.tf @@ -8,7 +8,7 @@ data "template_file" "container_definitions" { vars { api_auth_token = "${base64encode("${var.username}:${var.password}")}" - version = "${var.version}" + layer0_version = "${var.layer0_version}" access_key = "${aws_iam_access_key.mod.id}" secret_key = "${aws_iam_access_key.mod.secret}" region = "${var.region}" @@ -18,8 +18,8 @@ data "template_file" "container_definitions" { ecs_instance_profile = "${aws_iam_instance_profile.ecs.id}" vpc_id = "${var.vpc_id}" s3_bucket = "${aws_s3_bucket.mod.id}" - linux_service_ami = "${lookup(var.linux_region_amis, var.region)}" - windows_service_ami = "${lookup(var.windows_region_amis, var.region)}" + linux_service_ami = "${data.aws_ami.linux.id}" + windows_service_ami = "${data.aws_ami.windows.id}" l0_prefix = "${var.name}" account_id = "${data.aws_caller_identity.current.account_id}" ssh_key_pair = "${var.ssh_key_pair}" diff --git a/setup/module/api/environment.tf b/setup/module/api/environment.tf index 25ce868f6..568f3a9c8 100644 --- a/setup/module/api/environment.tf +++ b/setup/module/api/environment.tf @@ -34,7 +34,7 @@ data "template_file" "user_data" { resource "aws_launch_configuration" "api" { name_prefix = "l0-${var.name}-api-" - image_id = "${lookup(var.linux_region_amis, var.region)}" + image_id = "${data.aws_ami.linux.id}" instance_type = "t2.small" security_groups = ["${aws_security_group.api_env.id}"] iam_instance_profile = "${aws_iam_instance_profile.ecs.id}" diff --git a/setup/module/api/outputs.tf b/setup/module/api/outputs.tf index 953b691e5..4388c97e5 100644 --- a/setup/module/api/outputs.tf +++ b/setup/module/api/outputs.tf @@ -15,11 +15,11 @@ output "private_subnets" { } output "linux_service_ami" { - value = "${lookup(var.linux_region_amis, var.region)}" + value = "${data.aws_ami.linux.id}" } output "windows_service_ami" { - value = "${lookup(var.windows_region_amis, var.region)}" + value = "${data.aws_ami.windows.id}" } output "bucket_name" { @@ -47,9 +47,9 @@ output "user_secret_key" { } output "dynamo_tag_table" { - value = "${aws_dynamodb_table.tags.id}" + value = "${aws_dynamodb_table.tags.id}" } output "dynamo_job_table" { - value = "${aws_dynamodb_table.jobs.id}" + value = "${aws_dynamodb_table.jobs.id}" } diff --git a/setup/module/api/policies/ecs_role_policy.json b/setup/module/api/policies/ecs_role_policy.json index 71de124da..ad60e9d9e 100644 --- a/setup/module/api/policies/ecs_role_policy.json +++ b/setup/module/api/policies/ecs_role_policy.json @@ -12,6 +12,7 @@ "ecs:DiscoverPollEndpoint", "ecs:Submit*", "ecs:Poll", + "ecs:StartTelemetrySession", "logs:CreateLogStream", "logs:PutLogEvents", "logs:CreateLogGroup", diff --git a/setup/module/api/variables.tf b/setup/module/api/variables.tf index 3e044b6d4..a8be99055 100644 --- a/setup/module/api/variables.tf +++ b/setup/module/api/variables.tf @@ -4,7 +4,7 @@ variable "name" {} variable "region" {} -variable "version" {} +variable "layer0_version" {} variable "vpc_id" {} @@ -21,26 +21,6 @@ variable "tags" { default = {} } -# Current AMI: amzn-ami-2016.09.g-amazon-ecs-optimized -variable "linux_region_amis" { - default = { - us-west-1 = "ami-689bc208" - us-west-2 = "ami-62d35c02" - us-east-1 = "ami-62745007" - eu-west-1 = "ami-95f8d2f3" - } -} - -# Current AMI: Microsoft Windows Server 2016 Base with Containers -variable "windows_region_amis" { - default = { - us-west-1 = "ami-7c2b0e1c" - us-west-2 = "ami-7729b917" - us-east-1 = "ami-9667ef80" - eu-west-1 = "ami-b9fac0df" - } -} - variable "group_policies" { default = [ "autoscaling", diff --git a/setup/module/main.tf b/setup/module/main.tf index 0787a89c3..8a810d1ea 100644 --- a/setup/module/main.tf +++ b/setup/module/main.tf @@ -10,12 +10,9 @@ module "vpc" { # todo: count_hack is workaround for https://github.com/hashicorp/terraform/issues/953 count_hack = "${ var.vpc_id == "" ? 1 : 0 }" - source = "./vpc" - name = "${var.name}" - cidr = "10.100.0.0/16" - private_subnets = ["10.100.1.0/24", "10.100.2.0/24", "10.100.3.0/24"] - public_subnets = ["10.100.101.0/24", "10.100.102.0/24", "10.100.103.0/24"] - azs = ["${var.region}a", "${var.region}b", "${var.region}c"] + source = "./vpc" + name = "${var.name}" + cidr = "10.100.0.0/16" tags { "layer0" = "${var.name}" @@ -23,12 +20,12 @@ module "vpc" { } module "api" { - source = "./api" - name = "${var.name}" - region = "${var.region}" - version = "${var.version}" - username = "${var.username}" - password = "${var.password}" + source = "./api" + name = "${var.name}" + region = "${var.region}" + layer0_version = "${var.layer0_version}" + username = "${var.username}" + password = "${var.password}" # todo: format hack is a workaround for https://github.com/hashicorp/terraform/issues/14399 vpc_id = "${ var.vpc_id == "" ? format("%s", module.vpc.vpc_id) : var.vpc_id }" diff --git a/setup/module/outputs.tf b/setup/module/outputs.tf index 70af7a9ad..9ec75e917 100644 --- a/setup/module/outputs.tf +++ b/setup/module/outputs.tf @@ -59,9 +59,13 @@ output "windows_service_ami" { } output "dynamo_tag_table" { - value = "${module.api.dynamo_tag_table}" + value = "${module.api.dynamo_tag_table}" } output "dynamo_job_table" { - value = "${module.api.dynamo_job_table}" + value = "${module.api.dynamo_job_table}" +} + +output "region" { + value = "${var.region}" } diff --git a/setup/module/variables.tf b/setup/module/variables.tf index 62491dca1..bbd8450d9 100644 --- a/setup/module/variables.tf +++ b/setup/module/variables.tf @@ -1,6 +1,6 @@ variable "name" {} -variable "version" {} +variable "layer0_version" {} variable "access_key" {} diff --git a/setup/module/vpc/main.tf b/setup/module/vpc/main.tf index f39f05be9..bcfb54b3a 100644 --- a/setup/module/vpc/main.tf +++ b/setup/module/vpc/main.tf @@ -1,3 +1,5 @@ +data "aws_availability_zones" "available" {} + resource "aws_vpc" "mod" { count = "${var.count_hack}" @@ -46,18 +48,18 @@ resource "aws_route_table" "private" { resource "aws_subnet" "private" { vpc_id = "${aws_vpc.mod.id}" - cidr_block = "${var.private_subnets[count.index]}" - availability_zone = "${element(var.azs, count.index)}" - count = "${length(var.private_subnets) * var.count_hack}" - tags = "${merge(var.tags, map("Tier", "Private"), map("Name", format("l0-%s-subnet-private-%s", var.name, element(var.azs, count.index))))}" + cidr_block = "${cidrsubnet(aws_vpc.mod.cidr_block, 8, count.index + 1)}" + availability_zone = "${element(data.aws_availability_zones.available.names, count.index)}" + count = "${length(data.aws_availability_zones.available.names) * var.count_hack}" + tags = "${merge(var.tags, map("Tier", "Private"), map("Name", format("l0-%s-subnet-private-%s", var.name, element(data.aws_availability_zones.available.names, count.index))))}" } resource "aws_subnet" "public" { vpc_id = "${aws_vpc.mod.id}" - cidr_block = "${var.public_subnets[count.index]}" - availability_zone = "${element(var.azs, count.index)}" - count = "${length(var.public_subnets) * var.count_hack}" - tags = "${merge(var.tags, map("Tier", "Public"), map("Name", format("l0-%s-subnet-public-%s", var.name, element(var.azs, count.index))))}" + cidr_block = "${cidrsubnet(aws_vpc.mod.cidr_block, 8, count.index + 1 + 100)}" + availability_zone = "${element(data.aws_availability_zones.available.names, count.index)}" + count = "${length(data.aws_availability_zones.available.names) * var.count_hack}" + tags = "${merge(var.tags, map("Tier", "Public"), map("Name", format("l0-%s-subnet-public-%s", var.name, element(data.aws_availability_zones.available.names, count.index))))}" map_public_ip_on_launch = "${var.map_public_ip_on_launch}" } @@ -78,13 +80,13 @@ resource "aws_nat_gateway" "natgw" { } resource "aws_route_table_association" "private" { - count = "${length(var.private_subnets) * var.count_hack}" + count = "${length(data.aws_availability_zones.available.names) * var.count_hack}" subnet_id = "${element(aws_subnet.private.*.id, count.index)}" route_table_id = "${aws_route_table.private.id}" } resource "aws_route_table_association" "public" { - count = "${length(var.public_subnets) * var.count_hack}" + count = "${length(data.aws_availability_zones.available.names) * var.count_hack}" subnet_id = "${element(aws_subnet.public.*.id, count.index)}" route_table_id = "${aws_route_table.public.id}" } diff --git a/setup/module/vpc/outputs.tf b/setup/module/vpc/outputs.tf index 2d8c4a176..411132248 100644 --- a/setup/module/vpc/outputs.tf +++ b/setup/module/vpc/outputs.tf @@ -20,7 +20,7 @@ output "private_route_table_ids" { } output "default_security_group_id" { - value = "${aws_vpc.mod.default_security_group_id}" + value = "${element(aws_vpc.mod.*.default_security_group_id, 0) }" } output "nat_eips" { @@ -36,5 +36,5 @@ output "natgw_ids" { } output "igw_id" { - value = "${aws_internet_gateway.mod.id}" + value = "${element(aws_internet_gateway.mod.*.id, 0) }" } diff --git a/setup/module/vpc/variables.tf b/setup/module/vpc/variables.tf index f836758e9..108c23202 100644 --- a/setup/module/vpc/variables.tf +++ b/setup/module/vpc/variables.tf @@ -4,21 +4,6 @@ variable "name" {} variable "cidr" {} -variable "public_subnets" { - description = "A list of public subnets inside the VPC." - default = [] -} - -variable "private_subnets" { - description = "A list of private subnets inside the VPC." - default = [] -} - -variable "azs" { - description = "A list of Availability zones in the region" - default = [] -} - variable "map_public_ip_on_launch" { description = "Auto-assign public IP on launch" default = false diff --git a/setup/terraform/terraform.go b/setup/terraform/terraform.go index 4f6529f2c..c9f0b6034 100644 --- a/setup/terraform/terraform.go +++ b/setup/terraform/terraform.go @@ -39,6 +39,10 @@ func (t *Terraform) Get(dir string) error { return t.run(dir, "get", "-update") } +func (t *Terraform) Init(dir string) error { + return t.run(dir, "init", "-no-color") +} + func (t *Terraform) Output(dir, key string) (string, error) { if err := t.validateTerraformVersion(); err != nil { return "", err diff --git a/tests/README.md b/tests/README.md index fa1578a3c..f13f18787 100644 --- a/tests/README.md +++ b/tests/README.md @@ -64,8 +64,50 @@ When developing a system test, waiting for terraform to setup/destroy the test r Using this method, you can run your test multiple times without terraform destroying and rebuilding the resources. Some useful builtin flags: -* `-run nameOfTest` - Executes tests that match the specified name (can be used to run a single test case). +* `-run nameOfTest` - Executes tests that match the specified name (can be used to run a single test case, or given a param that matches nothing to only run other types of tests). +* `-bench PathOrFileOrTest` - Executes benchmark tests that match the specified identifier. * `-parallel n` - Specifies the number of tests to run in parallel at once. * `-short` - Execute the tests in short mode. Long running tests will be skipped. * `-timeout t` - Specifies the timeout for the tests. The default is `10m`, which typically isn't long enough to complete all of the system tests. + +### WARNING: Stress Tests and Service Limits +The stress tests intentionally create and destroy a lot of AWS resources, so you should be aware of the AWS service limits on the account in which these tests will be run. +Stress tests will create configurations of different combinations of Environments, Deploys, Services and Load Balancers. + +Currently, the known limits per resource are as follows: + +* Environments + +Cannot exceed 100 clusters per AWS region. + +* Deploys + +If you try to create more than 100 Deploys at a time, you will encounter EOF error messages + +* Services + +The number of Services you can create will be dependent on the number of Environments and Deploys. The higher the number of Environments and Deploys, the fewer the number of Services. +Generally, you want to create no more than 25 Services at a time. + +* Load Balancers + +The default limit for AWS Elastic Load Balancing is set to 20 per AWS region. + +It is recommended that you use [flow](https://github.com/quintilesims/layer0/blob/develop/scripts/flow.sh) to clean out your layer0 instance prior to running the stress tests. + +If you enounter an error running the Stress tests, and you have exceeded the number of allowed Environments, you will see the following error message: + +``` +AWS Error: clusters cannot have more than 100 elements (code 'InvalidParameterException') +``` + +If an error like this occurs, you will have to manually enter the AWS console and terminate resources by hand until you're back under the limits. +You may then programatically use Layer0 to destroy the remainder (using [flow](https://github.com/quintilesims/layer0/blob/develop/scripts/flow.sh)) + +To avoid such a scenario, before you run the stress tests, comment out specific functions that will exceed your service limits, or modify the parameters of some of the stress test functions. + +Some references: +* [Viewing account-specific EC2-related service limits](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-resource-limits.html) +* [General ECS service limits](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/service_limits.html) +* [General list of AWS service limits](https://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html) diff --git a/tests/smoke/task.bats b/tests/smoke/task.bats index 49cf8e43f..e058d06e4 100644 --- a/tests/smoke/task.bats +++ b/tests/smoke/task.bats @@ -12,8 +12,8 @@ l0 task create --wait test task1 alpine:latest } -@test "task create --copies 2 --env alpine:key=val test task2 alpine:latest" { - l0 task create --copies 2 --env alpine:key=val test task2 alpine:latest +@test "task create --env alpine:key=val --copies 3 test task2 alpine:latest" { + l0 task create --env alpine:key=val --copies 3 test task2 alpine:latest } @test "task list" { diff --git a/tests/stress/Makefile b/tests/stress/Makefile index e785720f3..e395e4a33 100644 --- a/tests/stress/Makefile +++ b/tests/stress/Makefile @@ -1,4 +1,7 @@ test: go test -v -parallel 10 -timeout 1h -.PHONY: test +benchmark: + go test -v -run NOTHING -bench . -timeout 2h + +.PHONY: test benchmark diff --git a/tests/stress/cases/task_stress/main.tf b/tests/stress/cases/task_stress/main.tf deleted file mode 100644 index f8e468131..000000000 --- a/tests/stress/cases/task_stress/main.tf +++ /dev/null @@ -1,15 +0,0 @@ -provider "layer0" { - endpoint = "${var.endpoint}" - token = "${var.token}" - skip_ssl_verify = true -} - -resource "layer0_environment" "tp" { - name = "tp" - size = "t2.micro" -} - -resource "layer0_deploy" "alpine" { - name = "alpine" - content = "${file("Dockerrun.aws.json")}" -} diff --git a/tests/stress/cases/task_stress/outputs.tf b/tests/stress/cases/task_stress/outputs.tf deleted file mode 100644 index 6654b3c4a..000000000 --- a/tests/stress/cases/task_stress/outputs.tf +++ /dev/null @@ -1,7 +0,0 @@ -output "environment_id" { - value = "${layer0_environment.tp.id}" -} - -output "deploy_id" { - value = "${layer0_deploy.alpine.id}" -} diff --git a/tests/stress/cases/task_stress/variables.tf b/tests/stress/cases/task_stress/variables.tf deleted file mode 100644 index 43d24577f..000000000 --- a/tests/stress/cases/task_stress/variables.tf +++ /dev/null @@ -1,3 +0,0 @@ -variable "endpoint" {} - -variable "token" {} diff --git a/tests/stress/main_test.go b/tests/stress/main_test.go index cc20720c5..ec91191a7 100644 --- a/tests/stress/main_test.go +++ b/tests/stress/main_test.go @@ -33,10 +33,10 @@ func setup() { log.Level = logrus.DebugLevel } - logutils.SetGlobalLogger(log) + logutils.SetGlobalLogger(log.Logger) if !*dry { - if err := filepath.Walk("cases", deleteStateFiles); err != nil { + if err := filepath.Walk("module", deleteStateFiles); err != nil { fmt.Println("Error occurred during setup: ", err) os.Exit(1) } @@ -45,7 +45,10 @@ func setup() { func teardown() { if !*dry { - if err := filepath.Walk("cases", deleteStateFiles); err != nil { + if err := filepath.Walk("module", deleteStateFiles); err != nil { + fmt.Println("Error occurred during teardown: ", err) + os.Exit(1) + } fmt.Println("Error occurred during teardown: ", err) os.Exit(1) } diff --git a/tests/stress/cases/task_stress/Dockerrun.aws.json b/tests/stress/module/Dockerrun.aws.json similarity index 56% rename from tests/stress/cases/task_stress/Dockerrun.aws.json rename to tests/stress/module/Dockerrun.aws.json index 420b87346..0a8284fdc 100644 --- a/tests/stress/cases/task_stress/Dockerrun.aws.json +++ b/tests/stress/module/Dockerrun.aws.json @@ -5,15 +5,9 @@ "name": "alpine", "image": "alpine", "entrypoint": [ "/bin/sh", "-c" ], - "command": ["$COMMAND"], "essential": true, "memory": 100, - "environment": [ - { - "name": "COMMAND", - "value": "sleep 10" - } - ] + "command": [ "while true ; do echo LONG RUNNING SERVICE ; sleep 5 ; done" ] } ] } diff --git a/tests/stress/module/main.tf b/tests/stress/module/main.tf new file mode 100644 index 000000000..b5eda9e4b --- /dev/null +++ b/tests/stress/module/main.tf @@ -0,0 +1,57 @@ +provider "layer0" { + endpoint = "${var.endpoint}" + token = "${var.token}" + skip_ssl_verify = true +} + +resource "random_pet" "environment_names" { + length = 1 + count = "${var.num_environments}" +} + +resource "layer0_environment" "te" { + name = "${element(random_pet.environment_names.*.id, count.index)}" + size = "t2.micro" + count = "${var.num_environments}" +} + +resource "random_pet" "load_balancer_names" { + length = 1 + count = "${var.num_load_balancers}" +} + +resource "layer0_load_balancer" "tlb" { + name = "${element(random_pet.load_balancer_names.*.id, count.index)}" + environment = "${element(layer0_environment.te.*.id, count.index)}" + count = "${var.num_load_balancers}" + + port { + host_port = 80 + container_port = 80 + protocol = "http" + } +} + +resource "random_pet" "deploy_families" { + length = 1 + count = "${var.num_deploy_families == 0 ? 1 : var.num_deploy_families}" +} + +resource "layer0_deploy" "td" { + name = "${element(random_pet.deploy_families.*.id, count.index)}" + content = "${file("${path.module}/Dockerrun.aws.json")}" + count = "${var.num_deploys}" +} + +resource "random_pet" "service_names" { + length = 1 + count = "${var.num_services}" +} + +resource "layer0_service" "ts" { + name = "${element(random_pet.service_names.*.id, count.index)}" + environment = "${element(layer0_environment.te.*.id, count.index)}" + deploy = "${element(layer0_deploy.td.*.id, count.index)}" + scale = 1 + count = "${var.num_services}" +} diff --git a/tests/stress/module/outputs.tf b/tests/stress/module/outputs.tf new file mode 100644 index 000000000..540396013 --- /dev/null +++ b/tests/stress/module/outputs.tf @@ -0,0 +1,15 @@ +output "environment_ids" { + value = ["${layer0_environment.te.*.id}"] +} + +output "load_balancer_ids" { + value = ["${layer0_load_balancer.tlb.*.id}"] +} + +output "deploy_ids" { + value = ["${layer0_deploy.td.*.id}"] +} + +output "service_ids" { + value = ["${layer0_service.ts.*.id}"] +} diff --git a/tests/stress/module/variables.tf b/tests/stress/module/variables.tf new file mode 100644 index 000000000..f59d95d78 --- /dev/null +++ b/tests/stress/module/variables.tf @@ -0,0 +1,8 @@ +variable "endpoint" {} +variable "token" {} + +variable "num_deploys" {} +variable "num_deploy_families" {} +variable "num_environments" {} +variable "num_load_balancers" {} +variable "num_services" {} diff --git a/tests/stress/stress_test.go b/tests/stress/stress_test.go index d82dbfcad..4dc34f696 100644 --- a/tests/stress/stress_test.go +++ b/tests/stress/stress_test.go @@ -1,6 +1,9 @@ package system import ( + "fmt" + "strconv" + "strings" "testing" "github.com/quintilesims/layer0/common/config" @@ -8,32 +11,246 @@ import ( "github.com/quintilesims/tftest" ) -type StressTest struct { - Terraform *tftest.TestContext - Layer0 *clients.Layer0TestClient +const ( + DEPLOY_SCALE_MIN = 1 + DEPLOY_SCALE_MED = 50 + DEPLOY_SCALE_MAX = 100 + DEPLOY_FAMILY_SCALE_MIN = 1 + DEPLOY_FAMILY_SCALE_MED = 15 + DEPLOY_FAMILY_SCALE_MAX = 30 + ENVIRONMENT_SCALE_MIN = 1 + ENVIRONMENT_SCALE_MED = 15 + ENVIRONMENT_SCALE_MAX = 30 + LOAD_BALANCER_SCALE_MIN = 1 + LOAD_BALANCER_SCALE_MED = 25 + LOAD_BALANCER_SCALE_MAX = 50 + SERVICE_SCALE_MIN = 1 + SERVICE_SCALE_MED = 25 + SERVICE_SCALE_MAX = 50 + TASK_SCALE_MIN = 1 + TASK_SCALE_MED = 50 + TASK_SCALE_MAX = 100 +) + +type StressTestCase struct { + NumDeploys int + NumDeployFamilies int + NumEnvironments int + NumLoadBalancers int + NumServices int + NumTasks int } -func NewStressTest(t *testing.T, dir string, vars map[string]string) *StressTest { - if vars == nil { - vars = map[string]string{} +func runTest(b *testing.B, c StressTestCase) { + if c.NumTasks > 0 || c.NumServices > 0 { + if c.NumEnvironments == 0 { + c.NumEnvironments = ENVIRONMENT_SCALE_MIN + } + + if c.NumDeploys == 0 { + c.NumDeploys = DEPLOY_SCALE_MIN + } + } + + if c.NumLoadBalancers > 0 && c.NumEnvironments == 0 { + c.NumEnvironments = ENVIRONMENT_SCALE_MIN } - vars["endpoint"] = config.APIEndpoint() - vars["token"] = config.AuthToken() + vars := map[string]string{ + "endpoint": config.APIEndpoint(), + "token": config.AuthToken(), + "num_deploys": strconv.Itoa(c.NumDeploys), + "num_deploy_families": strconv.Itoa(c.NumDeployFamilies), + "num_environments": strconv.Itoa(c.NumEnvironments), + "num_load_balancers": strconv.Itoa(c.NumLoadBalancers), + "num_services": strconv.Itoa(c.NumServices), + } - tfContext := tftest.NewTestContext(t, - tftest.Dir(dir), + terraform := tftest.NewTestContext( + b, + tftest.Dir("module"), tftest.Vars(vars), tftest.DryRun(*dry), - tftest.Log(log)) + tftest.Log(b), + ) - layer0 := clients.NewLayer0TestClient(t, vars["endpoint"], vars["token"]) + layer0 := clients.NewLayer0TestClient(b, vars["endpoint"], vars["token"]) - // download modules using terraform get - tfContext.Terraformf("get") + terraform.Apply() + defer terraform.Destroy() - return &StressTest{ - Terraform: tfContext, - Layer0: layer0, + methodsToBenchmark := map[string]func(){} + + if c.NumDeploys > 0 { + deployIDs := strings.Split(terraform.Output("deploy_ids"), ",\n") + methodsToBenchmark["GetDeploy"] = func() { layer0.GetDeploy(deployIDs[0]) } + methodsToBenchmark["ListDeploys"] = func() { layer0.ListDeploys() } } + + if c.NumEnvironments > 0 { + environmentIDs := strings.Split(terraform.Output("environment_ids"), ",\n") + methodsToBenchmark["GetEnvironment"] = func() { layer0.GetEnvironment(environmentIDs[0]) } + methodsToBenchmark["ListEnvironments"] = func() { layer0.ListEnvironments() } + } + + if c.NumLoadBalancers > 0 { + loadBalancerIDs := strings.Split(terraform.Output("load_balancer_ids"), ",\n") + methodsToBenchmark["GetLoadBalancer"] = func() { layer0.GetLoadBalancer(loadBalancerIDs[0]) } + methodsToBenchmark["ListLoadBalancers"] = func() { layer0.ListLoadBalancers() } + } + + if c.NumServices > 0 { + serviceIDs := strings.Split(terraform.Output("service_ids"), ",\n") + methodsToBenchmark["GetService"] = func() { layer0.GetService(serviceIDs[0]) } + methodsToBenchmark["ListServices"] = func() { layer0.ListServices() } + } + + if c.NumTasks > 0 { + methodsToBenchmark["ListTasks"] = func() { layer0.ListTasks() } + + deployIDs := strings.Split(terraform.Output("deploy_ids"), ",\n") + environmentIDs := strings.Split(terraform.Output("environment_ids"), ",\n") + + for i := 0; i < c.NumTasks; i++ { + environmentID := environmentIDs[i%len(environmentIDs)] + deployID := deployIDs[i%len(deployIDs)] + taskName := fmt.Sprintf("tt%v", i) + layer0.CreateTask(taskName, environmentID, deployID, nil) + } + } + + benchmark(b, methodsToBenchmark) +} + +func benchmark(b *testing.B, methods map[string]func()) { + for name, fn := range methods { + b.Run(name, func(b *testing.B) { + for n := 0; n < b.N; n++ { + fn() + } + }) + } +} + +func BenchmarkMinFamiliesMinDeploys(b *testing.B) { + runTest(b, StressTestCase{ + NumDeployFamilies: DEPLOY_FAMILY_SCALE_MIN, + NumDeploys: DEPLOY_SCALE_MIN, + }) +} + +func BenchmarkMedFamiliesMedDeploys(b *testing.B) { + runTest(b, StressTestCase{ + NumDeployFamilies: DEPLOY_FAMILY_SCALE_MED, + NumDeploys: DEPLOY_SCALE_MED, + }) +} + +func BenchmarkMaxFamiliesMaxDeploys(b *testing.B) { + runTest(b, StressTestCase{ + NumDeployFamilies: DEPLOY_FAMILY_SCALE_MAX, + NumDeploys: DEPLOY_SCALE_MAX, + }) +} + +func BenchmarkMinEnvironments(b *testing.B) { + runTest(b, StressTestCase{ + NumEnvironments: ENVIRONMENT_SCALE_MIN, + }) +} + +func BenchmarkMedEnvironments(b *testing.B) { + runTest(b, StressTestCase{ + NumEnvironments: ENVIRONMENT_SCALE_MED, + }) +} + +func BenchmarkMaxEnvironments(b *testing.B) { + runTest(b, StressTestCase{ + NumEnvironments: ENVIRONMENT_SCALE_MAX, + }) +} + +func BenchmarkMinServices(b *testing.B) { + runTest(b, StressTestCase{ + NumServices: SERVICE_SCALE_MIN, + }) +} + +func BenchmarkMedServices(b *testing.B) { + runTest(b, StressTestCase{ + NumServices: SERVICE_SCALE_MED, + }) +} + +func BenchmarkMaxServices(b *testing.B) { + runTest(b, StressTestCase{ + NumServices: SERVICE_SCALE_MAX, + }) +} + +func BenchmarkMinLoadBalancers(b *testing.B) { + runTest(b, StressTestCase{ + NumLoadBalancers: LOAD_BALANCER_SCALE_MIN, + }) +} + +func BenchmarkMedLoadBalancers(b *testing.B) { + runTest(b, StressTestCase{ + NumLoadBalancers: LOAD_BALANCER_SCALE_MED, + }) +} + +func BenchmarkMaxLoadBalancers(b *testing.B) { + runTest(b, StressTestCase{ + NumLoadBalancers: LOAD_BALANCER_SCALE_MAX, + }) +} + +func BenchmarkMinTasks(b *testing.B) { + runTest(b, StressTestCase{ + NumTasks: TASK_SCALE_MIN, + }) +} + +func BenchmarkMedTasks(b *testing.B) { + runTest(b, StressTestCase{ + NumTasks: TASK_SCALE_MED, + }) +} + +func BenchmarkMaxTasks(b *testing.B) { + runTest(b, StressTestCase{ + NumTasks: TASK_SCALE_MAX, + }) +} + +func BenchmarkAggregateMin(b *testing.B) { + runTest(b, StressTestCase{ + NumDeploys: DEPLOY_SCALE_MIN, + NumDeployFamilies: DEPLOY_FAMILY_SCALE_MIN, + NumEnvironments: ENVIRONMENT_SCALE_MIN, + NumLoadBalancers: LOAD_BALANCER_SCALE_MIN, + NumServices: SERVICE_SCALE_MIN, + }) +} + +func BenchmarkAggregateMed(b *testing.B) { + runTest(b, StressTestCase{ + NumDeploys: DEPLOY_SCALE_MED, + NumDeployFamilies: DEPLOY_FAMILY_SCALE_MED, + NumEnvironments: ENVIRONMENT_SCALE_MED, + NumLoadBalancers: LOAD_BALANCER_SCALE_MED, + NumServices: SERVICE_SCALE_MED, + }) +} + +func BenchmarkAggregateMax(b *testing.B) { + runTest(b, StressTestCase{ + NumDeploys: DEPLOY_SCALE_MAX, + NumDeployFamilies: DEPLOY_FAMILY_SCALE_MAX, + NumEnvironments: ENVIRONMENT_SCALE_MAX, + NumLoadBalancers: LOAD_BALANCER_SCALE_MAX, + NumServices: SERVICE_SCALE_MAX, + }) } diff --git a/tests/stress/taskStress_test.go b/tests/stress/taskStress_test.go deleted file mode 100644 index 34b301ea7..000000000 --- a/tests/stress/taskStress_test.go +++ /dev/null @@ -1,73 +0,0 @@ -package system - -import ( - "testing" - "time" - - "github.com/quintilesims/layer0/common/testutils" -) - -// Test Resources: -// This test creates an environment named 'tp' -// and a deploy named 'alpine' -func TestTaskStress(t *testing.T) { - t.Parallel() - - s := NewStressTest(t, "cases/task_stress", nil) - s.Terraform.Apply() - defer s.Terraform.Destroy() - - environmentID := s.Terraform.Output("environment_id") - deployID := s.Terraform.Output("deploy_id") - - // create 100 tasks - taskNameCopies := map[string]int{ - "TaskA": 50, - "TaskB": 25, - "TaskC": 10, - "TaskD": 5, - "TaskE": 5, - "TaskF": 1, - "TaskG": 1, - "TaskH": 1, - "TaskI": 1, - "TaskJ": 1, - } - - for taskName, copies := range taskNameCopies { - go func(taskName string, copies int) { - log.Debugf("Creating task %s (copies: %d)", taskName, copies) - s.Layer0.CreateTask(taskName, environmentID, deployID, copies, nil) - }(taskName, copies) - } - - testutils.WaitFor(t, time.Second*30, time.Minute*10, func() bool { - log.Debugf("Waiting for all tasks to run") - - var numTasks int - for _, taskSummary := range s.Layer0.ListTasks() { - if taskSummary.EnvironmentID == environmentID { - numTasks++ - } - } - - log.Debugf("%d/100 tasks have ran", numTasks) - return numTasks >= 100 - }) - - // each task sleeps for 10 seconds - // wait for all of them to complete - time.Sleep(time.Second * 10) - - log.Debugf("Checking task exit codes") - for _, taskSummary := range s.Layer0.ListTasks() { - if taskSummary.EnvironmentID == environmentID { - task := s.Layer0.GetTask(taskSummary.TaskID) - detail := task.Copies[0].Details[0] - - if detail.ExitCode != 0 { - t.Fatalf("Task %s has unexpected exit code: %#v", task.TaskID, detail) - } - } - } -} diff --git a/tests/system/main_test.go b/tests/system/main_test.go index cc20720c5..203c94eba 100644 --- a/tests/system/main_test.go +++ b/tests/system/main_test.go @@ -33,7 +33,7 @@ func setup() { log.Level = logrus.DebugLevel } - logutils.SetGlobalLogger(log) + logutils.SetGlobalLogger(log.Logger) if !*dry { if err := filepath.Walk("cases", deleteStateFiles); err != nil { diff --git a/tests/system/system_test.go b/tests/system/system_test.go index e8a52c981..464aea62b 100644 --- a/tests/system/system_test.go +++ b/tests/system/system_test.go @@ -30,8 +30,14 @@ func NewSystemTest(t *testing.T, dir string, vars map[string]string) *SystemTest layer0 := clients.NewLayer0TestClient(t, vars["endpoint"], vars["token"]) // download modules using terraform get - tfContext.Terraformf("get") + if _, err := tfContext.Terraformf("init"); err != nil { + t.Fatal(err) + } + if _, err := tfContext.Terraformf("get"); err != nil { + t.Fatal(err) + } + return &SystemTest{ Terraform: tfContext, Layer0: layer0, diff --git a/vendor/github.com/golang/mock/gomock/call.go b/vendor/github.com/golang/mock/gomock/call.go index ea1e09227..8ed74a627 100644 --- a/vendor/github.com/golang/mock/gomock/call.go +++ b/vendor/github.com/golang/mock/gomock/call.go @@ -17,6 +17,7 @@ package gomock import ( "fmt" "reflect" + "strconv" "strings" ) @@ -24,10 +25,11 @@ import ( type Call struct { t TestReporter // for triggering test failures on invalid call setup - receiver interface{} // the receiver of the method call - method string // the name of the method - args []Matcher // the args - rets []interface{} // the return values (if any) + receiver interface{} // the receiver of the method call + method string // the name of the method + methodType reflect.Type // the type of the method + args []Matcher // the args + origin string // file and line number of call setup preReqs []*Call // prerequisite calls @@ -36,29 +38,135 @@ type Call struct { numCalls int // actual number made - // Actions - doFunc reflect.Value - setArgs map[int]reflect.Value + // actions are called when this Call is called. Each action gets the args and + // can set the return values by returning a non-nil slice. Actions run in the + // order they are created. + actions []func([]interface{}) []interface{} } +// newCall creates a *Call. It requires the method type in order to support +// unexported methods. +func newCall(t TestReporter, receiver interface{}, method string, methodType reflect.Type, args ...interface{}) *Call { + if h, ok := t.(testHelper); ok { + h.Helper() + } + + // TODO: check arity, types. + margs := make([]Matcher, len(args)) + for i, arg := range args { + if m, ok := arg.(Matcher); ok { + margs[i] = m + } else if arg == nil { + // Handle nil specially so that passing a nil interface value + // will match the typed nils of concrete args. + margs[i] = Nil() + } else { + margs[i] = Eq(arg) + } + } + + origin := callerInfo(3) + actions := []func([]interface{}) []interface{}{func([]interface{}) []interface{} { + // Synthesize the zero value for each of the return args' types. + rets := make([]interface{}, methodType.NumOut()) + for i := 0; i < methodType.NumOut(); i++ { + rets[i] = reflect.Zero(methodType.Out(i)).Interface() + } + return rets + }} + return &Call{t: t, receiver: receiver, method: method, methodType: methodType, + args: margs, origin: origin, minCalls: 1, maxCalls: 1, actions: actions} +} + +// AnyTimes allows the expectation to be called 0 or more times func (c *Call) AnyTimes() *Call { c.minCalls, c.maxCalls = 0, 1e8 // close enough to infinity return c } -// Do declares the action to run when the call is matched. +// MinTimes requires the call to occur at least n times. If AnyTimes or MaxTimes have not been called, MinTimes also +// sets the maximum number of calls to infinity. +func (c *Call) MinTimes(n int) *Call { + c.minCalls = n + if c.maxCalls == 1 { + c.maxCalls = 1e8 + } + return c +} + +// MaxTimes limits the number of calls to n times. If AnyTimes or MinTimes have not been called, MaxTimes also +// sets the minimum number of calls to 0. +func (c *Call) MaxTimes(n int) *Call { + c.maxCalls = n + if c.minCalls == 1 { + c.minCalls = 0 + } + return c +} + +// DoAndReturn declares the action to run when the call is matched. +// The return values from this function are returned by the mocked function. +// It takes an interface{} argument to support n-arity functions. +func (c *Call) DoAndReturn(f interface{}) *Call { + // TODO: Check arity and types here, rather than dying badly elsewhere. + v := reflect.ValueOf(f) + + c.addAction(func(args []interface{}) []interface{} { + vargs := make([]reflect.Value, len(args)) + ft := v.Type() + for i := 0; i < len(args); i++ { + if args[i] != nil { + vargs[i] = reflect.ValueOf(args[i]) + } else { + // Use the zero value for the arg. + vargs[i] = reflect.Zero(ft.In(i)) + } + } + vrets := v.Call(vargs) + rets := make([]interface{}, len(vrets)) + for i, ret := range vrets { + rets[i] = ret.Interface() + } + return rets + }) + return c +} + +// Do declares the action to run when the call is matched. The function's +// return values are ignored to retain backward compatibility. To use the +// return values call DoAndReturn. // It takes an interface{} argument to support n-arity functions. func (c *Call) Do(f interface{}) *Call { // TODO: Check arity and types here, rather than dying badly elsewhere. - c.doFunc = reflect.ValueOf(f) + v := reflect.ValueOf(f) + + c.addAction(func(args []interface{}) []interface{} { + vargs := make([]reflect.Value, len(args)) + ft := v.Type() + for i := 0; i < len(args); i++ { + if args[i] != nil { + vargs[i] = reflect.ValueOf(args[i]) + } else { + // Use the zero value for the arg. + vargs[i] = reflect.Zero(ft.In(i)) + } + } + v.Call(vargs) + return nil + }) return c } +// Return declares the values to be returned by the mocked function call. func (c *Call) Return(rets ...interface{}) *Call { - mt := c.methodType() + if h, ok := c.t.(testHelper); ok { + h.Helper() + } + + mt := c.methodType if len(rets) != mt.NumOut() { - c.t.Fatalf("wrong number of arguments to Return for %T.%v: got %d, want %d", - c.receiver, c.method, len(rets), mt.NumOut()) + c.t.Fatalf("wrong number of arguments to Return for %T.%v: got %d, want %d [%s]", + c.receiver, c.method, len(rets), mt.NumOut(), c.origin) } for i, ret := range rets { if got, want := reflect.TypeOf(ret), mt.Out(i); got == want { @@ -69,8 +177,8 @@ func (c *Call) Return(rets ...interface{}) *Call { case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice: // ok default: - c.t.Fatalf("argument %d to Return for %T.%v is nil, but %v is not nillable", - i, c.receiver, c.method, want) + c.t.Fatalf("argument %d to Return for %T.%v is nil, but %v is not nillable [%s]", + i, c.receiver, c.method, want, c.origin) } } else if got.AssignableTo(want) { // Assignable type relation. Make the assignment now so that the generated code @@ -79,31 +187,38 @@ func (c *Call) Return(rets ...interface{}) *Call { v.Set(reflect.ValueOf(ret)) rets[i] = v.Interface() } else { - c.t.Fatalf("wrong type of argument %d to Return for %T.%v: %v is not assignable to %v", - i, c.receiver, c.method, got, want) + c.t.Fatalf("wrong type of argument %d to Return for %T.%v: %v is not assignable to %v [%s]", + i, c.receiver, c.method, got, want, c.origin) } } - c.rets = rets + c.addAction(func([]interface{}) []interface{} { + return rets + }) + return c } +// Times declares the exact number of times a function call is expected to be executed. func (c *Call) Times(n int) *Call { c.minCalls, c.maxCalls = n, n return c } // SetArg declares an action that will set the nth argument's value, -// indirected through a pointer. +// indirected through a pointer. Or, in the case of a slice, SetArg +// will copy value's elements into the nth argument. func (c *Call) SetArg(n int, value interface{}) *Call { - if c.setArgs == nil { - c.setArgs = make(map[int]reflect.Value) + if h, ok := c.t.(testHelper); ok { + h.Helper() } - mt := c.methodType() + + mt := c.methodType // TODO: This will break on variadic methods. // We will need to check those at invocation time. if n < 0 || n >= mt.NumIn() { - c.t.Fatalf("SetArg(%d, ...) called for a method with %d args", n, mt.NumIn()) + c.t.Fatalf("SetArg(%d, ...) called for a method with %d args [%s]", + n, mt.NumIn(), c.origin) } // Permit setting argument through an interface. // In the interface case, we don't (nay, can't) check the type here. @@ -112,14 +227,28 @@ func (c *Call) SetArg(n int, value interface{}) *Call { case reflect.Ptr: dt := at.Elem() if vt := reflect.TypeOf(value); !vt.AssignableTo(dt) { - c.t.Fatalf("SetArg(%d, ...) argument is a %v, not assignable to %v", n, vt, dt) + c.t.Fatalf("SetArg(%d, ...) argument is a %v, not assignable to %v [%s]", + n, vt, dt, c.origin) } case reflect.Interface: // nothing to do + case reflect.Slice: + // nothing to do default: - c.t.Fatalf("SetArg(%d, ...) referring to argument of non-pointer non-interface type %v", n, at) + c.t.Fatalf("SetArg(%d, ...) referring to argument of non-pointer non-interface non-slice type %v [%s]", + n, at, c.origin) } - c.setArgs[n] = reflect.ValueOf(value) + + c.addAction(func(args []interface{}) []interface{} { + v := reflect.ValueOf(value) + switch reflect.TypeOf(args[n]).Kind() { + case reflect.Slice: + setSlice(args[n], v) + default: + reflect.ValueOf(args[n]).Elem().Set(v) + } + return nil + }) return c } @@ -135,19 +264,22 @@ func (c *Call) isPreReq(other *Call) bool { // After declares that the call may only match after preReq has been exhausted. func (c *Call) After(preReq *Call) *Call { + if h, ok := c.t.(testHelper); ok { + h.Helper() + } + + if c == preReq { + c.t.Fatalf("A call isn't allowed to be its own prerequisite") + } if preReq.isPreReq(c) { - msg := fmt.Sprintf( - "Loop in call order: %v is a prerequisite to %v (possibly indirectly).", - c, preReq, - ) - panic(msg) + c.t.Fatalf("Loop in call order: %v is a prerequisite to %v (possibly indirectly).", c, preReq) } c.preReqs = append(c.preReqs, preReq) return c } -// Returns true iff the minimum number of calls have been made. +// Returns true if the minimum number of calls have been made. func (c *Call) satisfied() bool { return c.numCalls >= c.minCalls } @@ -163,31 +295,108 @@ func (c *Call) String() string { args[i] = arg.String() } arguments := strings.Join(args, ", ") - return fmt.Sprintf("%T.%v(%s)", c.receiver, c.method, arguments) + return fmt.Sprintf("%T.%v(%s) %s", c.receiver, c.method, arguments, c.origin) } // Tests if the given call matches the expected call. -func (c *Call) matches(args []interface{}) bool { - if len(args) != len(c.args) { - return false - } - for i, m := range c.args { - if !m.Matches(args[i]) { - return false +// If yes, returns nil. If no, returns error with message explaining why it does not match. +func (c *Call) matches(args []interface{}) error { + if !c.methodType.IsVariadic() { + if len(args) != len(c.args) { + return fmt.Errorf("Expected call at %s has the wrong number of arguments. Got: %d, want: %d", + c.origin, len(args), len(c.args)) + } + + for i, m := range c.args { + if !m.Matches(args[i]) { + return fmt.Errorf("Expected call at %s doesn't match the argument at index %s.\nGot: %v\nWant: %v", + c.origin, strconv.Itoa(i), args[i], m) + } + } + } else { + if len(c.args) < c.methodType.NumIn()-1 { + return fmt.Errorf("Expected call at %s has the wrong number of matchers. Got: %d, want: %d", + c.origin, len(c.args), c.methodType.NumIn()-1) + } + if len(c.args) != c.methodType.NumIn() && len(args) != len(c.args) { + return fmt.Errorf("Expected call at %s has the wrong number of arguments. Got: %d, want: %d", + c.origin, len(args), len(c.args)) + } + if len(args) < len(c.args)-1 { + return fmt.Errorf("Expected call at %s has the wrong number of arguments. Got: %d, want: greater than or equal to %d", + c.origin, len(args), len(c.args)-1) + } + + for i, m := range c.args { + if i < c.methodType.NumIn()-1 { + // Non-variadic args + if !m.Matches(args[i]) { + return fmt.Errorf("Expected call at %s doesn't match the argument at index %s.\nGot: %v\nWant: %v", + c.origin, strconv.Itoa(i), args[i], m) + } + continue + } + // The last arg has a possibility of a variadic argument, so let it branch + + // sample: Foo(a int, b int, c ...int) + if len(c.args) == len(args) { + if m.Matches(args[i]) { + // Got Foo(a, b, c) want Foo(matcherA, matcherB, gomock.Any()) + // Got Foo(a, b, c) want Foo(matcherA, matcherB, someSliceMatcher) + // Got Foo(a, b, c) want Foo(matcherA, matcherB, matcherC) + // Got Foo(a, b) want Foo(matcherA, matcherB) + // Got Foo(a, b, c, d) want Foo(matcherA, matcherB, matcherC, matcherD) + break + } + } + + // The number of actual args don't match the number of matchers, + // or the last matcher is a slice and the last arg is not. + // If this function still matches it is because the last matcher + // matches all the remaining arguments or the lack of any. + // Convert the remaining arguments, if any, into a slice of the + // expected type. + vargsType := c.methodType.In(c.methodType.NumIn() - 1) + vargs := reflect.MakeSlice(vargsType, 0, len(args)-i) + for _, arg := range args[i:] { + vargs = reflect.Append(vargs, reflect.ValueOf(arg)) + } + if m.Matches(vargs.Interface()) { + // Got Foo(a, b, c, d, e) want Foo(matcherA, matcherB, gomock.Any()) + // Got Foo(a, b, c, d, e) want Foo(matcherA, matcherB, someSliceMatcher) + // Got Foo(a, b) want Foo(matcherA, matcherB, gomock.Any()) + // Got Foo(a, b) want Foo(matcherA, matcherB, someEmptySliceMatcher) + break + } + // Wrong number of matchers or not match. Fail. + // Got Foo(a, b) want Foo(matcherA, matcherB, matcherC, matcherD) + // Got Foo(a, b, c) want Foo(matcherA, matcherB, matcherC, matcherD) + // Got Foo(a, b, c, d) want Foo(matcherA, matcherB, matcherC, matcherD, matcherE) + // Got Foo(a, b, c, d, e) want Foo(matcherA, matcherB, matcherC, matcherD) + // Got Foo(a, b, c) want Foo(matcherA, matcherB) + return fmt.Errorf("Expected call at %s doesn't match the argument at index %s.\nGot: %v\nWant: %v", + c.origin, strconv.Itoa(i), args[i:], c.args[i]) + } } // Check that all prerequisite calls have been satisfied. for _, preReqCall := range c.preReqs { if !preReqCall.satisfied() { - return false + return fmt.Errorf("Expected call at %s doesn't have a prerequisite call satisfied:\n%v\nshould be called before:\n%v", + c.origin, preReqCall, c) } } - return true + // Check that the call is not exhausted. + if c.exhausted() { + return fmt.Errorf("Expected call at %s has already been called the max number of times.", c.origin) + } + + return nil } -// dropPrereqs tells the expected Call to not re-check prerequite calls any +// dropPrereqs tells the expected Call to not re-check prerequisite calls any // longer, and to return its current set. func (c *Call) dropPrereqs() (preReqs []*Call) { preReqs = c.preReqs @@ -195,48 +404,9 @@ func (c *Call) dropPrereqs() (preReqs []*Call) { return } -func (c *Call) call(args []interface{}) (rets []interface{}, action func()) { +func (c *Call) call(args []interface{}) []func([]interface{}) []interface{} { c.numCalls++ - - // Actions - if c.doFunc.IsValid() { - doArgs := make([]reflect.Value, len(args)) - ft := c.doFunc.Type() - for i := 0; i < ft.NumIn(); i++ { - if args[i] != nil { - doArgs[i] = reflect.ValueOf(args[i]) - } else { - // Use the zero value for the arg. - doArgs[i] = reflect.Zero(ft.In(i)) - } - } - action = func() { c.doFunc.Call(doArgs) } - } - for n, v := range c.setArgs { - reflect.ValueOf(args[n]).Elem().Set(v) - } - - rets = c.rets - if rets == nil { - // Synthesize the zero value for each of the return args' types. - mt := c.methodType() - rets = make([]interface{}, mt.NumOut()) - for i := 0; i < mt.NumOut(); i++ { - rets[i] = reflect.Zero(mt.Out(i)).Interface() - } - } - - return -} - -func (c *Call) methodType() reflect.Type { - recv := reflect.ValueOf(c.receiver) - for i := 0; i < recv.Type().NumMethod(); i++ { - if recv.Type().Method(i).Name == c.method { - return recv.Method(i).Type() - } - } - panic(fmt.Sprintf("gomock: failed finding method %s on %T", c.method, c.receiver)) + return c.actions } // InOrder declares that the given calls should occur in order. @@ -245,3 +415,14 @@ func InOrder(calls ...*Call) { calls[i].After(calls[i-1]) } } + +func setSlice(arg interface{}, v reflect.Value) { + va := reflect.ValueOf(arg) + for i := 0; i < v.Len(); i++ { + va.Index(i).Set(v.Index(i)) + } +} + +func (c *Call) addAction(action func([]interface{}) []interface{}) { + c.actions = append(c.actions, action) +} diff --git a/vendor/github.com/golang/mock/gomock/callset.go b/vendor/github.com/golang/mock/gomock/callset.go index 1b7de4c0b..c44a8a585 100644 --- a/vendor/github.com/golang/mock/gomock/callset.go +++ b/vendor/github.com/golang/mock/gomock/callset.go @@ -14,63 +14,95 @@ package gomock +import ( + "bytes" + "fmt" +) + // callSet represents a set of expected calls, indexed by receiver and method // name. -type callSet map[interface{}]map[string][]*Call +type callSet struct { + // Calls that are still expected. + expected map[callSetKey][]*Call + // Calls that have been exhausted. + exhausted map[callSetKey][]*Call +} + +// callSetKey is the key in the maps in callSet +type callSetKey struct { + receiver interface{} + fname string +} + +func newCallSet() *callSet { + return &callSet{make(map[callSetKey][]*Call), make(map[callSetKey][]*Call)} +} // Add adds a new expected call. func (cs callSet) Add(call *Call) { - methodMap, ok := cs[call.receiver] - if !ok { - methodMap = make(map[string][]*Call) - cs[call.receiver] = methodMap + key := callSetKey{call.receiver, call.method} + m := cs.expected + if call.exhausted() { + m = cs.exhausted } - methodMap[call.method] = append(methodMap[call.method], call) + m[key] = append(m[key], call) } // Remove removes an expected call. func (cs callSet) Remove(call *Call) { - methodMap, ok := cs[call.receiver] - if !ok { - return - } - sl := methodMap[call.method] - for i, c := range sl { + key := callSetKey{call.receiver, call.method} + calls := cs.expected[key] + for i, c := range calls { if c == call { - // quick removal; we don't need to maintain call order - if len(sl) > 1 { - sl[i] = sl[len(sl)-1] - } - methodMap[call.method] = sl[:len(sl)-1] + // maintain order for remaining calls + cs.expected[key] = append(calls[:i], calls[i+1:]...) + cs.exhausted[key] = append(cs.exhausted[key], call) break } } } -// FindMatch searches for a matching call. Returns nil if no call matched. -func (cs callSet) FindMatch(receiver interface{}, method string, args []interface{}) *Call { - methodMap, ok := cs[receiver] - if !ok { - return nil - } - calls, ok := methodMap[method] - if !ok { - return nil - } +// FindMatch searches for a matching call. Returns error with explanation message if no call matched. +func (cs callSet) FindMatch(receiver interface{}, method string, args []interface{}) (*Call, error) { + key := callSetKey{receiver, method} - // Search through the unordered set of calls expected on a method on a - // receiver. - for _, call := range calls { - // A call should not normally still be here if exhausted, - // but it can happen if, for instance, .Times(0) was used. - // Pretend the call doesn't match. - if call.exhausted() { - continue + // Search through the expected calls. + expected := cs.expected[key] + var callsErrors bytes.Buffer + for _, call := range expected { + err := call.matches(args) + if err != nil { + fmt.Fprintf(&callsErrors, "\n%v", err) + } else { + return call, nil } - if call.matches(args) { - return call + } + + // If we haven't found a match then search through the exhausted calls so we + // get useful error messages. + exhausted := cs.exhausted[key] + for _, call := range exhausted { + if err := call.matches(args); err != nil { + fmt.Fprintf(&callsErrors, "\n%v", err) } } - return nil + if len(expected)+len(exhausted) == 0 { + fmt.Fprintf(&callsErrors, "there are no expected calls of the method %q for that receiver", method) + } + + return nil, fmt.Errorf(callsErrors.String()) +} + +// Failures returns the calls that are not satisfied. +func (cs callSet) Failures() []*Call { + failures := make([]*Call, 0, len(cs.expected)) + for _, calls := range cs.expected { + for _, call := range calls { + if !call.satisfied() { + failures = append(failures, call) + } + } + } + return failures } diff --git a/vendor/github.com/golang/mock/gomock/controller.go b/vendor/github.com/golang/mock/gomock/controller.go index 6ca952803..78fac962f 100644 --- a/vendor/github.com/golang/mock/gomock/controller.go +++ b/vendor/github.com/golang/mock/gomock/controller.go @@ -55,7 +55,14 @@ // - Handle different argument/return types (e.g. ..., chan, map, interface). package gomock -import "sync" +import ( + "fmt" + "reflect" + "runtime" + "sync" + + "golang.org/x/net/context" +) // A TestReporter is something that can be used to report test failures. // It is satisfied by the standard library's *testing.T. @@ -70,79 +77,118 @@ type TestReporter interface { type Controller struct { mu sync.Mutex t TestReporter - expectedCalls callSet + expectedCalls *callSet + finished bool } func NewController(t TestReporter) *Controller { return &Controller{ t: t, - expectedCalls: make(callSet), + expectedCalls: newCallSet(), } } +type cancelReporter struct { + t TestReporter + cancel func() +} + +func (r *cancelReporter) Errorf(format string, args ...interface{}) { r.t.Errorf(format, args...) } +func (r *cancelReporter) Fatalf(format string, args ...interface{}) { + defer r.cancel() + r.t.Fatalf(format, args...) +} + +// WithContext returns a new Controller and a Context, which is cancelled on any +// fatal failure. +func WithContext(ctx context.Context, t TestReporter) (*Controller, context.Context) { + ctx, cancel := context.WithCancel(ctx) + return NewController(&cancelReporter{t, cancel}), ctx +} + func (ctrl *Controller) RecordCall(receiver interface{}, method string, args ...interface{}) *Call { - // TODO: check arity, types. - margs := make([]Matcher, len(args)) - for i, arg := range args { - if m, ok := arg.(Matcher); ok { - margs[i] = m - } else if arg == nil { - // Handle nil specially so that passing a nil interface value - // will match the typed nils of concrete args. - margs[i] = Nil() - } else { - margs[i] = Eq(arg) + if h, ok := ctrl.t.(testHelper); ok { + h.Helper() + } + + recv := reflect.ValueOf(receiver) + for i := 0; i < recv.Type().NumMethod(); i++ { + if recv.Type().Method(i).Name == method { + return ctrl.RecordCallWithMethodType(receiver, method, recv.Method(i).Type(), args...) } } + ctrl.t.Fatalf("gomock: failed finding method %s on %T", method, receiver) + panic("unreachable") +} - ctrl.mu.Lock() - defer ctrl.mu.Unlock() +func (ctrl *Controller) RecordCallWithMethodType(receiver interface{}, method string, methodType reflect.Type, args ...interface{}) *Call { + if h, ok := ctrl.t.(testHelper); ok { + h.Helper() + } - call := &Call{t: ctrl.t, receiver: receiver, method: method, args: margs, minCalls: 1, maxCalls: 1} + call := newCall(ctrl.t, receiver, method, methodType, args...) + ctrl.mu.Lock() + defer ctrl.mu.Unlock() ctrl.expectedCalls.Add(call) + return call } func (ctrl *Controller) Call(receiver interface{}, method string, args ...interface{}) []interface{} { - ctrl.mu.Lock() - defer ctrl.mu.Unlock() - - expected := ctrl.expectedCalls.FindMatch(receiver, method, args) - if expected == nil { - ctrl.t.Fatalf("no matching expected call: %T.%v(%v)", receiver, method, args) + if h, ok := ctrl.t.(testHelper); ok { + h.Helper() } - // Two things happen here: - // * the matching call no longer needs to check prerequite calls, - // * and the prerequite calls are no longer expected, so remove them. - preReqCalls := expected.dropPrereqs() - for _, preReqCall := range preReqCalls { - ctrl.expectedCalls.Remove(preReqCall) - } + // Nest this code so we can use defer to make sure the lock is released. + actions := func() []func([]interface{}) []interface{} { + ctrl.mu.Lock() + defer ctrl.mu.Unlock() - rets, action := expected.call(args) - if expected.exhausted() { - ctrl.expectedCalls.Remove(expected) - } + expected, err := ctrl.expectedCalls.FindMatch(receiver, method, args) + if err != nil { + origin := callerInfo(2) + ctrl.t.Fatalf("Unexpected call to %T.%v(%v) at %s because: %s", receiver, method, args, origin, err) + } + + // Two things happen here: + // * the matching call no longer needs to check prerequite calls, + // * and the prerequite calls are no longer expected, so remove them. + preReqCalls := expected.dropPrereqs() + for _, preReqCall := range preReqCalls { + ctrl.expectedCalls.Remove(preReqCall) + } - // Don't hold the lock while doing the call's action (if any) - // so that actions may execute concurrently. - // We use the deferred Unlock to capture any panics that happen above; - // here we add a deferred Lock to balance it. - ctrl.mu.Unlock() - defer ctrl.mu.Lock() - if action != nil { - action() + actions := expected.call(args) + if expected.exhausted() { + ctrl.expectedCalls.Remove(expected) + } + return actions + }() + + var rets []interface{} + for _, action := range actions { + if r := action(args); r != nil { + rets = r + } } return rets } func (ctrl *Controller) Finish() { + if h, ok := ctrl.t.(testHelper); ok { + h.Helper() + } + ctrl.mu.Lock() defer ctrl.mu.Unlock() + if ctrl.finished { + ctrl.t.Fatalf("Controller.Finish was called more than once. It has to be called exactly once.") + } + ctrl.finished = true + // If we're currently panicking, probably because this is a deferred call, // pass through the panic. if err := recover(); err != nil { @@ -150,18 +196,23 @@ func (ctrl *Controller) Finish() { } // Check that all remaining expected calls are satisfied. - failures := false - for _, methodMap := range ctrl.expectedCalls { - for _, calls := range methodMap { - for _, call := range calls { - if !call.satisfied() { - ctrl.t.Errorf("missing call(s) to %v", call) - failures = true - } - } - } + failures := ctrl.expectedCalls.Failures() + for _, call := range failures { + ctrl.t.Errorf("missing call(s) to %v", call) } - if failures { + if len(failures) != 0 { ctrl.t.Fatalf("aborting test due to missing call(s)") } } + +func callerInfo(skip int) string { + if _, file, line, ok := runtime.Caller(skip + 1); ok { + return fmt.Sprintf("%s:%d", file, line) + } + return "unknown file" +} + +type testHelper interface { + TestReporter + Helper() +} diff --git a/vendor/github.com/golang/mock/gomock/matchers.go b/vendor/github.com/golang/mock/gomock/matchers.go index 32628ae8c..e8b1ddccf 100644 --- a/vendor/github.com/golang/mock/gomock/matchers.go +++ b/vendor/github.com/golang/mock/gomock/matchers.go @@ -1,3 +1,5 @@ +//go:generate mockgen -destination mock_matcher/mock_matcher.go github.com/golang/mock/gomock Matcher + // Copyright 2010 Google Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +24,7 @@ import ( // A Matcher is a representation of a class of values. // It is used to represent the valid or expected arguments to a mocked method. type Matcher interface { - // Matches returns whether y is a match. + // Matches returns whether x is a match. Matches(x interface{}) bool // String describes what the matcher matches. diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-change-multi-default-to-single/local-state.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-change-multi-default-to-single/local-state.tfstate new file mode 100644 index 000000000..88c1d86ec --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-change-multi-default-to-single/local-state.tfstate @@ -0,0 +1,6 @@ +{ + "version": 3, + "terraform_version": "0.8.2", + "serial": 7, + "lineage": "backend-change" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-change-multi-to-multi/local-state.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-change-multi-to-multi/local-state.tfstate new file mode 100644 index 000000000..88c1d86ec --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-change-multi-to-multi/local-state.tfstate @@ -0,0 +1,6 @@ +{ + "version": 3, + "terraform_version": "0.8.2", + "serial": 7, + "lineage": "backend-change" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-change-single-to-single/local-state.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-change-single-to-single/local-state.tfstate new file mode 100644 index 000000000..88c1d86ec --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-change-single-to-single/local-state.tfstate @@ -0,0 +1,6 @@ +{ + "version": 3, + "terraform_version": "0.8.2", + "serial": 7, + "lineage": "backend-change" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-change/local-state.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-change/local-state.tfstate new file mode 100644 index 000000000..88c1d86ec --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-change/local-state.tfstate @@ -0,0 +1,6 @@ +{ + "version": 3, + "terraform_version": "0.8.2", + "serial": 7, + "lineage": "backend-change" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-changed-with-legacy/local-state-old.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-changed-with-legacy/local-state-old.tfstate new file mode 100644 index 000000000..e9f980b59 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-changed-with-legacy/local-state-old.tfstate @@ -0,0 +1,6 @@ +{ + "version": 3, + "terraform_version": "0.8.2", + "serial": 7, + "lineage": "legacy" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-changed-with-legacy/local-state.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-changed-with-legacy/local-state.tfstate new file mode 100644 index 000000000..5e9330595 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-changed-with-legacy/local-state.tfstate @@ -0,0 +1,6 @@ +{ + "version": 3, + "terraform_version": "0.8.2", + "serial": 7, + "lineage": "configured" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-new-legacy/local-state-old.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-new-legacy/local-state-old.tfstate new file mode 100644 index 000000000..8f312596d --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-new-legacy/local-state-old.tfstate @@ -0,0 +1,12 @@ +{ + "version": 3, + "terraform_version": "0.8.2", + "serial": 7, + "lineage": "backend-new-legacy", + "remote": { + "type": "local", + "config": { + "path": "local-state-old.tfstate" + } + } +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-new-migrate-existing/local-state.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-new-migrate-existing/local-state.tfstate new file mode 100644 index 000000000..81f6ffebb --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-new-migrate-existing/local-state.tfstate @@ -0,0 +1,16 @@ +{ + "version": 3, + "terraform_version": "0.8.2", + "serial": 8, + "lineage": "remote", + "modules": [ + { + "path": [ + "root" + ], + "outputs": {}, + "resources": {}, + "depends_on": [] + } + ] +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-plan-backend-empty-config/local-state.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-plan-backend-empty-config/local-state.tfstate new file mode 100644 index 000000000..48be87380 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-plan-backend-empty-config/local-state.tfstate @@ -0,0 +1,5 @@ +{ + "version": 3, + "serial": 0, + "lineage": "hello" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-plan-backend-match/local-state.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-plan-backend-match/local-state.tfstate new file mode 100644 index 000000000..48be87380 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-plan-backend-match/local-state.tfstate @@ -0,0 +1,5 @@ +{ + "version": 3, + "serial": 0, + "lineage": "hello" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-plan-backend-mismatch/local-state.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-plan-backend-mismatch/local-state.tfstate new file mode 100644 index 000000000..50101996a --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-plan-backend-mismatch/local-state.tfstate @@ -0,0 +1,5 @@ +{ + "version": 3, + "serial": 0, + "lineage": "different" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-plan-legacy-data/local-state.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-plan-legacy-data/local-state.tfstate new file mode 100644 index 000000000..48be87380 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-plan-legacy-data/local-state.tfstate @@ -0,0 +1,5 @@ +{ + "version": 3, + "serial": 0, + "lineage": "hello" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-plan-legacy-data/state.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-plan-legacy-data/state.tfstate new file mode 100644 index 000000000..195441f37 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-plan-legacy-data/state.tfstate @@ -0,0 +1,21 @@ +{ + "version": 3, + "serial": 0, + "lineage": "666f9301-7e65-4b19-ae23-71184bb19b03", + "remote": { + "type": "local", + "config": { + "path": "local-state.tfstate" + } + }, + "modules": [ + { + "path": [ + "root" + ], + "outputs": {}, + "resources": {}, + "depends_on": [] + } + ] +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-unchanged-with-legacy/local-state-old.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-unchanged-with-legacy/local-state-old.tfstate new file mode 100644 index 000000000..7ebed86ad --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-unchanged-with-legacy/local-state-old.tfstate @@ -0,0 +1,6 @@ +{ + "version": 3, + "terraform_version": "0.8.2", + "serial": 7, + "lineage": "backend-unchanged-with-legacy" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-unchanged-with-legacy/local-state.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-unchanged-with-legacy/local-state.tfstate new file mode 100644 index 000000000..5e9330595 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-unchanged-with-legacy/local-state.tfstate @@ -0,0 +1,6 @@ +{ + "version": 3, + "terraform_version": "0.8.2", + "serial": 7, + "lineage": "configured" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-unchanged/local-state.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-unchanged/local-state.tfstate new file mode 100644 index 000000000..5ed2459a9 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-unchanged/local-state.tfstate @@ -0,0 +1,6 @@ +{ + "version": 3, + "terraform_version": "0.8.2", + "serial": 7, + "lineage": "configuredUnchanged" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-unset-with-legacy/local-state-old.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-unset-with-legacy/local-state-old.tfstate new file mode 100644 index 000000000..e9f980b59 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-unset-with-legacy/local-state-old.tfstate @@ -0,0 +1,6 @@ +{ + "version": 3, + "terraform_version": "0.8.2", + "serial": 7, + "lineage": "legacy" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-unset-with-legacy/local-state.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-unset-with-legacy/local-state.tfstate new file mode 100644 index 000000000..18a4c8009 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-unset-with-legacy/local-state.tfstate @@ -0,0 +1,6 @@ +{ + "version": 3, + "terraform_version": "0.8.2", + "serial": 7, + "lineage": "backend" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-unset/local-state.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-unset/local-state.tfstate new file mode 100644 index 000000000..51d588030 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/backend-unset/local-state.tfstate @@ -0,0 +1,6 @@ +{ + "version": 3, + "terraform_version": "0.8.2", + "serial": 7, + "lineage": "configuredUnset" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-list-backend/local-state.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-list-backend/local-state.tfstate new file mode 100644 index 000000000..fc10b3cc7 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-list-backend/local-state.tfstate @@ -0,0 +1,31 @@ +{ + "version": 3, + "terraform_version": "0.8.2", + "serial": 7, + "lineage": "configuredUnchanged", + "modules": [ + { + "path": [ + "root" + ], + "outputs": {}, + "resources": { + "null_resource.a": { + "type": "null_resource", + "depends_on": [], + "primary": { + "id": "5416263284413907707", + "attributes": { + "id": "5416263284413907707" + }, + "meta": {}, + "tainted": false + }, + "deposed": [], + "provider": "" + } + }, + "depends_on": [] + } + ] +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-bad-lineage/local-state.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-bad-lineage/local-state.tfstate new file mode 100644 index 000000000..4023b53e0 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-bad-lineage/local-state.tfstate @@ -0,0 +1,5 @@ +{ + "version": 3, + "serial": 1, + "lineage": "mismatch" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-bad-lineage/replace.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-bad-lineage/replace.tfstate new file mode 100644 index 000000000..0e3b7013a --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-bad-lineage/replace.tfstate @@ -0,0 +1,5 @@ +{ + "version": 3, + "serial": 2, + "lineage": "hello" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-good/replace.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-good/replace.tfstate new file mode 100644 index 000000000..48be87380 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-good/replace.tfstate @@ -0,0 +1,5 @@ +{ + "version": 3, + "serial": 0, + "lineage": "hello" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-replace-match/local-state.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-replace-match/local-state.tfstate new file mode 100644 index 000000000..8dd356bc9 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-replace-match/local-state.tfstate @@ -0,0 +1,5 @@ +{ + "version": 3, + "serial": 1, + "lineage": "hello" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-replace-match/replace.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-replace-match/replace.tfstate new file mode 100644 index 000000000..0e3b7013a --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-replace-match/replace.tfstate @@ -0,0 +1,5 @@ +{ + "version": 3, + "serial": 2, + "lineage": "hello" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-serial-newer/local-state.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-serial-newer/local-state.tfstate new file mode 100644 index 000000000..c114b190d --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-serial-newer/local-state.tfstate @@ -0,0 +1,5 @@ +{ + "version": 3, + "serial": 3, + "lineage": "hello" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-serial-newer/replace.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-serial-newer/replace.tfstate new file mode 100644 index 000000000..0e3b7013a --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-serial-newer/replace.tfstate @@ -0,0 +1,5 @@ +{ + "version": 3, + "serial": 2, + "lineage": "hello" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-serial-older/local-state.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-serial-older/local-state.tfstate new file mode 100644 index 000000000..8dd356bc9 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-serial-older/local-state.tfstate @@ -0,0 +1,5 @@ +{ + "version": 3, + "serial": 1, + "lineage": "hello" +} diff --git a/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-serial-older/replace.tfstate b/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-serial-older/replace.tfstate new file mode 100644 index 000000000..0e3b7013a --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/command/test-fixtures/state-push-serial-older/replace.tfstate @@ -0,0 +1,5 @@ +{ + "version": 3, + "serial": 2, + "lineage": "hello" +} diff --git a/vendor/github.com/jmespath/go-jmespath/cmd/jpgo/main.go b/vendor/github.com/jmespath/go-jmespath/cmd/jpgo/main.go new file mode 100644 index 000000000..1c53cfc86 --- /dev/null +++ b/vendor/github.com/jmespath/go-jmespath/cmd/jpgo/main.go @@ -0,0 +1,96 @@ +/*Basic command line interface for debug and testing purposes. + +Examples: + +Only print the AST for the expression: + + jp.go -ast "foo.bar.baz" + +Evaluate the JMESPath expression against JSON data from a file: + + jp.go -input /tmp/data.json "foo.bar.baz" + +This program can also be used as an executable to the jp-compliance +runner (github.com/jmespath/jmespath.test). + +*/ +package main + +import ( + "flag" + "fmt" + "io/ioutil" + "os" +) + +import ( + "encoding/json" + + "github.com/jmespath/go-jmespath" +) + +func errMsg(msg string, a ...interface{}) int { + fmt.Fprintf(os.Stderr, msg, a...) + fmt.Fprintln(os.Stderr) + return 1 +} + +func run() int { + + astOnly := flag.Bool("ast", false, "Print the AST for the input expression and exit.") + inputFile := flag.String("input", "", "Filename containing JSON data to search. If not provided, data is read from stdin.") + + flag.Parse() + args := flag.Args() + if len(args) != 1 { + fmt.Fprintf(os.Stderr, "Usage:\n\n") + flag.PrintDefaults() + return errMsg("\nError: expected a single argument (the JMESPath expression).") + } + + expression := args[0] + parser := jmespath.NewParser() + parsed, err := parser.Parse(expression) + if err != nil { + if syntaxError, ok := err.(jmespath.SyntaxError); ok { + return errMsg("%s\n%s\n", syntaxError, syntaxError.HighlightLocation()) + } + return errMsg("%s", err) + } + if *astOnly { + fmt.Println("") + fmt.Printf("%s\n", parsed) + return 0 + } + + var inputData []byte + if *inputFile != "" { + inputData, err = ioutil.ReadFile(*inputFile) + if err != nil { + return errMsg("Error loading file %s: %s", *inputFile, err) + } + } else { + // If an input data file is not provided then we read the + // data from stdin. + inputData, err = ioutil.ReadAll(os.Stdin) + if err != nil { + return errMsg("Error reading from stdin: %s", err) + } + } + var data interface{} + json.Unmarshal(inputData, &data) + result, err := jmespath.Search(expression, data) + if err != nil { + return errMsg("Error executing expression: %s", err) + } + toJSON, err := json.MarshalIndent(result, "", " ") + if err != nil { + return errMsg("Error serializing result to JSON: %s", err) + } + fmt.Println(string(toJSON)) + return 0 +} + +func main() { + os.Exit(run()) +} diff --git a/vendor/github.com/quintilesims/tftest/context.go b/vendor/github.com/quintilesims/tftest/context.go index bc31af127..d23365fca 100644 --- a/vendor/github.com/quintilesims/tftest/context.go +++ b/vendor/github.com/quintilesims/tftest/context.go @@ -2,7 +2,6 @@ package tftest import ( "fmt" - "log" "os" "os/exec" "strings" @@ -17,7 +16,7 @@ type Context struct { func NewContext(options ...ContextOption) *Context { context := &Context{ - Logger: log.New(os.Stdout, "", 0), + Logger: NewIOLogger(os.Stdout), Vars: map[string]string{}, dir: ".", } @@ -79,7 +78,7 @@ func (c *Context) Terraformf(command string, args ...string) ([]byte, error) { cmd.Env = env cmd.Dir = c.dir - c.Logger.Printf("Running %v from %s", cmd.Args, cmd.Dir) + c.Logger.Logf("Running %v from %s", cmd.Args, cmd.Dir) output, err := cmd.CombinedOutput() if err != nil { diff --git a/vendor/github.com/quintilesims/tftest/logger.go b/vendor/github.com/quintilesims/tftest/logger.go index c193f1568..e0067e270 100644 --- a/vendor/github.com/quintilesims/tftest/logger.go +++ b/vendor/github.com/quintilesims/tftest/logger.go @@ -1,21 +1,27 @@ package tftest import ( - "testing" + "fmt" + "io" ) type Logger interface { - Printf(string, ...interface{}) + Log(args ...interface{}) + Logf(format string, args ...interface{}) } -type TestLogger struct { - t *testing.T +type IOLogger struct { + writer io.Writer } -func NewTestLogger(t *testing.T) *TestLogger { - return &TestLogger{t: t} +func NewIOLogger(w io.Writer) *IOLogger { + return &IOLogger{writer: w} } -func (l *TestLogger) Printf(format string, tokens ...interface{}) { - l.t.Logf(format, tokens...) +func (i *IOLogger) Log(args ...interface{}) { + fmt.Fprint(i.writer, args...) +} + +func (i *IOLogger) Logf(format string, args ...interface{}) { + fmt.Fprintf(i.writer, format, args...) } diff --git a/vendor/github.com/quintilesims/tftest/test_context.go b/vendor/github.com/quintilesims/tftest/test_context.go index 127c59017..c4905bb6d 100644 --- a/vendor/github.com/quintilesims/tftest/test_context.go +++ b/vendor/github.com/quintilesims/tftest/test_context.go @@ -1,16 +1,16 @@ package tftest -import ( - "testing" -) +type Tester interface { + Fatal(args ...interface{}) + Fatalf(format string, args ...interface{}) +} type TestContext struct { *Context - t *testing.T + t Tester } -func NewTestContext(t *testing.T, options ...ContextOption) *TestContext { - options = append([]ContextOption{Log(NewTestLogger(t))}, options...) +func NewTestContext(t Tester, options ...ContextOption) *TestContext { return &TestContext{ Context: NewContext(options...), t: t, diff --git a/vendor/vendor.json b/vendor/vendor.json index 20973d0ce..c61454059 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -1333,9 +1333,10 @@ "revision": "afbd495e5aaea13597b5e14fe514ddeaa4d76fc3" }, { - "checksumSHA1": "I2lXmuk1IHZmw+zDXgTGi0+LvpY=", + "checksumSHA1": "/5JpULDw51Em+1+OJHcfDkbw/e0=", "path": "github.com/golang/mock/gomock", - "revision": "15f8b22550555c0d3edf5afa97d74001bda2208b" + "revision": "b3e60bcdc577185fce3cf625fc96b62857ce5574", + "revisionTime": "2017-12-16T01:26:12Z" }, { "checksumSHA1": "0SXJ9K2OIJosXJiCiDudn1t6nQ8=", @@ -3272,10 +3273,10 @@ "revisionTime": "2017-04-20T21:30:45Z" }, { - "checksumSHA1": "JTotRbkq8HA32xEvnbVARLr9mm4=", + "checksumSHA1": "ObB94Sg/UH32j6sGBtG6J2BQmaI=", "path": "github.com/quintilesims/tftest", - "revision": "398756cbff26d353c7d04c6a4e64132d5de82e6a", - "revisionTime": "2017-07-24T21:57:35Z" + "revision": "50e64a47e2216f68f260bbd17f8d8d0f81cbc127", + "revisionTime": "2017-08-23T23:42:00Z" }, { "checksumSHA1": "pvg8L4xN+zO9HLJislpVeHPPLjM=",