-
Notifications
You must be signed in to change notification settings - Fork 5
/
app_test.go
72 lines (57 loc) · 1.45 KB
/
app_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
package main
import (
"bytes"
"fmt"
"io/ioutil"
"k8s.io/client-go/kubernetes/fake"
"k8s.io/kubernetes/pkg/controller/testutil"
"github.com/stretchr/testify/require"
"testing"
)
func TestAppRunOnce(t *testing.T) {
cmd := newCmd()
buf := new(bytes.Buffer)
cmd.SetOutput(buf)
testgolden := testGoldenFileName(t)
var testout string
if *update {
testout = testgolden
} else {
testoutfile, err := ioutil.TempFile("", "testout")
require.NoError(t, err)
testout = testoutfile.Name()
defer UnlinkQuietly(testout)
}
err := cmd.ParseFlags([]string{
"--once",
fmt.Sprintf("--template=%s:%s", testTemplateName(t), testout),
})
require.NoError(t, err)
cfg, err := newConfig(cmd)
require.NoError(t, err)
pod := testutil.NewPod("pod1", "host1")
fakeClient := fake.NewSimpleClientset(pod)
stopCh := make(chan struct{})
doneCh := make(chan struct{})
defer close(stopCh)
defer close(doneCh)
tc, err := newClient(fakeClient, stopCh, false)
require.NoError(t, err)
dm := newDependencyManager(tc)
templates, err := newTemplatesFromConfig(cfg, dm)
require.NoError(t, err)
app := &App{
stopCh: stopCh,
doneCh: doneCh,
dm: dm,
templates: templates,
dryRun: cfg.DryRun,
updatePeriod: cfg.PollPeriod,
}
app.RunOnce()
actual, err := ioutil.ReadFile(testout)
require.NoError(t, err)
expected, err := ioutil.ReadFile(testgolden)
require.NoError(t, err)
require.Equal(t, string(expected), string(actual))
}