From 9a5ebc7e8ae4120077441313b9fbca7eccb61800 Mon Sep 17 00:00:00 2001 From: Richard Kettelerij Date: Tue, 1 Oct 2024 13:50:52 +0200 Subject: [PATCH] feat: add tests --- cmd/main_test.go | 12 ++++++++++ .../testdata/expected_dataset_collection.json | 12 ++++++++++ .../expected_dataset_landingpage.json | 24 +++++++++++++++++++ .../core/templates/landing-page.go.html | 8 +++---- .../geospatial/templates/collection.go.html | 10 ++++---- 5 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 internal/engine/testdata/expected_dataset_collection.json create mode 100644 internal/engine/testdata/expected_dataset_landingpage.json diff --git a/cmd/main_test.go b/cmd/main_test.go index 3c6988ba..9edc4406 100644 --- a/cmd/main_test.go +++ b/cmd/main_test.go @@ -86,6 +86,18 @@ func Test_newRouter(t *testing.T) { apiCall: "http://localhost:8181/sitemap.xml", wantBody: "internal/engine/testdata/expected_sitemap.xml", }, + { + name: "Should have valid structured data of type 'Dataset' on landing page", + configFile: "examples/config_all.yaml", + apiCall: "http://localhost:8181?f=html", + wantBody: "internal/engine/testdata/expected_dataset_landingpage.json", + }, + { + name: "Should have valid structured data of type 'Dataset' on (each) collection page", + configFile: "examples/config_all.yaml", + apiCall: "http://localhost:8181/collections/addresses?f=html", + wantBody: "internal/engine/testdata/expected_dataset_collection.json", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/engine/testdata/expected_dataset_collection.json b/internal/engine/testdata/expected_dataset_collection.json new file mode 100644 index 00000000..19e99407 --- /dev/null +++ b/internal/engine/testdata/expected_dataset_collection.json @@ -0,0 +1,12 @@ +{ + "@context": "https://schema.org/", + "@type": "Dataset", + "isPartOf": "http:\/\/localhost:8080?f=html", + "name": "Demo of all OGC specs in one API - Addresses", + "url": "http:\/\/localhost:8080/collections/addresses?f=html","license": "https:\/\/creativecommons.org\/publicdomain\/zero\/1.0\/deed.nl", + "isAccessibleForFree": true, + "creator":{ + "@type":"Organization", + "name":"haha Example Support" + } +} \ No newline at end of file diff --git a/internal/engine/testdata/expected_dataset_landingpage.json b/internal/engine/testdata/expected_dataset_landingpage.json new file mode 100644 index 00000000..8c98abaa --- /dev/null +++ b/internal/engine/testdata/expected_dataset_landingpage.json @@ -0,0 +1,24 @@ +{ + "@context": "https://schema.org/", + "@type": "Dataset", + "name": "Demo of all OGC specs in one API (OGC API)", + "description": "This is example combines features, 3D and vector tiles in one API. Usually this would encompass one dataset but this demo uses data from various sources. So don\u0027t pay too much attention to the actual data. It\u0027s just an example\/demo of GoKoala\u0027s capabilities.", + "url": "http:\/\/localhost:8080?f=html", + "keywords": ["keyword1, keyword2"], + "license": "https:\/\/creativecommons.org\/publicdomain\/zero\/1.0\/deed.nl", + "isAccessibleForFree": true, + "creator":{ + "@type":"Organization", + "name":"Example Support" + }, + "hasPart": [ + { + "@type": "URL", + "url": "http:\/\/localhost:8080/collections/addresses" + }, + { + "@type": "URL", + "url": "http:\/\/localhost:8080/collections/addresses2" + } + ] +} \ No newline at end of file diff --git a/internal/ogc/common/core/templates/landing-page.go.html b/internal/ogc/common/core/templates/landing-page.go.html index e40886cf..d728b80e 100644 --- a/internal/ogc/common/core/templates/landing-page.go.html +++ b/internal/ogc/common/core/templates/landing-page.go.html @@ -14,13 +14,13 @@ "keywords": ["{{ .Config.Keywords | join ", " }}"], {{- end }} "license": "{{ .Config.License.URL }}", - "isAccessibleForFree": true, + "isAccessibleForFree": true {{- if .Config.Support }} - "creator":{ + ,"creator":{ "@type":"Organization", "name":"{{ .Config.Support.Name }}" - }, - "hasPart": [ + } + ,"hasPart": [ {{- range $index, $coll := .Config.AllCollections.Unique }} {{- if $index }},{{ end }} { diff --git a/internal/ogc/common/geospatial/templates/collection.go.html b/internal/ogc/common/geospatial/templates/collection.go.html index ffe42171..17b33db5 100644 --- a/internal/ogc/common/geospatial/templates/collection.go.html +++ b/internal/ogc/common/geospatial/templates/collection.go.html @@ -32,18 +32,18 @@ "keywords": ["{{ .Params.Metadata.Keywords | join ", " }}"], {{- end -}} "license": "{{ .Config.License.URL }}", - "isAccessibleForFree": true, + "isAccessibleForFree": true {{- if .Config.Support }} - "creator":{ + ,"creator":{ "@type":"Organization", "name":"haha {{ .Config.Support.Name }}" - }, + } {{- end }} {{- if and .Params.Metadata .Params.Metadata.Thumbnail }} - "thumbnail": "resources/{{ .Params.Metadata.Thumbnail }}", + ,"thumbnail": "resources/{{ .Params.Metadata.Thumbnail }}", {{- end }} {{- if and .Params.Metadata .Params.Metadata.LastUpdated }} - "version": "{{ toDate "2006-01-02T15:04:05Z07:00" .Params.Metadata.LastUpdated | date "2006-01-02" }}" + ,"version": "{{ toDate "2006-01-02T15:04:05Z07:00" .Params.Metadata.LastUpdated | date "2006-01-02" }}" {{- end }} }