Skip to content

Commit

Permalink
feat: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
rkettelerij committed Sep 30, 2024
1 parent ac94b0b commit b6cc092
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 43 deletions.
8 changes: 7 additions & 1 deletion cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ func Test_newRouter(t *testing.T) {
apiCall: "http://localhost:8181/conformance?f=html",
wantBody: "internal/engine/testdata/expected_processes_conformance.html",
},
{
name: "Should have valid sitemap XML",
configFile: "examples/config_all.yaml",
apiCall: "http://localhost:8181/sitemap.xml",
wantBody: "internal/engine/testdata/expected_sitemap.xml",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -107,7 +113,7 @@ func Test_newRouter(t *testing.T) {
switch {
case strings.HasSuffix(tt.apiCall, "json"):
assert.JSONEq(t, recorder.Body.String(), string(expectedBody))
case strings.HasSuffix(tt.apiCall, "html"):
case strings.HasSuffix(tt.apiCall, "html") || strings.HasSuffix(tt.apiCall, "xml"):
assert.Contains(t, normalize(recorder.Body.String()), normalize(string(expectedBody)))
default:
log.Fatalf("implement support to test format: %s", tt.apiCall)
Expand Down
84 changes: 42 additions & 42 deletions internal/engine/templates/sitemap.go.xml
Original file line number Diff line number Diff line change
@@ -1,78 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>{{ .Config.BaseURL}}/</loc>
<loc>{{- .Config.BaseURL -}}/</loc>
</url>
<url>
<loc>{{ .Config.BaseURL}}/api</loc>
<loc>{{- .Config.BaseURL -}}/api</loc>
</url>
<url>
<loc>{{ .Config.BaseURL}}/conformance</loc>
<loc>{{- .Config.BaseURL -}}/conformance</loc>
</url>
{{ if .Config.HasCollections }}
{{- if .Config.HasCollections -}}
<url>
<loc>{{ .Config.BaseURL}}/collections</loc>
<loc>{{- .Config.BaseURL -}}/collections</loc>
</url>
{{ end }}
{{ range $index, $coll := .Config.AllCollections.Unique }}
{{- end -}}
{{- range $index, $coll := .Config.AllCollections.Unique -}}
<url>
<loc>{{ $.Config.BaseURL}}/collections/{{ $coll.ID }}</loc>
<loc>{{- $.Config.BaseURL -}}/collections/{{- $coll.ID -}}</loc>
</url>
{{ if and $.Config.OgcAPI.Tiles $.Config.OgcAPI.Tiles.Collections ($.Config.OgcAPI.Tiles.Collections.ContainsID $coll.ID) }}
{{- if and $.Config.OgcAPI.Tiles $.Config.OgcAPI.Tiles.Collections ($.Config.OgcAPI.Tiles.Collections.ContainsID $coll.ID) -}}
<url>
<loc>{{ $.Config.BaseURL}}/collections/{{ $coll.ID }}/tiles</loc>
<loc>{{- $.Config.BaseURL -}}/collections/{{- $coll.ID -}}/tiles</loc>
</url>
{{ end }}
{{ if and $.Config.OgcAPI.Features $.Config.OgcAPI.Features.Collections ($.Config.OgcAPI.Features.Collections.ContainsID $coll.ID) }}
{{- end -}}
{{- if and $.Config.OgcAPI.Features $.Config.OgcAPI.Features.Collections ($.Config.OgcAPI.Features.Collections.ContainsID $coll.ID) -}}
<url>
<loc>{{ $.Config.BaseURL}}/collections/{{ $coll.ID }}/items</loc>
<loc>{{- $.Config.BaseURL -}}/collections/{{- $coll.ID -}}/items</loc>
</url>
{{ end }}
{{- end -}}
{{/* don't list /collections/<name>/3dtiles since it has no HTML representation */}}
{{ end }}
{{ if and .Config.OgcAPI.Tiles .Config.OgcAPI.Tiles.DatasetTiles }}
{{- end -}}
{{- if and .Config.OgcAPI.Tiles .Config.OgcAPI.Tiles.DatasetTiles -}}
<url>
<loc>{{ .Config.BaseURL}}/tiles</loc>
<loc>{{- .Config.BaseURL -}}/tiles</loc>
</url>
{{ if .Config.OgcAPI.Tiles.HasProjection "EPSG:28992" }}
{{- if .Config.OgcAPI.Tiles.HasProjection "EPSG:28992" -}}
<url>
<loc>{{ .Config.BaseURL}}/tiles/NetherlandsRDNewQuad</loc>
<loc>{{- .Config.BaseURL -}}/tiles/NetherlandsRDNewQuad</loc>
</url>
{{ end }}
{{ if .Config.OgcAPI.Tiles.HasProjection "EPSG:3035" }}
{{- end -}}
{{- if .Config.OgcAPI.Tiles.HasProjection "EPSG:3035" -}}
<url>
<loc>{{ .Config.BaseURL}}/tiles/EuropeanETRS89_LAEAQuad</loc>
<loc>{{- .Config.BaseURL -}}/tiles/EuropeanETRS89_LAEAQuad</loc>
</url>
{{ end }}
{{ if .Config.OgcAPI.Tiles.HasProjection "EPSG:3857" }}
{{- end -}}
{{- if .Config.OgcAPI.Tiles.HasProjection "EPSG:3857" -}}
<url>
<loc>{{ .Config.BaseURL}}/tiles/WebMercatorQuad</loc>
<loc>{{- .Config.BaseURL -}}/tiles/WebMercatorQuad</loc>
</url>
{{ end }}
{{ end }}
{{ if .Config.OgcAPI.Tiles }}
{{- end -}}
{{- end -}}
{{- if .Config.OgcAPI.Tiles -}}
<url>
<loc>{{ .Config.BaseURL}}/tileMatrixSets</loc>
<loc>{{- .Config.BaseURL -}}/tileMatrixSets</loc>
</url>
{{ if .Config.OgcAPI.Tiles.HasProjection "EPSG:28992" }}
{{- if .Config.OgcAPI.Tiles.HasProjection "EPSG:28992" -}}
<url>
<loc>{{ .Config.BaseURL}}/tileMatrixSets/NetherlandsRDNewQuad</loc>
<loc>{{- .Config.BaseURL -}}/tileMatrixSets/NetherlandsRDNewQuad</loc>
</url>
{{ end }}
{{ if .Config.OgcAPI.Tiles.HasProjection "EPSG:3035" }}
{{- end -}}
{{- if .Config.OgcAPI.Tiles.HasProjection "EPSG:3035" -}}
<url>
<loc>{{ .Config.BaseURL}}/tileMatrixSets/EuropeanETRS89_LAEAQuad</loc>
<loc>{{- .Config.BaseURL -}}/tileMatrixSets/EuropeanETRS89_LAEAQuad</loc>
</url>
{{ end }}
{{ if .Config.OgcAPI.Tiles.HasProjection "EPSG:3857" }}
{{- end -}}
{{- if .Config.OgcAPI.Tiles.HasProjection "EPSG:3857" -}}
<url>
<loc>{{ .Config.BaseURL}}/tileMatrixSets/WebMercatorQuad</loc>
<loc>{{- .Config.BaseURL -}}/tileMatrixSets/WebMercatorQuad</loc>
</url>
{{ end }}
{{ end }}
{{ if and .Config.OgcAPI.Styles .Config.OgcAPI.Tiles }}
{{- end -}}
{{- end -}}
{{- if and .Config.OgcAPI.Styles .Config.OgcAPI.Tiles -}}
<url>
<loc>{{ .Config.BaseURL}}/styles</loc>
<loc>{{- .Config.BaseURL -}}/styles</loc>
</url>
{{ end }}
{{- end -}}
</urlset>
50 changes: 50 additions & 0 deletions internal/engine/testdata/expected_sitemap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://localhost:8080/</loc>
</url>
<url>
<loc>http://localhost:8080/api</loc>
</url>
<url>
<loc>http://localhost:8080/conformance</loc>
</url>
<url>
<loc>http://localhost:8080/collections</loc>
</url>
<url>
<loc>http://localhost:8080/collections/addresses</loc>
</url>
<url>
<loc>http://localhost:8080/collections/addresses/tiles</loc>
</url>
<url>
<loc>http://localhost:8080/collections/addresses/items</loc>
</url>
<url>
<loc>http://localhost:8080/collections/addresses2</loc>
</url>
<url>
<loc>http://localhost:8080/collections/addresses2/items</loc>
</url>
<url>
<loc>http://localhost:8080/tiles</loc>
</url>
<url>
<loc>http://localhost:8080/tiles/NetherlandsRDNewQuad</loc>
</url>
<url>
<loc>http://localhost:8080/tiles/EuropeanETRS89_LAEAQuad</loc>
</url>
<url>
<loc>http://localhost:8080/tileMatrixSets</loc>
</url>
<url>
<loc>http://localhost:8080/tileMatrixSets/NetherlandsRDNewQuad</loc>
</url>
<url>
<loc>http://localhost:8080/tileMatrixSets/EuropeanETRS89_LAEAQuad</loc>
</url>
<url>
<loc>http://localhost:8080/styles</loc>
</url>
</urlset>

0 comments on commit b6cc092

Please sign in to comment.