@@ -10,15 +10,15 @@ import (
10
10
"testing"
11
11
12
12
"github.com/argoproj/argo-workflows/v3/pkg/plugins/executor"
13
- "github.com/magiconair/properties /assert"
13
+ "github.com/stretchr/testify /assert"
14
14
)
15
15
16
16
var (
17
- headerEmpty = map [string ]string {}
18
- headerContentJson = map [string ]string {"Content-Type" : "application/json" }
19
- headerContentEncoded = map [string ]string {"Content-Type" : "application/x-www-form-urlencoded" }
20
- validWorkflowBody = []byte (
21
- `{
17
+ headerEmpty = map [string ]string {}
18
+ headerContentJson = map [string ]string {"Content-Type" : "application/json" }
19
+ headerContentEncoded = map [string ]string {"Content-Type" : "application/x-www-form-urlencoded" }
20
+ validWorkflowBody = []byte (
21
+ `{
22
22
"workflow": {
23
23
"metadata": {
24
24
"name": "test-template"
@@ -39,11 +39,11 @@ var (
39
39
type errReader int
40
40
41
41
func (errReader ) Read (_ []byte ) (n int , err error ) {
42
- return 0 , errors .New ("read error" )
42
+ return 0 , errors .New ("read error" )
43
43
}
44
44
45
45
type executorSpy struct {
46
- Called bool
46
+ Called bool
47
47
}
48
48
49
49
func (e * executorSpy ) Execute (_ executor.ExecuteTemplateArgs ) executor.ExecuteTemplateReply {
@@ -55,16 +55,16 @@ func (e *executorSpy) Execute(_ executor.ExecuteTemplateArgs) executor.ExecuteTe
55
55
func TestArgocdPlugin (t * testing.T ) {
56
56
// test returning correct result based on input
57
57
58
- spy := executorSpy {}
58
+ spy := executorSpy {}
59
59
argocdPlugin := ArgocdPlugin (& spy )
60
60
handler := http .HandlerFunc (argocdPlugin )
61
61
62
62
var failTests = []struct {
63
- name string
64
- body io.Reader
63
+ name string
64
+ body io.Reader
65
65
headers map [string ]string
66
- want string
67
- status int
66
+ want string
67
+ status int
68
68
}{
69
69
{
70
70
name : "fail header content-type is empty" ,
@@ -104,7 +104,7 @@ func TestArgocdPlugin(t *testing.T) {
104
104
}
105
105
response := httptest .NewRecorder ()
106
106
handler .ServeHTTP (response , request )
107
-
107
+
108
108
got := strings .Trim (response .Body .String (), "\n " )
109
109
gotStatus := response .Result ().StatusCode
110
110
@@ -114,18 +114,18 @@ func TestArgocdPlugin(t *testing.T) {
114
114
}
115
115
116
116
var execTests = []struct {
117
- name string
118
- fail bool
117
+ name string
118
+ fail bool
119
119
status int
120
120
}{
121
121
{
122
- name : "exec without fail" ,
123
- fail : false ,
122
+ name : "exec without fail" ,
123
+ fail : false ,
124
124
status : http .StatusOK ,
125
125
},
126
126
{
127
- name : "exec fails" ,
128
- fail : true ,
127
+ name : "exec fails" ,
128
+ fail : true ,
129
129
status : http .StatusInternalServerError ,
130
130
},
131
131
}
@@ -138,7 +138,7 @@ func TestArgocdPlugin(t *testing.T) {
138
138
request .Header .Set ("Content-Type" , "application/json" )
139
139
response := httptest .NewRecorder ()
140
140
handler .ServeHTTP (response , request )
141
-
141
+
142
142
if ! spy .Called && ! tt .fail {
143
143
t .Error ("ApiExecutor was not called" )
144
144
}
@@ -148,6 +148,5 @@ func TestArgocdPlugin(t *testing.T) {
148
148
assert .Equal (t , got , tt .status )
149
149
assert .Equal (t , got , tt .status )
150
150
})
151
- }
151
+ }
152
152
}
153
-
0 commit comments