From 2d95081cab2fc2ae949f645a696f453d703acd51 Mon Sep 17 00:00:00 2001 From: Sam Craske Date: Wed, 4 Dec 2024 15:12:48 +1100 Subject: [PATCH] feat: agentMock, RunMock, and Bk plugin annotation is unused --- src/go.mod | 1 - src/go.sum | 2 -- src/main.go | 3 +-- src/plugin/task-runner.go | 19 +------------ src/plugin/task-runner_mocks_test.go | 40 ---------------------------- src/plugin/task-runner_test.go | 28 ------------------- 6 files changed, 2 insertions(+), 91 deletions(-) delete mode 100644 src/plugin/task-runner_mocks_test.go delete mode 100644 src/plugin/task-runner_test.go diff --git a/src/go.mod b/src/go.mod index 1b4acc6..9a89306 100644 --- a/src/go.mod +++ b/src/go.mod @@ -9,7 +9,6 @@ require ( require ( github.com/kr/pretty v0.1.0 // indirect - github.com/stretchr/objx v0.5.2 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect ) diff --git a/src/go.sum b/src/go.sum index 26f0816..58c034f 100644 --- a/src/go.sum +++ b/src/go.sum @@ -49,8 +49,6 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= diff --git a/src/main.go b/src/main.go index a70558e..5880fc0 100644 --- a/src/main.go +++ b/src/main.go @@ -10,11 +10,10 @@ import ( func main() { ctx := context.Background() - agent := &buildkite.Agent{} fetcher := plugin.EnvironmentConfigFetcher{} taskRunnerPlugin := plugin.TaskRunnerPlugin{} - err := taskRunnerPlugin.Run(ctx, fetcher, agent) + err := taskRunnerPlugin.Run(ctx, fetcher) if err != nil { buildkite.LogFailuref("plugin execution failed: %s\n", err.Error()) diff --git a/src/plugin/task-runner.go b/src/plugin/task-runner.go index 1f28793..a794aa2 100644 --- a/src/plugin/task-runner.go +++ b/src/plugin/task-runner.go @@ -22,11 +22,7 @@ type ConfigFetcher interface { Fetch(config *Config) error } -type Agent interface { - Annotate(ctx context.Context, message string, style string, annotationContext string) error -} - -func (trp TaskRunnerPlugin) Run(ctx context.Context, fetcher ConfigFetcher, agent Agent) error { +func (trp TaskRunnerPlugin) Run(ctx context.Context, fetcher ConfigFetcher) error { var config Config err := fetcher.Fetch(&config) if err != nil { @@ -36,19 +32,6 @@ func (trp TaskRunnerPlugin) Run(ctx context.Context, fetcher ConfigFetcher, agen buildkite.Log("Executing task-runner plugin\n") - annotation := config.ParameterName - err = agent.Annotate(ctx, annotation, "info", "message") - if err != nil { - buildkite.LogFailuref("buildkite annotation error: %s\n", err.Error()) - return err - } - annotation = config.Script - err = agent.Annotate(ctx, annotation, "info", "message") - if err != nil { - buildkite.LogFailuref("buildkite annotation error: %s\n", err.Error()) - return err - } - cfg, err := awsconfig.LoadDefaultConfig(ctx) if err != nil { log.Fatalf("config load failed: %v", err) diff --git a/src/plugin/task-runner_mocks_test.go b/src/plugin/task-runner_mocks_test.go deleted file mode 100644 index 94d0526..0000000 --- a/src/plugin/task-runner_mocks_test.go +++ /dev/null @@ -1,40 +0,0 @@ -package plugin_test - -import ( - "context" - "ecs-task-runner/plugin" - - "github.com/stretchr/testify/mock" -) - -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 deleted file mode 100644 index c819398..0000000 --- a/src/plugin/task-runner_test.go +++ /dev/null @@ -1,28 +0,0 @@ -package plugin_test - -import ( - "context" - "testing" - - "ecs-task-runner/plugin" - - "github.com/stretchr/testify/require" -) - -func TestDoesAnnotate(t *testing.T) { - agent := &AgentMock{} - fetcher := plugin.EnvironmentConfigFetcher{} - examplePlugin := mockPlugin{} - ctx := context.Background() - parameterName := "test-parameter" - secretName := "hello-world" - - t.Setenv("BUILDKITE_PLUGIN_ECS_TASK_RUNNER_PARAMETER_NAME", parameterName) - t.Setenv("BUILDKITE_PLUGIN_ECS_TASK_RUNNER_SCRIPT", secretName) - agent.Mock.On("Annotate", ctx, parameterName, "info", "message").Return(nil) - agent.Mock.On("Annotate", ctx, secretName, "info", "message").Return(nil) - - err := examplePlugin.RunMock(ctx, fetcher, agent) - - require.NoError(t, err, "should not error") -}