|
1
|
|
|
package application |
|
2
|
|
|
|
|
3
|
|
|
import ( |
|
4
|
|
|
"testing" |
|
5
|
|
|
|
|
6
|
|
|
"github.com/stretchr/testify/assert" |
|
7
|
|
|
) |
|
8
|
|
|
|
|
9
|
|
|
const ( |
|
10
|
|
|
testSpecificationURL = "./../../test/resources/openapi-files/ValueGeneration.yaml" |
|
11
|
|
|
testConfigFilename = "./../../test/resources/config.yaml" |
|
12
|
|
|
) |
|
13
|
|
|
|
|
14
|
|
|
func TestExecute_ValidArguments_NoError(t *testing.T) { |
|
15
|
|
|
tests := []struct { |
|
16
|
|
|
name string |
|
17
|
|
|
arguments []string |
|
18
|
|
|
}{ |
|
19
|
|
|
{ |
|
20
|
|
|
"serve command with short url", |
|
21
|
|
|
[]string{ |
|
22
|
|
|
"serve", |
|
23
|
|
|
"-u", |
|
24
|
|
|
testSpecificationURL, |
|
25
|
|
|
}, |
|
26
|
|
|
}, |
|
27
|
|
|
{ |
|
28
|
|
|
"serve command with long url", |
|
29
|
|
|
[]string{ |
|
30
|
|
|
"serve", |
|
31
|
|
|
"--specification-url", |
|
32
|
|
|
testSpecificationURL, |
|
33
|
|
|
}, |
|
34
|
|
|
}, |
|
35
|
|
|
{ |
|
36
|
|
|
"serve command with url from config (short)", |
|
37
|
|
|
[]string{ |
|
38
|
|
|
"serve", |
|
39
|
|
|
"-c", |
|
40
|
|
|
testConfigFilename, |
|
41
|
|
|
}, |
|
42
|
|
|
}, |
|
43
|
|
|
{ |
|
44
|
|
|
"serve command with url from config (long)", |
|
45
|
|
|
[]string{ |
|
46
|
|
|
"serve", |
|
47
|
|
|
"--configuration", |
|
48
|
|
|
testConfigFilename, |
|
49
|
|
|
}, |
|
50
|
|
|
}, |
|
51
|
|
|
{ |
|
52
|
|
|
"validate command with short url", |
|
53
|
|
|
[]string{ |
|
54
|
|
|
"validate", |
|
55
|
|
|
"-u", |
|
56
|
|
|
testSpecificationURL, |
|
57
|
|
|
}, |
|
58
|
|
|
}, |
|
59
|
|
|
{ |
|
60
|
|
|
"validate command with long url", |
|
61
|
|
|
[]string{ |
|
62
|
|
|
"validate", |
|
63
|
|
|
"--specification-url", |
|
64
|
|
|
testSpecificationURL, |
|
65
|
|
|
}, |
|
66
|
|
|
}, |
|
67
|
|
|
{ |
|
68
|
|
|
"help command with short argument", |
|
69
|
|
|
[]string{"-h"}, |
|
70
|
|
|
}, |
|
71
|
|
|
{ |
|
72
|
|
|
"help command with long argument", |
|
73
|
|
|
[]string{"--help"}, |
|
74
|
|
|
}, |
|
75
|
|
|
} |
|
76
|
|
|
for _, test := range tests { |
|
77
|
|
|
t.Run(test.name, func(t *testing.T) { |
|
78
|
|
|
args := append(test.arguments, "--dry-run") |
|
79
|
|
|
|
|
80
|
|
|
err := Execute(Arguments(args)) |
|
81
|
|
|
|
|
82
|
|
|
assert.NoError(t, err) |
|
83
|
|
|
}) |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
func TestExecute_InvalidArguments_Error(t *testing.T) { |
|
88
|
|
|
tests := []struct { |
|
89
|
|
|
name string |
|
90
|
|
|
arguments []string |
|
91
|
|
|
error string |
|
92
|
|
|
}{ |
|
93
|
|
|
{ |
|
94
|
|
|
"no specification url", |
|
95
|
|
|
[]string{"serve"}, |
|
96
|
|
|
"failed to load OpenAPI specification from '': open : no such file or directory", |
|
97
|
|
|
}, |
|
98
|
|
|
} |
|
99
|
|
|
for _, test := range tests { |
|
100
|
|
|
t.Run(test.name, func(t *testing.T) { |
|
101
|
|
|
args := append(test.arguments, "--dry-run") |
|
102
|
|
|
|
|
103
|
|
|
err := Execute(Arguments(args)) |
|
104
|
|
|
|
|
105
|
|
|
assert.EqualError(t, err, test.error) |
|
106
|
|
|
}) |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|