...
1 package api
2
3 import (
4 "testing"
5
6 "github.com/stretchr/testify/assert"
7 )
8
9 func TestGraphQLErrorMatch(t *testing.T) {
10 tests := []struct {
11 name string
12 error GraphQLError
13 kind string
14 path string
15 wantMatch bool
16 }{
17 {
18 name: "matches path and type",
19 error: GraphQLError{Errors: []GraphQLErrorItem{
20 {Path: []interface{}{"repository", "issue"}, Type: "NOT_FOUND"},
21 }},
22 kind: "NOT_FOUND",
23 path: "repository.issue",
24 wantMatch: true,
25 },
26 {
27 name: "matches base path and type",
28 error: GraphQLError{Errors: []GraphQLErrorItem{
29 {Path: []interface{}{"repository", "issue"}, Type: "NOT_FOUND"},
30 }},
31 kind: "NOT_FOUND",
32 path: "repository.",
33 wantMatch: true,
34 },
35 {
36 name: "does not match path but matches type",
37 error: GraphQLError{Errors: []GraphQLErrorItem{
38 {Path: []interface{}{"repository", "issue"}, Type: "NOT_FOUND"},
39 }},
40 kind: "NOT_FOUND",
41 path: "label.title",
42 wantMatch: false,
43 },
44 {
45 name: "matches path but not type",
46 error: GraphQLError{Errors: []GraphQLErrorItem{
47 {Path: []interface{}{"repository", "issue"}, Type: "NOT_FOUND"},
48 }},
49 kind: "UNKNOWN",
50 path: "repository.issue",
51 wantMatch: false,
52 },
53 }
54
55 for _, tt := range tests {
56 t.Run(tt.name, func(t *testing.T) {
57 assert.Equal(t, tt.wantMatch, tt.error.Match(tt.kind, tt.path))
58 })
59 }
60 }
61
View as plain text