forked from hooklift/gowsdl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
location_test.go
147 lines (135 loc) · 3.25 KB
/
location_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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package gowsdl
import (
"os"
"path/filepath"
"testing"
)
func TestLocation_ParseLocation_URL(t *testing.T) {
r, err := ParseLocation("http://example.org/my.wsdl")
if err != nil {
t.Fatal(err)
}
if !r.isURL() || r.isFile() {
t.Error("Location should be a URL type")
}
if r.String() != "http://example.org/my.wsdl" {
t.Error("got " + r.String() + " wanted " + "http://example.org/my.wsdl")
}
}
func TestLocation_Parse_URL(t *testing.T) {
tests := []struct {
name string
ref string
expected string
}{
{"http://example.org/my.wsdl", "some.xsd", "http://example.org/some.xsd"},
{"http://example.org/folder/my.wsdl", "some.xsd", "http://example.org/folder/some.xsd"},
{"http://example.org/folder/my.wsdl", "../some.xsd", "http://example.org/some.xsd"},
}
for _, test := range tests {
r, err := ParseLocation(test.name)
if err != nil {
t.Error(err)
continue
}
r, err = r.Parse(test.ref)
if err != nil {
t.Error(err)
continue
}
if !r.isURL() || r.isFile() {
t.Error("Location should be a URL type")
}
if r.String() != test.expected {
t.Error("got " + r.String() + " wanted " + test.name)
}
}
}
func TestLocation_ParseLocation_File(t *testing.T) {
tests := []struct {
name string
}{
{"fixtures/test.wsdl"},
{"cmd/../fixtures/test.wsdl"},
}
for _, test := range tests {
r, err := ParseLocation(test.name)
if err != nil {
t.Error(err)
continue
}
if r.isURL() || !r.isFile() {
t.Error("Location should be a FILE type")
continue
}
if !filepath.IsAbs(r.String()) {
t.Error("Path should be absolute")
}
if _, err := os.Stat(r.String()); err != nil {
t.Errorf("Location should point to existing loc: %s", err.Error())
}
}
}
func TestLocation_Parse_File(t *testing.T) {
tests := []struct {
name string
ref string
expected string
}{
{"fixtures/test.wsdl", "some.xsd", "fixtures/some.xsd"},
{"fixtures/test.wsdl", "../xsd/some.xsd", "xsd/some.xsd"},
{"fixtures/test.wsdl", "xsd/some.xsd", "fixtures/xsd/some.xsd"},
}
for _, test := range tests {
r, err := ParseLocation(test.name)
if err != nil {
t.Error(err)
continue
}
r, err = r.Parse(test.ref)
if err != nil {
t.Error(err)
continue
}
if r.isURL() || !r.isFile() {
t.Error("Location should be a File type")
continue
}
x, _ := filepath.Abs("")
rel, _ := filepath.Rel(x, r.String())
if rel != test.expected {
t.Error("got " + rel + " wanted " + test.expected)
}
}
}
func TestLocation_Parse_FileToURL(t *testing.T) {
tests := []struct {
name string
ref string
expected string
}{
{"fixtures/test.wsdl", "http://example.org/some.xsd", "http://example.org/some.xsd"},
}
for _, test := range tests {
r, err := ParseLocation(test.name)
if err != nil {
t.Error(err)
continue
}
r, err = r.Parse(test.ref)
if err != nil {
t.Error(err)
continue
}
if !r.isURL() || r.isFile() {
t.Error("Location should be a URL type")
continue
}
if r.String() != test.expected {
t.Error("got " + r.String() + " wanted " + test.expected)
}
}
}