Skip to content

Commit

Permalink
test: fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Jian Zeng <[email protected]>
  • Loading branch information
knight42 committed Jan 3, 2024
1 parent dee59a0 commit 731ec0c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
9 changes: 5 additions & 4 deletions pkg/docker/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/client"
"github.com/docker/docker/errdefs"
Expand Down Expand Up @@ -42,7 +43,7 @@ type clientImpl struct {
client *client.Client
}

func (c *clientImpl) listImages(timeout time.Duration) ([]types.ImageSummary, error) {
func (c *clientImpl) listImages(timeout time.Duration) ([]image.Summary, error) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
return c.client.ImageList(ctx, types.ImageListOptions{
Expand Down Expand Up @@ -92,7 +93,7 @@ func (c *clientImpl) ListContainersWithTimeout(running bool, timeout time.Durati
args.Add("status", status)
}

return c.client.ContainerList(ctx, types.ContainerListOptions{
return c.client.ContainerList(ctx, container.ListOptions{
All: true,
Filters: args,
})
Expand All @@ -101,7 +102,7 @@ func (c *clientImpl) ListContainersWithTimeout(running bool, timeout time.Durati
func (c *clientImpl) RemoveContainerWithTimeout(id string, timeout time.Duration) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
return c.client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{
return c.client.ContainerRemove(ctx, id, container.RemoveOptions{
RemoveVolumes: true,
Force: true,
})
Expand Down Expand Up @@ -151,7 +152,7 @@ func (c *clientImpl) RunContainer(ctx context.Context, config *container.Config,
}
}

err = c.client.ContainerStart(ctx, ct.ID, types.ContainerStartOptions{})
err = c.client.ContainerStart(ctx, ct.ID, container.StartOptions{})
if err != nil {
return "", fmt.Errorf("start container: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/docker/fake/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (f *Client) WaitContainerWithTimeout(id string, timeout time.Duration) (int
return 0, fmt.Errorf("container %s not found", id)
}
const delay = 5 * time.Second
if timeout < delay {
if timeout > 0 && timeout < delay {
time.Sleep(timeout)
return 0, context.DeadlineExceeded
}
Expand Down
15 changes: 6 additions & 9 deletions pkg/server/repo_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ func TestHandlerSyncRepo(t *testing.T) {
Cron: "@every 1h",
Image: "alpine:latest",
StorageDir: "/data",
Envs: model.StringMap{
"UPSTREAM": "http://foo.com",
},
}).Error)
schedule, _ := cron.ParseStandard("@every 1h")
te.server.repoSchedules.Set(name, schedule)
Expand All @@ -147,15 +144,15 @@ func TestHandlerSyncRepo(t *testing.T) {
Name: name,
}
testutils.PollUntilTimeout(t, time.Minute, func() bool {
require.NoError(t, te.server.db.First(&meta).Error)
require.NoError(t, te.server.db.Take(&meta).Error)
return !meta.Syncing
})

require.NoError(t, te.server.db.First(&meta).Error)
require.EqualValues(t, "http://foo.com", meta.Upstream)
require.NotEmpty(t, meta.PrevRun)
require.NotEmpty(t, meta.LastSuccess)
require.NotEmpty(t, meta.NextRun)
require.NoError(t, te.server.db.Take(&meta).Error)
require.NotEmpty(t, meta.PrevRun, "PrevRun")
require.Empty(t, meta.ExitCode, "ExitCode")
require.NotEmpty(t, meta.LastSuccess, "LastSuccess")
require.NotEmpty(t, meta.NextRun, "NextRun")
}

func TestHandlerRemoveRepo(t *testing.T) {
Expand Down

0 comments on commit 731ec0c

Please sign in to comment.