Skip to content

Commit

Permalink
chore: reduce linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dmke committed Mar 21, 2024
1 parent 91c258d commit 37aa8c3
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 15 deletions.
4 changes: 2 additions & 2 deletions exec/docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 8 additions & 6 deletions exec/docker_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ 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(
ctx context.Context,
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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion exec/docker_in_docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions exec/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions exec/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
}
Expand Down
4 changes: 3 additions & 1 deletion exec/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 37aa8c3

Please sign in to comment.