-
Notifications
You must be signed in to change notification settings - Fork 318
/
Copy pathdisable_test.go
89 lines (65 loc) · 2.21 KB
/
disable_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
80
81
82
83
84
85
86
87
88
89
//go:build integration
// +build integration
package integration
import (
"context"
"fmt"
"strconv"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestDisableK8s(t *testing.T) {
f := newK8sFixture(t, "disable")
f.TiltUp()
ctx, cancel := context.WithTimeout(f.ctx, time.Minute)
defer cancel()
f.WaitForAllPodsReady(ctx, "app=disabletest")
setDisabled(f.fixture, "disabletest", true)
f.WaitUntil(ctx, "pod gone", func() (string, error) {
out, err := f.runCommand("kubectl", "get", "pod", namespaceFlag, "-lapp=disabletest", "--no-headers")
return out.String(), err
}, "No resources found")
setDisabled(f.fixture, "disabletest", false)
f.WaitForAllPodsReady(ctx, "app=disabletest")
}
func TestDisableDC(t *testing.T) {
f := newDCFixture(t, "disable")
f.dockerKillAll("tilt")
f.TiltUp("-f", "Tiltfile.dc")
ctx, cancel := context.WithTimeout(f.ctx, time.Minute)
defer cancel()
f.WaitUntil(ctx, "uiresource available", func() (string, error) {
out, err := f.tilt.Get(ctx, "uiresource")
return string(out), err
}, "disabletest")
f.runOrFail(f.tilt.cmd(ctx, []string{"wait", "--for=condition=Ready", "uiresource/disabletest"}, nil), "wait")
psArgs := []string{
"ps", "-f", "name=disabletest", "--format", "{{.Image}}",
}
out, err := f.dockerCmdOutput(psArgs)
require.NoError(t, err)
require.Contains(t, out, "disabletest")
f.WaitUntil(ctx, "disable configmap available", func() (string, error) {
out, err := f.tilt.Get(ctx, "configmap")
return string(out), err
}, "disabletest-disable")
setDisabled(f.fixture, "disabletest", true)
require.Eventually(t, func() bool {
out, _ := f.dockerCmdOutput(psArgs)
return len(out) == 0
}, time.Minute, 15*time.Millisecond, "dc service stopped")
setDisabled(f.fixture, "disabletest", false)
f.WaitUntil(ctx, "service up", func() (string, error) {
return f.dockerCmdOutput(psArgs)
}, "disabletest")
}
func setDisabled(f *fixture, resourceName string, isDisabled bool) {
err := f.tilt.Patch(
f.ctx,
"configmap",
fmt.Sprintf("{\"data\": {\"isDisabled\": \"%s\"}}", strconv.FormatBool(isDisabled)),
fmt.Sprintf("%s-disable", resourceName),
)
require.NoErrorf(f.t, err, "setting disable state for %s to %v", resourceName, isDisabled)
}