Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sreya committed Jul 1, 2024
1 parent 09f8fad commit 907d47b
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 26 deletions.
8 changes: 4 additions & 4 deletions buildlog/coder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (
"net/url"
"time"

"github.com/google/uuid"
"golang.org/x/xerrors"
"storj.io/drpc"

"cdr.dev/slog"
"github.com/coder/coder/v2/agent/proto"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/codersdk/agentsdk"
"github.com/coder/retry"
"github.com/google/uuid"
"golang.org/x/xerrors"
"storj.io/drpc"
)

const (
Expand Down Expand Up @@ -109,7 +110,6 @@ func OpenCoderClient(ctx context.Context, accessURL *url.URL, logger slog.Logger

type CoderLogger struct {
ctx context.Context
cancel context.CancelFunc
client CoderClient
logger slog.Logger
}
Expand Down
14 changes: 13 additions & 1 deletion buildlog/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package buildlog
import (
"fmt"
"io"

"golang.org/x/xerrors"
)

type Logger interface {
Expand Down Expand Up @@ -48,8 +50,18 @@ func (m multiLogger) Write(p []byte) (int, error) {
}

func (m multiLogger) Close() error {
var errs error
for _, log := range m.loggers {
log.Close()
if err := log.Close(); err != nil {
if errs == nil {
errs = err
} else {
errs = xerrors.Errorf("%v: %w", errs.Error(), err)
}
}
}
if errs != nil {
return xerrors.Errorf("close: %w", errs)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions cli/clitest/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewFakeExecer() *xunixfake.FakeExec {
func NewFakeDockerClient() dockerutil.DockerClient {
client := &dockerfake.MockClient{}

client.ContainerInspectFn = func(_ context.Context, container string) (dockertypes.ContainerJSON, error) {
client.ContainerInspectFn = func(_ context.Context, _ string) (dockertypes.ContainerJSON, error) {
return dockertypes.ContainerJSON{
ContainerJSONBase: &dockertypes.ContainerJSONBase{
GraphDriver: dockertypes.GraphDriverData{
Expand All @@ -51,7 +51,7 @@ func NewFakeDockerClient() dockerutil.DockerClient {
}, nil
}

client.ContainerExecAttachFn = func(_ context.Context, execID string, config dockertypes.ExecStartCheck) (dockertypes.HijackedResponse, error) {
client.ContainerExecAttachFn = func(_ context.Context, _ string, _ dockertypes.ExecStartCheck) (dockertypes.HijackedResponse, error) {
return dockertypes.HijackedResponse{
Reader: bufio.NewReader(strings.NewReader("root:x:0:0:root:/root:/bin/bash")),
Conn: &net.IPConn{},
Expand Down
4 changes: 1 addition & 3 deletions cli/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,7 @@ func runDockerCVM(ctx context.Context, log slog.Logger, client dockerutil.Docker
blog.Info("Starting up workspace...")
err = client.ContainerStart(ctx, containerID, dockertypes.ContainerStartOptions{})
if err != nil {
if err != nil {
return xerrors.Errorf("start container: %w", err)
}
return xerrors.Errorf("start container: %w", err)
}

log.Debug(ctx, "creating bootstrap directory", slog.F("directory", imgMeta.HomeDir))
Expand Down
22 changes: 11 additions & 11 deletions cli/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func TestDocker(t *testing.T) {

client := clitest.DockerClient(t, ctx)
var called bool
client.ContainerCreateFn = func(_ context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, _ *v1.Platform, containerName string) (container.CreateResponse, error) {
client.ContainerCreateFn = func(_ context.Context, config *container.Config, _ *container.HostConfig, _ *network.NetworkingConfig, _ *v1.Platform, containerName string) (container.CreateResponse, error) {
if containerName == cli.InnerContainerName {
called = true
require.ElementsMatch(t, expectedEnvs, config.Env)
Expand Down Expand Up @@ -213,15 +213,15 @@ func TestDocker(t *testing.T) {

// Set the exec response from inspecting the image to some ID
// greater than 0.
client.ContainerExecAttachFn = func(_ context.Context, execID string, config dockertypes.ExecStartCheck) (dockertypes.HijackedResponse, error) {
client.ContainerExecAttachFn = func(_ context.Context, _ string, _ dockertypes.ExecStartCheck) (dockertypes.HijackedResponse, error) {
return dockertypes.HijackedResponse{
Reader: bufio.NewReader(strings.NewReader("root:x:1001:1001:root:/root:/bin/bash")),
Conn: &net.IPConn{},
}, nil
}

var called bool
client.ContainerCreateFn = func(_ context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, _ *v1.Platform, containerName string) (container.CreateResponse, error) {
client.ContainerCreateFn = func(_ context.Context, _ *container.Config, hostConfig *container.HostConfig, _ *network.NetworkingConfig, _ *v1.Platform, containerName string) (container.CreateResponse, error) {
if containerName == cli.InnerContainerName {
called = true
require.Equal(t, expectedMounts, hostConfig.Binds)
Expand Down Expand Up @@ -301,7 +301,7 @@ func TestDocker(t *testing.T) {
)

var called bool
client.ContainerCreateFn = func(_ context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, _ *v1.Platform, containerName string) (container.CreateResponse, error) {
client.ContainerCreateFn = func(_ context.Context, _ *container.Config, hostConfig *container.HostConfig, _ *network.NetworkingConfig, _ *v1.Platform, containerName string) (container.CreateResponse, error) {
if containerName == cli.InnerContainerName {
called = true
require.Equal(t, expectedDevices, hostConfig.Devices)
Expand Down Expand Up @@ -346,7 +346,7 @@ func TestDocker(t *testing.T) {
statExecID = "hi"
)

client.ContainerExecCreateFn = func(_ context.Context, container string, config dockertypes.ExecConfig) (dockertypes.IDResponse, error) {
client.ContainerExecCreateFn = func(_ context.Context, _ string, config dockertypes.ExecConfig) (dockertypes.IDResponse, error) {
if config.Cmd[0] == "stat" {
return dockertypes.IDResponse{
ID: statExecID,
Expand All @@ -366,7 +366,7 @@ func TestDocker(t *testing.T) {
}

var called bool
client.ContainerCreateFn = func(_ context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, _ *v1.Platform, containerName string) (container.CreateResponse, error) {
client.ContainerCreateFn = func(_ context.Context, config *container.Config, _ *container.HostConfig, _ *network.NetworkingConfig, _ *v1.Platform, containerName string) (container.CreateResponse, error) {
if containerName == cli.InnerContainerName {
called = true
require.Equal(t, []string{"sleep", "infinity"}, []string(config.Entrypoint))
Expand Down Expand Up @@ -394,7 +394,7 @@ func TestDocker(t *testing.T) {
authB64 := base64.URLEncoding.EncodeToString(raw)

client := clitest.DockerClient(t, ctx)
client.ImagePullFn = func(_ context.Context, ref string, options dockertypes.ImagePullOptions) (io.ReadCloser, error) {
client.ImagePullFn = func(_ context.Context, _ string, options dockertypes.ImagePullOptions) (io.ReadCloser, error) {
// Assert that we call the image pull function with the credentials.
require.Equal(t, authB64, options.RegistryAuth)
return io.NopCloser(bytes.NewReader(nil)), nil
Expand Down Expand Up @@ -423,7 +423,7 @@ func TestDocker(t *testing.T) {

var called bool
client := clitest.DockerClient(t, ctx)
client.ContainerCreateFn = func(_ context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, _ *v1.Platform, containerName string) (container.CreateResponse, error) {
client.ContainerCreateFn = func(_ context.Context, _ *container.Config, hostConfig *container.HostConfig, _ *network.NetworkingConfig, _ *v1.Platform, containerName string) (container.CreateResponse, error) {
if containerName == cli.InnerContainerName {
called = true
require.Equal(t, int64(memory), hostConfig.Memory)
Expand Down Expand Up @@ -542,7 +542,7 @@ func TestDocker(t *testing.T) {

var called bool
client := clitest.DockerClient(t, ctx)
client.ContainerCreateFn = func(_ context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, _ *v1.Platform, containerName string) (container.CreateResponse, error) {
client.ContainerCreateFn = func(_ context.Context, config *container.Config, hostConfig *container.HostConfig, _ *network.NetworkingConfig, _ *v1.Platform, containerName string) (container.CreateResponse, error) {
if containerName == cli.InnerContainerName {
called = true
// Test that '/dev' mounts are passed as devices.
Expand All @@ -565,7 +565,7 @@ func TestDocker(t *testing.T) {
for _, file := range expectedUsrLibFiles {
require.Contains(t, hostConfig.Binds, fmt.Sprintf("%s:%s:ro",
file,
strings.Replace(file, usrLibMountpoint, "/usr/lib/", -1),
strings.ReplaceAll(file, usrLibMountpoint, "/usr/lib/"),
))
}

Expand Down Expand Up @@ -599,7 +599,7 @@ func TestDocker(t *testing.T) {

var called bool
client := clitest.DockerClient(t, ctx)
client.ContainerCreateFn = func(_ context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, _ *v1.Platform, containerName string) (container.CreateResponse, error) {
client.ContainerCreateFn = func(_ context.Context, config *container.Config, _ *container.HostConfig, _ *network.NetworkingConfig, _ *v1.Platform, containerName string) (container.CreateResponse, error) {
if containerName == cli.InnerContainerName {
called = true
require.Equal(t, "hello-world", config.Hostname)
Expand Down
6 changes: 2 additions & 4 deletions cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ func Root() *cobra.Command {
Use: "envbox",
SilenceErrors: true,
SilenceUsage: true,
Args: func(cmd *cobra.Command, args []string) error {
return cobra.NoArgs(cmd, args)
},
RunE: func(cmd *cobra.Command, args []string) error {
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
return cmd.Help()
},
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ require (
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028
k8s.io/mount-utils v0.26.2
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2
storj.io/drpc v0.0.33
)

require (
Expand Down Expand Up @@ -215,6 +216,5 @@ require (
inet.af/peercred v0.0.0-20210906144145-0893ea02156a // indirect
k8s.io/klog/v2 v2.100.1 // indirect
nhooyr.io/websocket v1.8.7 // indirect
storj.io/drpc v0.0.33 // indirect
tailscale.com v1.46.1 // indirect
)

0 comments on commit 907d47b

Please sign in to comment.