-
Notifications
You must be signed in to change notification settings - Fork 0
/
preflight_test.go
57 lines (49 loc) · 1.32 KB
/
preflight_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
package main
import (
"testing"
)
func TestPreflightAsset(t *testing.T) {
//byte slices
invalidUtf8 := []byte{0xff, 0xfe, 0xfd}
validJSON := []byte("{ \"foo\": [\"bar\", \"barfoo\"] }")
invalidJSON := []byte("foo { \"foo\": [\"bar\", \"barfoo\"] } foo")
validYaml := []byte("\"foo\": \"bar\"")
invalidYaml := []byte("\"foo\":foo:bar: \"bar\"")
multilineYaml := []byte(`"foo":
- "bar"
- "foobar"
- "boofar"
- "roobar"
`)
multilineYamlConverted := []byte("{\"foo\":[\"bar\",\"foobar\",\"boofar\",\"roobar\"]}")
//expect error
err := preflightAsset(&invalidUtf8)
if err == nil {
t.Error("Must reject invalid UTF8")
}
err = preflightAsset(&invalidJSON)
if err == nil {
t.Error("Must reject invalid JSON")
}
err = preflightAsset(&invalidYaml)
if err == nil {
t.Error("Must reject invalid YAML")
}
//expect success
err = preflightAsset(&validYaml)
if err != nil {
t.Errorf("Must accept valid YAML: %v", err)
}
err = preflightAsset(&validJSON)
if err != nil {
t.Errorf("Must accept valid JSON: %v", err)
}
//in-place conversion must match predefined result
err = preflightAsset(&multilineYaml)
if err != nil {
t.Errorf("Must accept valid multiline YAML: %v", err)
}
if string(multilineYaml) != string(multilineYamlConverted) {
t.Errorf("Expected %s to match %s", multilineYaml, multilineYamlConverted)
}
}