-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain_test.go
More file actions
90 lines (79 loc) · 2.77 KB
/
main_test.go
File metadata and controls
90 lines (79 loc) · 2.77 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
81
82
83
84
85
86
87
88
89
90
package main
import (
"bytes"
"testing"
"github.com/CustomResourceDefinition/catalog/internal/command"
"github.com/stretchr/testify/assert"
)
var logger = bytes.NewBuffer([]byte{})
func TestNoArgumentsRunning(t *testing.T) {
args := []string{"bin"}
err := run(args, logger)
assert.ErrorIs(t, err, command.ErrNoArguments)
}
func TestNoArgumentsParsing(t *testing.T) {
args := []string{"bin"}
_, err := parse(args, logger)
assert.ErrorIs(t, err, command.ErrNoArguments)
}
func TestUnknownCommandParsing(t *testing.T) {
tests := [][]string{
{"horse"},
{"monkey"},
{"monkey", "horse"},
}
for _, test := range tests {
args := []string{"bin"}
args = append(args, test...)
_, err := parse(args, logger)
assert.ErrorIs(t, err, command.ErrUnknownCommand)
}
}
func TestCompareCommandParsingIncorrectFlags(t *testing.T) {
tests := [][]string{
{"bin", commandCompare, "--not-a-flag"},
{"bin", commandUpdate, "--not-a-flag"},
{"bin", commandVerify, "--not-a-flag"},
}
for i, test := range tests {
cmd, err := parse(test, logger)
assert.NotNil(t, err, "index %d failed", i)
assert.Nil(t, cmd, "index %d failed", i)
}
}
func TestCompareCommandParsing(t *testing.T) {
tests := [][]string{
{"bin", commandCompare},
{"bin", commandUpdate},
{"bin", commandVerify},
}
for i, test := range tests {
cmd, err := parse(test, logger)
assert.Nil(t, err, "index %d failed", i)
assert.NotNil(t, cmd, "index %d failed", i)
}
}
func TestCommandRunningInvalidConfiguration(t *testing.T) {
tests := [][]string{
{"bin", commandCompare},
{"bin", commandCompare, "--current", "."},
{"bin", commandCompare, "--datreeio", "."},
{"bin", commandCompare, "--current", ".", "--datreeio", "."},
{"bin", commandUpdate},
{"bin", commandUpdate, "--configuration", "testdata/schema.json"},
{"bin", commandUpdate, "--output", "testdata"},
{"bin", commandUpdate, "--definitions", "testdata"},
{"bin", commandUpdate, "--configuration", "testdata/does-not-exist.json", "--output", "testdata", "--definitions", "testdata"},
{"bin", commandUpdate, "--configuration", "testdata/schema.json", "--output", "testdata/does-not-exist", "--definitions", "testdata"},
{"bin", commandUpdate, "--configuration", "testdata/schema.json", "--output", "testdata", "--definitions", "testdata/does-not-exist"},
{"bin", commandVerify},
{"bin", commandVerify, "--schema", "testdata/schema.json"},
{"bin", commandVerify, "--file", "testdata/schema.json"},
{"bin", commandVerify, "--schema", "testdata/does-not-exist.json", "--file", "testdata/schema.json"},
{"bin", commandVerify, "--schema", "testdata/schema.json", "--file", "testdata/does-not-exist.json"},
}
for i, test := range tests {
err := run(test, logger)
assert.ErrorIs(t, err, command.ErrInvalidConfiguration, "index %d failed", i)
}
}