From da6dbee691f279077999c6c405ab2443ff0621f8 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Fri, 2 Aug 2024 19:34:25 -0400 Subject: [PATCH] refactor: remove pull indirection, call driver directly --- internal/runner/runner.go | 7 +------ internal/runner/runner_flow_test.go | 20 -------------------- 2 files changed, 1 insertion(+), 26 deletions(-) diff --git a/internal/runner/runner.go b/internal/runner/runner.go index afa9874..41f48b9 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -96,7 +96,7 @@ func (r *Runner) Execute(workflow workflow.Workflow) Task { log.Printf("Using image %s (label: %s)", runnerImage, job.RunsOn) - if pullError := r.PullContainer(runnerImage); pullError != nil { + if pullError := r.Driver.Pull(runnerImage); pullError != nil { jobContext.SetStatus("failed").SetError(pullError) continue } @@ -137,11 +137,6 @@ func (r *Runner) RunJobInContainer(imageUri string, containerId string, job work return nil } -// Pulls the container from the registry provided its image uri. -func (r *Runner) PullContainer(uri string) error { - return r.Driver.Pull(uri) -} - // Executes a command within the given container. // // If the command raises an error while in the container or fails to run diff --git a/internal/runner/runner_flow_test.go b/internal/runner/runner_flow_test.go index 1596c34..b99d033 100644 --- a/internal/runner/runner_flow_test.go +++ b/internal/runner/runner_flow_test.go @@ -3,7 +3,6 @@ package runner import ( "errors" workflow "runner/internal/workflow" - "slices" "testing" ) @@ -111,22 +110,3 @@ func TestRunJobInContainerSchedulesStoppingContainers(t *testing.T) { t.Errorf("Expected 1 deferred task, found %d instead.", len(runner.deferred)) } } - -func TestRunnerPullContainerCallsDriverPull(t *testing.T) { - mockDriver := NewMockDriver() - runner := Runner{ - Driver: &mockDriver, - } - - runner.PullContainer("test-image") - - if len(mockDriver.calls) != 1 { - t.Error("Expected pull to have been called.") - } - - expectedArgs := []string{"test-image"} - actualArgs := mockDriver.calls["Pull"][0].args - if !slices.Equal(actualArgs, expectedArgs) { - t.Errorf("Expected call args to be %#v, got %#v instead.", expectedArgs, actualArgs) - } -}