forked from xanzy/go-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate_test.go
71 lines (64 loc) · 1.34 KB
/
validate_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
package gitlab
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestValidate(t *testing.T) {
testCases := []struct {
description string
content string
response string
want *LintResult
}{
{
description: "valid",
content: `
build1:
stage: build
script:
- echo "Do your build here"`,
response: `{
"status": "valid",
"errors": []
}`,
want: &LintResult{
Status: "valid",
Errors: []string{},
},
},
{
description: "invalid",
content: `
build1:
- echo "Do your build here"`,
response: `{
"status": "invalid",
"errors": ["error message when content is invalid"]
}`,
want: &LintResult{
Status: "invalid",
Errors: []string{"error message when content is invalid"},
},
},
}
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/ci/lint", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
fmt.Fprintf(w, tc.response)
})
got, _, err := client.Validate.Lint(tc.content)
if err != nil {
t.Errorf("Validate returned error: %v", err)
}
want := tc.want
if !reflect.DeepEqual(got, want) {
t.Errorf("Validate returned \ngot:\n%v\nwant:\n%v", Stringify(got), Stringify(want))
}
})
}
}