From e20d05ed6a38961376b3759406cc23825ffd3171 Mon Sep 17 00:00:00 2001 From: Sam Craske Date: Thu, 28 Nov 2024 11:30:04 +1100 Subject: [PATCH] test(plugin): mocks have a pre-existing shared directory --- src/plugin/task-runner_mocks_test.go | 24 ++++++++++++++++++++++++ src/plugin/task-runner_test.go | 17 ----------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/plugin/task-runner_mocks_test.go b/src/plugin/task-runner_mocks_test.go index efc4640..94d0526 100644 --- a/src/plugin/task-runner_mocks_test.go +++ b/src/plugin/task-runner_mocks_test.go @@ -2,6 +2,7 @@ package plugin_test import ( "context" + "ecs-task-runner/plugin" "github.com/stretchr/testify/mock" ) @@ -10,7 +11,30 @@ type AgentMock struct { mock.Mock } +type mockPlugin struct{} + func (m *AgentMock) Annotate(ctx context.Context, message string, style string, annotationContext string) error { args := m.Called(ctx, message, style, annotationContext) return args.Error(0) } + +// TODO: Run is overloaded with more than what was in the original template. We'd have to perform more-dependency injection if we use the original implementation +// In my head, it would make more sense to throw together a smaller mock Run function with just enough to test what we need +func (mp mockPlugin) RunMock(ctx context.Context, fetcher plugin.ConfigFetcher, agent plugin.Agent) error { + var config plugin.Config + err := fetcher.Fetch(&config) + if err != nil { + return err + } + + err = agent.Annotate(ctx, config.ParameterName, "info", "message") + if err != nil { + return err + } + err = agent.Annotate(ctx, config.Script, "info", "message") + if err != nil { + return err + } + + return nil +} diff --git a/src/plugin/task-runner_test.go b/src/plugin/task-runner_test.go index 5695bb6..f100a5c 100644 --- a/src/plugin/task-runner_test.go +++ b/src/plugin/task-runner_test.go @@ -9,8 +9,6 @@ import ( "github.com/stretchr/testify/require" ) -type mockPlugin struct{} - func TestDoesAnnotate(t *testing.T) { agent := &AgentMock{} fetcher := plugin.EnvironmentConfigFetcher{} @@ -28,18 +26,3 @@ func TestDoesAnnotate(t *testing.T) { require.NoError(t, err, "should not error") } - -// TODO: Run is overloaded with more than what was in the original template. We'd have to perform more-dependency injection if we use the original implementation -// In my head, it would make more sense to throw together a smaller mock Run function with just enough to test what we need -func (mp mockPlugin) RunMock(ctx context.Context, fetcher plugin.ConfigFetcher, agent plugin.Agent) error { - var config plugin.Config - err := fetcher.Fetch(&config) - if err != nil { - return err - } - - agent.Annotate(ctx, config.ParameterName, "info", "message") - agent.Annotate(ctx, config.Script, "info", "message") - - return nil -}