-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathembedded_ui_integration_test.go
79 lines (62 loc) · 1.77 KB
/
embedded_ui_integration_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//go:build integration
// +build integration
/*
2021 © Postgres.ai
*/
package embeddedui
import (
"context"
"testing"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/client"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/postgres-ai/database-lab/v3/internal/provision/runners"
"gitlab.com/postgres-ai/database-lab/v3/internal/retrieval/engine/postgres/tools"
"gitlab.com/postgres-ai/database-lab/v3/pkg/config/global"
"gitlab.com/postgres-ai/database-lab/v3/pkg/util/networks"
)
func TestStartExistingContainer(t *testing.T) {
t.Parallel()
docker, err := client.NewClientWithOpts(client.FromEnv)
require.NoError(t, err)
engProps := global.EngineProps{
InstanceID: "testuistart",
}
embeddedUI := New(
Config{
// "mock" UI image
DockerImage: "alpine:3.19",
},
engProps,
runners.NewLocalRunner(false),
docker,
)
ctx := context.TODO()
networks.Setup(ctx, docker, engProps.InstanceID, getEmbeddedUIName(engProps.InstanceID))
// clean test UI container
defer tools.RemoveContainer(ctx, docker, getEmbeddedUIName(engProps.InstanceID), 30)
// start UI container
err = embeddedUI.Run(ctx)
require.NoError(t, err)
// explicitly stop container
tools.StopContainer(ctx, docker, getEmbeddedUIName(engProps.InstanceID), 30)
// start UI container back
err = embeddedUI.Run(ctx)
require.NoError(t, err)
// list containers
filterArgs := filters.NewArgs()
filterArgs.Add("name", getEmbeddedUIName(engProps.InstanceID))
list, err := docker.ContainerList(
ctx,
types.ContainerListOptions{
All: true,
Filters: filterArgs,
},
)
require.NoError(t, err)
assert.NotEmpty(t, list)
// initial container
assert.Equal(t, "running", list[0].State)
}