Skip to content

Commit f76d421

Browse files
committed
added working failing tests
1 parent fd05d9e commit f76d421

File tree

2 files changed

+28
-57
lines changed

2 files changed

+28
-57
lines changed

internal/argocd-plugin/plugin.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,13 @@ func ArgocdPlugin(kubeClient kubernetes.Interface, namespace string) func(w http
3535
return
3636
}
3737

38-
log.Printf("Recieved body: %v", string(body))
39-
4038
args := executor.ExecuteTemplateArgs{}
4139
if err := json.Unmarshal(body, &args); err != nil {
4240
log.Print(ErrMarshallingBody)
4341
http.Error(w, ErrMarshallingBody.Error(), http.StatusBadRequest)
4442
return
4543
}
4644

47-
log.Printf("Received args: %v", args)
48-
4945
// channel, text, err := parsPayload(args)
5046
// if err != nil {
5147
// w.WriteHeader(http.StatusBadRequest)

internal/argocd-plugin/plugin_test.go

Lines changed: 28 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,6 @@ func TestArgocdPlugin(t *testing.T) {
6868
want: ErrMarshallingBody.Error(),
6969
status: http.StatusBadRequest,
7070
},
71-
{
72-
name: "succeed marshalling body",
73-
body: bytes.NewReader([]byte(`"lol": "test"`)),
74-
headers: headerContentJson,
75-
want: "Success",
76-
status: http.StatusBadRequest,
77-
},
7871
}
7972

8073
for _, tt := range failTests {
@@ -94,49 +87,31 @@ func TestArgocdPlugin(t *testing.T) {
9487
})
9588
}
9689

97-
}
98-
99-
// var tests = []struct {
100-
// name string
101-
// request executor.ExecuteTemplateArgs
102-
// want string
103-
// status int
104-
// }{
105-
// {
106-
// "parse body and return success",
107-
// executor.ExecuteTemplateArgs{
108-
// Workflow: &executor.Workflow{
109-
// ObjectMeta: executor.ObjectMeta{Name: "workflow"},
110-
// },
111-
// Template: &v1alpha1.Template{
112-
// Name: "my-tmpl",
113-
// Plugin: &v1alpha1.Plugin{
114-
// Object: v1alpha1.Object{Value: json.RawMessage(
115-
// `{
116-
// "argocd": {}
117-
// }`)},
118-
// },
119-
// },
120-
// },
121-
// `{"node": { "phase": "Succeeded", "message": "Succeeded"}}`,
122-
// http.StatusOK,
123-
// },
124-
// }
125-
126-
// kubeClient := fake.NewSimpleClientset()
127-
// argocdPlugin := ArgocdPlugin(kubeClient, "argo")
128-
// handler := http.HandlerFunc(argocdPlugin)
129-
130-
// for _, tt := range tests {
131-
// t.Run(tt.name, func(t *testing.T) {
132-
// body, _ := json.Marshal(&tt.request)
133-
// request, _ := http.NewRequest(http.MethodPost, "/api/v1/template.execute", bytes.NewReader(body))
134-
// response := httptest.NewRecorder()
135-
136-
// handler.ServeHTTP(response, request)
137-
138-
139-
// common.AssertResponseBody(t, response.Body.String(), tt.want)
140-
// common.AssertStatus(t, response.Code, tt.status)
141-
// })
142-
// }
90+
t.Run("succeed marshalling body and execute the request", func(t *testing.T) {
91+
body := bytes.NewReader([]byte(
92+
`{
93+
"workflow": {
94+
"metadata": {
95+
"name": "test-template"
96+
}
97+
},
98+
"template": {
99+
"name": "argocd-plugin",
100+
"inputs": {},
101+
"outputs": {},
102+
"plugin": {
103+
"argocd": {
104+
}
105+
}
106+
}
107+
}`))
108+
request, _ := http.NewRequest(http.MethodPost, "/api/v1/template.execute", body)
109+
request.Header.Set("Content-Type", "application/json")
110+
response := httptest.NewRecorder()
111+
handler.ServeHTTP(response, request)
112+
113+
got := response.Code
114+
115+
common.AssertStatus(t, got, http.StatusOK)
116+
})
117+
}

0 commit comments

Comments
 (0)