-
Notifications
You must be signed in to change notification settings - Fork 313
/
Copy pathcrd_test.go
73 lines (57 loc) · 2.03 KB
/
crd_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
//go:build integration
// +build integration
package integration
import (
"context"
"io/ioutil"
"path/filepath"
"regexp"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCRD(t *testing.T) {
f := newK8sFixture(t, "crd")
f.TiltUp()
ctx, cancel := context.WithTimeout(f.ctx, time.Minute)
defer cancel()
f.WaitUntil(ctx, "Waiting for UM to show up", func() (string, error) {
out, _ := f.runCommand("kubectl", "get", "um", namespaceFlag)
return out.String(), nil
}, "bobo")
out, err := f.runCommand("kubectl", "get", "um", namespaceFlag, "-o=yaml")
require.NoError(t, err)
contents := out.String()
// Make sure image injection didn't replace the name
// or the non-image field, but did replace the image field.
assert.Contains(t, contents, "name: bobo\n")
assert.Contains(t, contents, "nonImage: bobo\n")
assert.NotContains(t, contents, "image: bobo\n")
assert.Regexp(t, regexp.MustCompile("imagePullPolicy: (IfNotPresent|Never)\n"), contents)
}
// Make sure that running 'tilt down' with no resources installed
// yet handles 'not found' correctly
func TestCRDNotFound(t *testing.T) {
f := newK8sFixture(t, "crd")
err := f.tilt.Down(f.ctx, ioutil.Discard)
require.NoError(t, err)
}
// Make sure that running 'tilt down' tears down the CRD
// even when the CR doesn't exist.
func TestCRDPartialNotFound(t *testing.T) {
f := newK8sFixture(t, "crd")
out, err := f.runCommand("kubectl", "apply", "-f", filepath.Join(f.dir, "crd.yaml"))
assert.NoError(t, err)
assert.Contains(t, out.String(), "uselessmachines.tilt.dev created")
_, err = f.runCommand("kubectl", "get", "crd", "uselessmachines.tilt.dev")
assert.NoError(t, err)
err = f.tilt.Down(f.ctx, ioutil.Discard)
require.NoError(t, err)
// Make sure the crds were deleted.
assert.Eventually(t, func() bool {
out, err := f.runCommand("kubectl", "get", "crd", "uselessmachines.tilt.dev")
return err != nil && strings.Contains(out.String(), `"uselessmachines.tilt.dev" not found`)
}, 3*time.Second, time.Second)
}