-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdebug_test.go
More file actions
42 lines (35 loc) · 867 Bytes
/
debug_test.go
File metadata and controls
42 lines (35 loc) · 867 Bytes
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
package validation
import (
"strings"
"testing"
)
func TestDiagnosticLineNumbers(t *testing.T) {
yaml := `yapi: v1
# Comment
url: http://example.com/graphql
graphql: query { foo }
body:
key: value`
a, err := Analyze(yaml, AnalyzeOptions{})
if err != nil {
t.Fatalf("Analyze error: %v", err)
}
// Find the graphql+body conflict diagnostic
var graphqlDiag *Diagnostic
for i := range a.Diagnostics {
if strings.Contains(a.Diagnostics[i].Message, "cannot be used with") {
graphqlDiag = &a.Diagnostics[i]
break
}
}
if graphqlDiag == nil {
t.Fatal("expected graphql+body conflict diagnostic")
}
// body: is on line 5 (0-indexed)
if graphqlDiag.Line != 5 {
t.Errorf("expected body diagnostic on line 5, got %d", graphqlDiag.Line)
}
if graphqlDiag.Field != "body" {
t.Errorf("expected field 'body', got %q", graphqlDiag.Field)
}
}