Skip to content

Commit

Permalink
test(plugin): mocks have a pre-existing shared directory
Browse files Browse the repository at this point in the history
  • Loading branch information
therealvio committed Nov 28, 2024
1 parent b5dc822 commit e20d05e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
24 changes: 24 additions & 0 deletions src/plugin/task-runner_mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package plugin_test

import (
"context"
"ecs-task-runner/plugin"

"github.com/stretchr/testify/mock"
)
Expand All @@ -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
}
17 changes: 0 additions & 17 deletions src/plugin/task-runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"github.com/stretchr/testify/require"
)

type mockPlugin struct{}

func TestDoesAnnotate(t *testing.T) {
agent := &AgentMock{}
fetcher := plugin.EnvironmentConfigFetcher{}
Expand All @@ -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
}

0 comments on commit e20d05e

Please sign in to comment.