-
Notifications
You must be signed in to change notification settings - Fork 150
Expand file tree
/
Copy pathsetup_test.go
More file actions
80 lines (64 loc) · 1.84 KB
/
setup_test.go
File metadata and controls
80 lines (64 loc) · 1.84 KB
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
80
package dockerutil_test
import (
"context"
"fmt"
"testing"
volumetypes "github.com/docker/docker/api/types/volume"
"github.com/moby/moby/errdefs"
"github.com/stretchr/testify/require"
"github.com/strangelove-ventures/interchaintest/v8/dockerutil"
"github.com/strangelove-ventures/interchaintest/v8/mocktesting"
)
func TestDockerSetup_KeepVolumes(t *testing.T) {
if testing.Short() {
t.Skip("skipping due to short mode")
}
cli, _ := dockerutil.DockerSetup(t)
origKeep := dockerutil.KeepVolumesOnFailure
defer func() {
dockerutil.KeepVolumesOnFailure = origKeep
}()
ctx := context.Background()
for _, tc := range []struct {
keep bool
passed bool
volumeKept bool
}{
{keep: false, passed: false, volumeKept: false},
{keep: true, passed: false, volumeKept: true},
{keep: false, passed: true, volumeKept: false},
{keep: true, passed: true, volumeKept: false},
} {
state := "failed"
if tc.passed {
state = "passed"
}
testName := fmt.Sprintf("keep=%t, test %s", tc.keep, state)
t.Run(testName, func(t *testing.T) {
dockerutil.KeepVolumesOnFailure = tc.keep
mt := mocktesting.NewT(t.Name())
var volumeName string
mt.Simulate(func() {
cli, _ := dockerutil.DockerSetup(mt)
v, err := cli.VolumeCreate(ctx, volumetypes.CreateOptions{
Labels: map[string]string{dockerutil.CleanupLabel: mt.Name()},
})
require.NoError(t, err)
volumeName = v.Name
if !tc.passed {
mt.Fail()
}
})
require.Equal(t, !tc.passed, mt.Failed())
_, err := cli.VolumeInspect(ctx, volumeName)
if !tc.volumeKept {
require.Truef(t, errdefs.IsNotFound(err), "expected not found error, got %v", err)
return
}
require.NoError(t, err)
if err := cli.VolumeRemove(ctx, volumeName, true); err != nil {
t.Logf("failed to remove volume %s: %v", volumeName, err)
}
})
}
}