-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy patherrors_test.go
More file actions
77 lines (66 loc) · 1.82 KB
/
errors_test.go
File metadata and controls
77 lines (66 loc) · 1.82 KB
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
72
73
74
75
76
77
package publiccode
import (
"encoding/json"
"testing"
)
func TestParseErrorError(t *testing.T) {
e := ParseError{Reason: "something went wrong"}
if e.Error() != "something went wrong" {
t.Errorf("unexpected: %q", e.Error())
}
}
func TestValidationErrorErrorEmptyKey(t *testing.T) {
e := ValidationError{Key: "", Description: "bad field", Line: 1, Column: 2}
got := e.Error()
want := "publiccode.yml:1:2: error: bad field"
if got != want {
t.Errorf("got %q, want %q", got, want)
}
}
func TestValidationErrorErrorWithKey(t *testing.T) {
e := ValidationError{Key: "foo", Description: "bad field", Line: 3, Column: 4}
got := e.Error()
want := "publiccode.yml:3:4: error: foo: bad field"
if got != want {
t.Errorf("got %q, want %q", got, want)
}
}
func TestValidationErrorMarshalJSON(t *testing.T) {
e := ValidationError{Key: "foo", Description: "bad", Line: 1, Column: 1}
b, err := e.MarshalJSON()
if err != nil {
t.Fatal(err)
}
var m map[string]interface{}
if err := json.Unmarshal(b, &m); err != nil {
t.Fatal(err)
}
if m["type"] != "error" {
t.Errorf("expected type=error, got %v", m["type"])
}
if m["key"] != "foo" {
t.Errorf("expected key=foo, got %v", m["key"])
}
}
func TestValidationWarningMarshalJSON(t *testing.T) {
e := ValidationWarning{Key: "foo", Description: "minor", Line: 2, Column: 3}
b, err := e.MarshalJSON()
if err != nil {
t.Fatal(err)
}
var m map[string]interface{}
if err := json.Unmarshal(b, &m); err != nil {
t.Fatal(err)
}
if m["type"] != "warning" {
t.Errorf("expected type=warning, got %v", m["type"])
}
}
func TestValidationWarningErrorEmptyKey(t *testing.T) {
e := ValidationWarning{Key: "", Description: "minor issue", Line: 5, Column: 6}
got := e.Error()
want := "publiccode.yml:5:6: warning: minor issue"
if got != want {
t.Errorf("got %q, want %q", got, want)
}
}