-
Notifications
You must be signed in to change notification settings - Fork 1
/
start_stop_test.go
66 lines (47 loc) · 1.8 KB
/
start_stop_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
package test
import (
"context"
"testing"
"time"
"github.com/docker/docker/api/types"
docker "github.com/docker/docker/client"
"github.com/jlevesy/sind/pkg/sind"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSindCanStopAndStartACluster(t *testing.T) {
ctx := context.Background()
hostClient, err := docker.NewClientWithOpts(docker.FromEnv, docker.WithAPIVersionNegotiation())
require.NoError(t, err)
params := sind.ClusterConfiguration{
ClusterName: "test_create",
NetworkName: "test_create",
Managers: 3,
Workers: 4,
}
require.NoError(t, sind.CreateCluster(ctx, hostClient, params))
defer func() {
require.NoError(t, sind.DeleteCluster(ctx, hostClient, params.ClusterName))
}()
require.NoError(t, sind.StopCluster(ctx, hostClient, params.ClusterName))
clusterInfos, err := sind.InspectCluster(ctx, hostClient, params.ClusterName)
require.NoError(t, err)
for _, node := range clusterInfos.Nodes {
assert.Equal(t, "exited", node.State)
}
require.NoError(t, sind.StartCluster(ctx, hostClient, params.ClusterName))
clusterInfos, err = sind.InspectCluster(ctx, hostClient, params.ClusterName)
require.NoError(t, err)
for _, node := range clusterInfos.Nodes {
assert.Equal(t, "running", node.State)
}
swarmHost, err := sind.ClusterHost(ctx, hostClient, params.ClusterName)
require.NoError(t, err)
swarmClient, err := docker.NewClientWithOpts(docker.WithHost(swarmHost), docker.WithAPIVersionNegotiation())
require.NoError(t, err)
var info types.Info
require.NoError(t, retry(30, time.Second, func() error { info, err = swarmClient.Info(ctx); return err }))
require.True(t, info.Swarm.ControlAvailable)
assert.EqualValues(t, params.Managers, info.Swarm.Managers)
assert.EqualValues(t, params.Workers, info.Swarm.Nodes-info.Swarm.Managers)
}