This repository has been archived by the owner on Sep 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration_test.go
77 lines (68 loc) · 1.94 KB
/
integration_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
package main
import (
"io"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
type integrationTest struct {
name string
expectPanic bool
flags []string
expectedOutput string
}
func TestRun(t *testing.T) {
tests := []integrationTest{
{
name: "Validate flux2-install",
expectPanic: false,
flags: []string{"-f", "tests/flux2-install.yaml", "-l", "debug"},
expectedOutput: "total: 38, Invalid: 0\n",
},
{
name: "Validate invalid-metadata",
expectPanic: true,
flags: []string{"-f", "tests/invalid-metadata.yaml", "-l", "debug"},
expectedOutput: "total: 4, Invalid: 2\n",
},
{
name: "Validate invalid-metadata but with allow-failure",
expectPanic: false,
flags: []string{"-f", "tests/invalid-metadata.yaml", "-l", "debug", "--allow-failure=true"},
expectedOutput: "total: 4, Invalid: 2\n",
},
{
name: "Validate without-namespace",
expectPanic: false,
flags: []string{"-f", "tests/without-namespace.yaml", "-l", "debug"},
expectedOutput: "total: 2, Invalid: 0\n",
},
{
name: "Validate without-namespace but with --skip-auto-namespace",
expectPanic: true,
flags: []string{"-f", "tests/without-namespace.yaml", "-l", "debug", "--skip-auto-namespace=true"},
expectedOutput: "total: 1, Invalid: 1\n",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
executeIntegrationTest(t, test)
})
}
}
func executeIntegrationTest(t *testing.T, test integrationTest) {
f, err := os.CreateTemp(os.TempDir(), "yakmv-testing")
assert.NoError(t, err)
output = f
os.Args = append([]string{"yakmv"}, test.flags...)
if test.expectPanic {
assert.Panics(t, func() { main() })
} else {
main()
}
_, err = f.Seek(0, 0)
assert.NoError(t, err)
b, err := io.ReadAll(f)
assert.NoError(t, err)
assert.Equal(t, test.expectedOutput, string(b))
}