Skip to content

Commit d646efb

Browse files
committed
Added test
1 parent 39f19ce commit d646efb

1 file changed

Lines changed: 81 additions & 15 deletions

File tree

pkg/wms130/capabilities_test.go

Lines changed: 81 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,40 @@ package wms130
22

33
import (
44
"testing"
5+
6+
"gopkg.in/yaml.v3"
57
)
68

79
var capabilities = Capabilities{
810
WMSCapabilities: WMSCapabilities{
911
Layer: []Layer{
10-
{Name: sp(`depthOneLayerOne`),
12+
{Name: new(`depthOneLayerOne`),
1113
Layer: []*Layer{
12-
{Name: sp(`depthTwoLayerThree`), Style: []*Style{{Name: `StyleOne`}, {Name: `StyleTwo`}}},
13-
{Name: sp(`depthTwoLayerFour`),
14+
{Name: new(`depthTwoLayerThree`), Style: []*Style{{Name: `StyleOne`}, {Name: `StyleTwo`}}},
15+
{Name: new(`depthTwoLayerFour`),
1416
Layer: []*Layer{
15-
{Name: sp(`depthThreeLayerSix`)},
16-
{Name: sp(`depthThreeLayerSeven`), Style: []*Style{{Name: `StyleThree`}}},
17+
{Name: new(`depthThreeLayerSix`)},
18+
{Name: new(`depthThreeLayerSeven`), Style: []*Style{{Name: `StyleThree`}}},
1719
},
1820
},
1921
},
2022
},
21-
{Name: sp(`depthOneLayerTwo`),
23+
{Name: new(`depthOneLayerTwo`),
2224
Layer: []*Layer{
23-
{Name: sp(`depthTwoLayerFive`), Style: []*Style{{Name: `StyleFour`}, {Name: `StyleFive`}}}},
25+
{Name: new(`depthTwoLayerFive`), Style: []*Style{{Name: `StyleFour`}, {Name: `StyleFive`}}}},
2426
},
2527
},
2628
},
2729
}
2830

31+
var capabilitiesWithException = Capabilities{
32+
WMSCapabilities: WMSCapabilities{
33+
Exception: ExceptionType{
34+
Format: []string{"XML"},
35+
},
36+
},
37+
}
38+
2939
func TestGetLayerNames(t *testing.T) {
3040
expected := []string{`depthOneLayerOne`, `depthOneLayerTwo`, `depthTwoLayerThree`, `depthTwoLayerFour`, `depthTwoLayerFive`, `depthThreeLayerSix`, `depthThreeLayerSeven`}
3141

@@ -63,26 +73,82 @@ func TestStyleDefined(t *testing.T) {
6373

6474
func TestGetLayer(t *testing.T) {
6575
var tests = []struct {
66-
layername string
76+
layerName string
6777
exception Exceptions
6878
}{
69-
0: {layername: `depthTwoLayerThree`},
70-
1: {layername: `depthThreeLayerSeven`},
71-
2: {layername: `unknownLayer`, exception: Exceptions{LayerNotDefined(`unknownLayer`)}},
79+
0: {layerName: `depthTwoLayerThree`},
80+
1: {layerName: `depthThreeLayerSeven`},
81+
2: {layerName: `unknownLayer`, exception: Exceptions{LayerNotDefined(`unknownLayer`)}},
7282
}
7383

7484
for k, test := range tests {
75-
layerfound, exception := capabilities.GetLayer(test.layername)
85+
layerFound, exception := capabilities.GetLayer(test.layerName)
7686
if exception != nil {
7787
if test.exception != nil {
7888
if test.exception[0].Code() != exception[0].Code() {
79-
t.Errorf("test: %d, expected: %s \ngot: %v", k, test.layername, capabilities.GetLayerNames())
89+
t.Errorf("test: %d, expected: %s \ngot: %v", k, test.layerName, capabilities.GetLayerNames())
8090
}
8191
}
8292
} else {
83-
if *layerfound.Name != test.layername {
84-
t.Errorf("test: %d, expected: %s \ngot: %s", k, capabilities.GetLayerNames(), *layerfound.Name)
93+
if *layerFound.Name != test.layerName {
94+
t.Errorf("test: %d, expected: %s \ngot: %s", k, capabilities.GetLayerNames(), *layerFound.Name)
8595
}
8696
}
8797
}
8898
}
99+
100+
func TestException(t *testing.T) {
101+
102+
out, err := yaml.Marshal(capabilitiesWithException)
103+
if err != nil {
104+
t.Fatalf("marshal failed: %v", err)
105+
}
106+
107+
var got map[string]any
108+
if err = yaml.Unmarshal(out, &got); err != nil {
109+
t.Fatalf("unmarshal failed: %v", err)
110+
}
111+
112+
wmsRaw, ok := got["wmsCapabilities"]
113+
if !ok {
114+
t.Fatalf("expected 'wmsCapabilities' key")
115+
}
116+
117+
wms, ok := wmsRaw.(map[string]any)
118+
if !ok {
119+
t.Fatalf("'wmsCapabilities' is not a map, got %T", wmsRaw)
120+
}
121+
122+
exceptionRaw, ok := wms["exception"]
123+
if !ok {
124+
t.Fatalf("expected 'exception' key to exist")
125+
}
126+
127+
exception, ok := exceptionRaw.(map[string]any)
128+
if !ok {
129+
t.Fatalf("'exception' is not a map, got %T", exceptionRaw)
130+
}
131+
132+
formatsRaw, ok := exception["format"]
133+
if !ok {
134+
t.Fatalf("expected 'format' key to exist")
135+
}
136+
137+
formats, ok := formatsRaw.([]any)
138+
if !ok {
139+
t.Fatalf("'format' is not a slice, got %T", formatsRaw)
140+
}
141+
142+
if len(formats) != 1 {
143+
t.Fatalf("expected exactly 1 format, got %d", len(formats))
144+
}
145+
146+
formatStr, ok := formats[0].(string)
147+
if !ok {
148+
t.Fatalf("format value is not string, got %T", formats[0])
149+
}
150+
151+
if formatStr != "XML" {
152+
t.Errorf("expected 'XML', got %s", formatStr)
153+
}
154+
}

0 commit comments

Comments
 (0)