diff --git a/exec/docker_client.go b/exec/docker_client.go index 8052525..c426df5 100644 --- a/exec/docker_client.go +++ b/exec/docker_client.go @@ -18,7 +18,7 @@ import ( "go.uber.org/zap" ) -// newClient is swapped in tests +// newClient is swapped in tests. var newClient = func() (client.APIClient, error) { return client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) } @@ -178,7 +178,7 @@ func (dc *DockerClient) findAllowedImageID(tag string) string { return "" } -// containerWd is the work dir inside a (new) container +// containerWd is the work dir inside a (new) container. const containerWd = "/texd" func (dc *DockerClient) prepareContainer(ctx context.Context, tag, wd string, cmd []string) (string, error) { diff --git a/exec/docker_client_test.go b/exec/docker_client_test.go index 677890c..02324a3 100644 --- a/exec/docker_client_test.go +++ b/exec/docker_client_test.go @@ -41,7 +41,7 @@ func (m *apiMock) ImageList( args := m.Called(ctx, options) // channel trickery to allow TestSetImages create different return values // (and work around a limitation of the mock framework) - return <-args.Get(0).(chan []image.Summary), <-args.Get(1).(chan error) + return <-args.Get(0).(chan []image.Summary), <-args.Get(1).(chan error) //nolint:forcetypeassert } func (m *apiMock) ContainerInspect( @@ -49,7 +49,7 @@ func (m *apiMock) ContainerInspect( id string, ) (types.ContainerJSON, error) { args := m.Called(ctx, id) - return args.Get(0).(types.ContainerJSON), args.Error(1) + return args.Get(0).(types.ContainerJSON), args.Error(1) //nolint:forcetypeassert } func (m *apiMock) ImagePull( @@ -58,7 +58,7 @@ func (m *apiMock) ImagePull( options image.PullOptions, ) (io.ReadCloser, error) { args := m.Called(ctx, ref, options) - return args.Get(0).(io.ReadCloser), args.Error(1) + return args.Get(0).(io.ReadCloser), args.Error(1) //nolint:forcetypeassert } func (m *apiMock) ContainerLogs( @@ -67,7 +67,7 @@ func (m *apiMock) ContainerLogs( options container.LogsOptions, ) (io.ReadCloser, error) { args := m.Called(ctx, container, options) - return args.Get(0).(io.ReadCloser), args.Error(1) + return args.Get(0).(io.ReadCloser), args.Error(1) //nolint:forcetypeassert } func (m *apiMock) ContainerCreate( @@ -79,7 +79,7 @@ func (m *apiMock) ContainerCreate( containerName string, ) (container.CreateResponse, error) { args := m.Called(ctx, config, host, networking, platform, containerName) - return args.Get(0).(container.CreateResponse), args.Error(1) + return args.Get(0).(container.CreateResponse), args.Error(1) //nolint:forcetypeassert } func (m *apiMock) ContainerStart( @@ -97,7 +97,7 @@ func (m *apiMock) ContainerWait( condition container.WaitCondition, ) (<-chan container.WaitResponse, <-chan error) { args := m.Called(ctx, containerID, condition) - return args.Get(0).(chan container.WaitResponse), args.Get(1).(chan error) + return args.Get(0).(chan container.WaitResponse), args.Get(1).(chan error) //nolint:forcetypeassert } type dockerClientSuite struct { @@ -467,6 +467,8 @@ func (s *dockerClientSuite) TestSetImages_errLosingImageA() { errCh <- errors.New("image-list-err") close(errCh) + s.cli.On("ImageList", bg, image.ListOptions{}).Return(imgCh, errCh) + s.cli.On("ImagePull", bg, "test:v0", image.PullOptions{}). Return(io.NopCloser(&bytes.Buffer{}), nil) found, err := s.subject.SetImages(bg, true, "test:v0") diff --git a/exec/docker_in_docker.go b/exec/docker_in_docker.go index 0def285..e15c3a5 100644 --- a/exec/docker_in_docker.go +++ b/exec/docker_in_docker.go @@ -33,7 +33,7 @@ func (r *baseDirRewrite) MountConfig(path string) mount.Mount { var ErrMissingWorkdirVolume = errors.New("missing Docker volume or bind mount for work directory") -// swapped in tests +// swapped in tests. var ( dockerFs = afero.NewOsFs() hostname = os.Hostname diff --git a/exec/exec.go b/exec/exec.go index 1aec73c..7f98849 100644 --- a/exec/exec.go +++ b/exec/exec.go @@ -8,7 +8,7 @@ import ( ) type Exec interface { - Run(context.Context, *zap.Logger) error + Run(ctx context.Context, logger *zap.Logger) error } // Document is a sub-set of the tex.Document interface. diff --git a/exec/exec_test.go b/exec/exec_test.go index 9678095..68256a5 100644 --- a/exec/exec_test.go +++ b/exec/exec_test.go @@ -18,12 +18,12 @@ type mockDocument struct { var _ Document = (*mockDocument)(nil) -// methods of tex.Document needed for this test +// methods of tex.Document needed for this test. func (m *mockDocument) WorkingDirectory() (string, error) { return m.wd, m.wdErr } func (m *mockDocument) MainInput() (string, error) { return m.main, m.mainErr } func (*mockDocument) Engine() tex.Engine { return tex.DefaultEngine } -// methods required to satisfy the Document interface +// methods required to satisfy the Document interface. func (*mockDocument) Image() string { return "" } func TestBaseExec_extract(t *testing.T) { diff --git a/exec/local_test.go b/exec/local_test.go index f12649e..2b9563c 100644 --- a/exec/local_test.go +++ b/exec/local_test.go @@ -56,14 +56,14 @@ func TestLocalExec_Run(t *testing.T) { for _, tt := range tests { t.Run(tt.path, func(t *testing.T) { // create local exec - exec := LocalExec(tt.doc).(*localExec) + exec := LocalExec(tt.doc).(*localExec) //nolint:forcetypeassert exec.path = tt.path err := exec.Run(context.Background(), zap.NewNop()) if tt.expectedErr == "" { assert.NoError(t, err) } else if assert.EqualError(t, err, tt.expectedErr) { - cErr := err.(*tex.ErrWithCategory) + cErr := err.(*tex.ErrWithCategory) //nolint:forcetypeassert if tt.expectedOutput != "" { assert.Equal(t, tt.expectedOutput, cErr.Extra()["output"]) } diff --git a/exec/mock.go b/exec/mock.go index 5fc49f6..c4146c1 100644 --- a/exec/mock.go +++ b/exec/mock.go @@ -57,7 +57,9 @@ func (x *MockExec) Run(ctx context.Context, log *zap.Logger) error { outfile = main[:dot] + ".pdf" } - adder, ok := x.doc.(interface{ AddFile(string, string) error }) + adder, ok := x.doc.(interface { + AddFile(name string, content string) error + }) if !ok { panic("can't add files to document") }