From 644cdb763426016ccb1a99d301966713b0bf25a6 Mon Sep 17 00:00:00 2001 From: ilya-hontarau Date: Thu, 8 Aug 2024 12:52:57 +0200 Subject: [PATCH] gen mocks in test pkg --- cmd/internal/handle.go | 4 +++- internal/auto_scaler.go | 5 +++-- internal/mock_controller_test.go | 36 +++++++++++++++++--------------- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/cmd/internal/handle.go b/cmd/internal/handle.go index 227f7d3..3a4084a 100644 --- a/cmd/internal/handle.go +++ b/cmd/internal/handle.go @@ -3,9 +3,11 @@ package internal import ( "context" "fmt" + "github.com/caarlos0/env/v9" - "github.com/spacelift-io/awsautoscalr/internal" "golang.org/x/exp/slog" + + "github.com/spacelift-io/awsautoscalr/internal" ) func Handle(ctx context.Context, logger *slog.Logger) error { diff --git a/internal/auto_scaler.go b/internal/auto_scaler.go index f855c5d..fed873e 100644 --- a/internal/auto_scaler.go +++ b/internal/auto_scaler.go @@ -3,13 +3,14 @@ package internal import ( "context" "fmt" + "time" + autoscalingtypes "github.com/aws/aws-sdk-go-v2/service/autoscaling/types" ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types" "golang.org/x/exp/slog" - "time" ) -//go:generate mockery --inpackage --name ControllerInterface --filename mock_controller_test.go +//go:generate mockery --output ./ --name ControllerInterface --filename mock_controller_test.go --outpkg internal_test type ControllerInterface interface { DescribeInstances(ctx context.Context, instanceIDs []string) (instances []ec2types.Instance, err error) GetAutoscalingGroup(ctx context.Context) (out *autoscalingtypes.AutoScalingGroup, err error) diff --git a/internal/mock_controller_test.go b/internal/mock_controller_test.go index 2a010c6..fcff8d7 100644 --- a/internal/mock_controller_test.go +++ b/internal/mock_controller_test.go @@ -1,24 +1,26 @@ // Code generated by mockery v2.42.1. DO NOT EDIT. -package internal +package internal_test import ( context "context" autoscalingtypes "github.com/aws/aws-sdk-go-v2/service/autoscaling/types" + internal "github.com/spacelift-io/awsautoscalr/internal" + mock "github.com/stretchr/testify/mock" types "github.com/aws/aws-sdk-go-v2/service/ec2/types" ) -// MockControllerInterface is an autogenerated mock type for the ControllerInterface type -type MockControllerInterface struct { +// ControllerInterface is an autogenerated mock type for the ControllerInterface type +type ControllerInterface struct { mock.Mock } // DescribeInstances provides a mock function with given fields: ctx, instanceIDs -func (_m *MockControllerInterface) DescribeInstances(ctx context.Context, instanceIDs []string) ([]types.Instance, error) { +func (_m *ControllerInterface) DescribeInstances(ctx context.Context, instanceIDs []string) ([]types.Instance, error) { ret := _m.Called(ctx, instanceIDs) if len(ret) == 0 { @@ -48,7 +50,7 @@ func (_m *MockControllerInterface) DescribeInstances(ctx context.Context, instan } // DrainWorker provides a mock function with given fields: ctx, workerID -func (_m *MockControllerInterface) DrainWorker(ctx context.Context, workerID string) (bool, error) { +func (_m *ControllerInterface) DrainWorker(ctx context.Context, workerID string) (bool, error) { ret := _m.Called(ctx, workerID) if len(ret) == 0 { @@ -76,7 +78,7 @@ func (_m *MockControllerInterface) DrainWorker(ctx context.Context, workerID str } // GetAutoscalingGroup provides a mock function with given fields: ctx -func (_m *MockControllerInterface) GetAutoscalingGroup(ctx context.Context) (*autoscalingtypes.AutoScalingGroup, error) { +func (_m *ControllerInterface) GetAutoscalingGroup(ctx context.Context) (*autoscalingtypes.AutoScalingGroup, error) { ret := _m.Called(ctx) if len(ret) == 0 { @@ -106,23 +108,23 @@ func (_m *MockControllerInterface) GetAutoscalingGroup(ctx context.Context) (*au } // GetWorkerPool provides a mock function with given fields: ctx -func (_m *MockControllerInterface) GetWorkerPool(ctx context.Context) (*WorkerPool, error) { +func (_m *ControllerInterface) GetWorkerPool(ctx context.Context) (*internal.WorkerPool, error) { ret := _m.Called(ctx) if len(ret) == 0 { panic("no return value specified for GetWorkerPool") } - var r0 *WorkerPool + var r0 *internal.WorkerPool var r1 error - if rf, ok := ret.Get(0).(func(context.Context) (*WorkerPool, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context) (*internal.WorkerPool, error)); ok { return rf(ctx) } - if rf, ok := ret.Get(0).(func(context.Context) *WorkerPool); ok { + if rf, ok := ret.Get(0).(func(context.Context) *internal.WorkerPool); ok { r0 = rf(ctx) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*WorkerPool) + r0 = ret.Get(0).(*internal.WorkerPool) } } @@ -136,7 +138,7 @@ func (_m *MockControllerInterface) GetWorkerPool(ctx context.Context) (*WorkerPo } // KillInstance provides a mock function with given fields: ctx, instanceID -func (_m *MockControllerInterface) KillInstance(ctx context.Context, instanceID string) error { +func (_m *ControllerInterface) KillInstance(ctx context.Context, instanceID string) error { ret := _m.Called(ctx, instanceID) if len(ret) == 0 { @@ -154,7 +156,7 @@ func (_m *MockControllerInterface) KillInstance(ctx context.Context, instanceID } // ScaleUpASG provides a mock function with given fields: ctx, desiredCapacity -func (_m *MockControllerInterface) ScaleUpASG(ctx context.Context, desiredCapacity int32) error { +func (_m *ControllerInterface) ScaleUpASG(ctx context.Context, desiredCapacity int32) error { ret := _m.Called(ctx, desiredCapacity) if len(ret) == 0 { @@ -171,13 +173,13 @@ func (_m *MockControllerInterface) ScaleUpASG(ctx context.Context, desiredCapaci return r0 } -// NewMockControllerInterface creates a new instance of MockControllerInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// NewControllerInterface creates a new instance of ControllerInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. -func NewMockControllerInterface(t interface { +func NewControllerInterface(t interface { mock.TestingT Cleanup(func()) -}) *MockControllerInterface { - mock := &MockControllerInterface{} +}) *ControllerInterface { + mock := &ControllerInterface{} mock.Mock.Test(t) t.Cleanup(func() { mock.AssertExpectations(t) })