-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_schema_bundle_test.go
More file actions
100 lines (91 loc) · 3.67 KB
/
json_schema_bundle_test.go
File metadata and controls
100 lines (91 loc) · 3.67 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
import (
"github.com/xeipuuv/gojsonreference"
"testing"
)
var ref, _ = gojsonreference.NewJsonReference("/foo/bar/baz.json")
func TestNewJsonSchemaBundle(t *testing.T) {
noIdentifiedJsonSchemaBundle := NewJsonSchemaBundle(&ref, JsonSchema{Title: "NoIdentified"}, false)
if noIdentifiedJsonSchemaBundle.Name != "baz" {
t.Errorf("bundle name should be 'baz'. NAME: %S", noIdentifiedJsonSchemaBundle.Name)
}
if noIdentifiedJsonSchemaBundle.Ref != &ref {
t.Error("mismatched json reference pointer")
}
if noIdentifiedJsonSchemaBundle.Schema.Title != "NoIdentified" {
t.Error("json schema title should be 'NoIdentified'. TITLE: %s", noIdentifiedJsonSchemaBundle.Schema.Title)
}
if noIdentifiedJsonSchemaBundle.IsReferred != false {
t.Error("is referred should be false")
}
if noIdentifiedJsonSchemaBundle.HasParent != false {
t.Error("has parent should be false")
}
identifiedJsonSchemaBundle := NewJsonSchemaBundle(&ref, JsonSchema{Id: "Identified"}, false)
if identifiedJsonSchemaBundle.Name != "Identified" {
t.Errorf("bundle name should be 'Identified'. NAME: %S", identifiedJsonSchemaBundle.Name)
}
if identifiedJsonSchemaBundle.Schema.Id != "Identified" {
t.Error("json schema Id should be 'Identified'")
}
}
func TestNewNamedChildJsonSchemaBundle(t *testing.T) {
rootJsonSchemaBundle := NewJsonSchemaBundle(&ref, JsonSchema{Id: "Root"}, false)
bundle := NewNamedChildJsonSchemaBundle(rootJsonSchemaBundle, "Child", JsonSchema{Id: "ChildSchema"})
if bundle.Name != "Child" {
t.Errorf("bundle name should be 'Child'. NAME: %s", bundle.Name)
}
if bundle.Schema.Id != "ChildSchema" {
t.Errorf("json schema id should be 'Child'. ID: %s", bundle.Schema.Id)
}
if bundle.IsReferred != rootJsonSchemaBundle.IsReferred {
t.Error("is referred should be same to parent value")
}
if bundle.HasParent != true {
t.Error("has parent should be true")
}
}
func TestNewChildJsonSchemaBundle(t *testing.T) {
rootJsonSchemaBundle := NewJsonSchemaBundle(&ref, JsonSchema{Id: "Root"}, false)
bundle := NewChildJsonSchemaBundle(rootJsonSchemaBundle, JsonSchema{Id: "Child"})
if bundle.Name != "Root" {
t.Errorf("bundle name should be 'Root'. NAME: %s", bundle.Name)
}
if bundle.Schema.Id != "Child" {
t.Errorf("json schema id should be 'Child'. ID: %s", bundle.Schema.Id)
}
if bundle.IsReferred != rootJsonSchemaBundle.IsReferred {
t.Error("is referred should be same to parent value")
}
if bundle.HasParent != true {
t.Error("has parent should be true")
}
}
func TestJsonSchemaBundle_GetRelativeJsonReference(t *testing.T) {
rootJsonSchemaBundle := NewJsonSchemaBundle(&ref, JsonSchema{Id: "Root"}, false)
// relative path
ref, err := rootJsonSchemaBundle.GetRelativeJsonReference("./hoge/fuga/piyo.json")
if err != nil {
t.Fatal(err)
}
if ref.GetUrl().Path != "/foo/bar/hoge/fuga/piyo.json" {
t.Errorf("mismatched ref url. URL: %s", ref.GetUrl().Path)
}
// absolute path
ref, err = rootJsonSchemaBundle.GetRelativeJsonReference("/hoge/fuga/piyo.json")
if ref.GetUrl().Path != "/hoge/fuga/piyo.json" {
t.Errorf("mismatched ref url. URL: %s", ref.GetUrl().Path)
}
}
func TestJsonSchemaBundle_IsSameRef(t *testing.T) {
rootJsonSchemaBundle := NewJsonSchemaBundle(&ref, JsonSchema{Id: "Root"}, false)
childJsonSchemaBundle := NewChildJsonSchemaBundle(rootJsonSchemaBundle, JsonSchema{Id: "Child"})
if rootJsonSchemaBundle.IsSameRef(childJsonSchemaBundle) != true {
t.Error("is same ref should be true")
}
otherRef, _ := gojsonreference.NewJsonReference("/other/bundle.json")
otherJsonSchemaBundle := NewJsonSchemaBundle(&otherRef, JsonSchema{}, false)
if rootJsonSchemaBundle.IsSameRef(otherJsonSchemaBundle) != false {
t.Error("is same ref should be false")
}
}