Skip to content

Commit

Permalink
fix: fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rkettelerij committed Oct 22, 2024
1 parent 2c8435d commit d6f138e
Show file tree
Hide file tree
Showing 22 changed files with 78 additions and 4,619 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ COMMANDS:
help, h Shows a list of commands or help for one command

GLOBAL OPTIONS:
--host value bind host for OGC server (default: "0.0.0.0") [$HOST]
--port value bind port for OGC server (default: 8080) [$PORT]
--host value bind host (default: "0.0.0.0") [$HOST]
--port value bind port (default: 8080) [$PORT]
--debug-port value bind port for debug server (disabled by default), do not expose this port publicly (default: -1) [$DEBUG_PORT]
--shutdown-delay value delay (in seconds) before initiating graceful shutdown (e.g. useful in k8s to allow ingress controller to update their endpoints list) (default: 0) [$SHUTDOWN_DELAY]
--config-file value reference to YAML configuration file [$CONFIG_FILE]
--openapi-file value reference to a (customized) OGC OpenAPI spec for the dynamic parts of your OGC API [$OPENAPI_FILE]
--enable-trailing-slash allow API calls to URLs with a trailing slash. (default: false) [$ALLOW_TRAILING_SLASH]
--enable-cors enable Cross-Origin Resource Sharing (CORS) as required by OGC API specs. Disable if you handle CORS elsewhere. (default: false) [$ENABLE_CORS]
--help, -h show help
Expand Down
50 changes: 7 additions & 43 deletions cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,68 +33,32 @@ func Test_newRouter(t *testing.T) {
wantBody string
}{
{
name: "Check conformance with all OGC APIs enabled in JSON",
configFile: "examples/config_all.yaml",
name: "Check conformance with OGC APIs enabled in JSON",
configFile: "examples/config.yaml",
apiCall: "http://localhost:8181/conformance?f=json",
wantBody: "internal/engine/testdata/expected_conformance.json",
},
{
name: "Check conformance with all OGC APIs enabled in HTML",
configFile: "examples/config_all.yaml",
name: "Check conformance with OGC APIs enabled in HTML",
configFile: "examples/config.yaml",
apiCall: "http://localhost:8181/conformance?f=html",
wantBody: "internal/engine/testdata/expected_conformance.html",
},
{
name: "Serve multiple OGC APIs for single collection in JSON",
configFile: "internal/engine/testdata/config_multiple_ogc_apis_single_collection.yaml",
apiCall: "http://localhost:8180/collections/NewYork?f=json",
wantBody: "internal/engine/testdata/expected_multiple_ogc_apis_single_collection.json",
},
{
name: "Serve multiple OGC APIs for single collection in HTML",
configFile: "internal/engine/testdata/config_multiple_ogc_apis_single_collection.yaml",
apiCall: "http://localhost:8180/collections/NewYork?f=html",
wantBody: "internal/engine/testdata/expected_multiple_ogc_apis_single_collection.html",
},
{
name: "Serve multiple Feature Tables from single GeoPackage",
configFile: "internal/ogc/features/testdata/config_features_bag_multiple_feature_tables.yaml",
apiCall: "http://localhost:8180/collections?f=json",
wantBody: "internal/ogc/features/testdata/expected_multiple_feature_tables_single_geopackage.json",
},
{
name: "Serve top-level OGC API Tiles",
configFile: "internal/ogc/tiles/testdata/config_tiles_toplevel_and_collectionlevel.yaml",
apiCall: "http://localhost:8180/tiles?f=json",
wantBody: "internal/ogc/tiles/testdata/expected_top_level_tiles.json",
},
{
name: "Serve collection-level OGC API Tiles",
configFile: "internal/ogc/tiles/testdata/config_tiles_toplevel_and_collectionlevel.yaml",
apiCall: "http://localhost:8180/collections/example2/tiles?f=json",
wantBody: "internal/ogc/tiles/testdata/expected_collection_level_tiles.json",
},
{
name: "Check conformance of OGC API Processes",
configFile: "internal/engine/testdata/config_processes.yaml",
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",
configFile: "examples/config.yaml",
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",
configFile: "examples/config.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",
configFile: "examples/config.yaml",
apiCall: "http://localhost:8181/collections/addresses?f=html",
wantBody: "internal/engine/testdata/expected_dataset_collection.json",
},
Expand Down
50 changes: 0 additions & 50 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,6 @@ func TestGeoSpatialCollections_Ordering(t *testing.T) {
expectedOrder: []string{"B", "C", "Z", "Z", "A"},
},
},
{
name: "should return collections in default order (alphabetic) - extra test",
args: args{
configFile: "internal/engine/testdata/config_collections_unique.yaml",
expectedOrder: []string{"BarCollection", "FooCollection", "FooCollection"},
},
},
{
name: "should return collections in explicit / literal order",
args: args{
configFile: "internal/engine/testdata/config_collections_order_literal.yaml",
expectedOrder: []string{"Z", "Z", "C", "A", "B"},
},
},
{
name: "should not error when no collections",
args: args{
configFile: "internal/engine/testdata/config_minimal.yaml",
expectedOrder: []string{},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -121,35 +100,6 @@ func TestGeoSpatialCollections_Ordering(t *testing.T) {
}
}

func TestGeoSpatialCollections_Unique(t *testing.T) {
type args struct {
configFile string
nrOfCollections int
nrOfUniqueCollections int
}
tests := []struct {
name string
args args
}{
{
name: "should filter duplicate collections when calling Unique()",
args: args{
configFile: "internal/engine/testdata/config_collections_unique.yaml",
nrOfCollections: 3,
nrOfUniqueCollections: 2,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
config, err := NewConfig(tt.args.configFile)
assert.NoError(t, err)
assert.Len(t, config.AllCollections(), tt.args.nrOfCollections)
assert.Len(t, config.AllCollections().Unique(), tt.args.nrOfUniqueCollections)
})
}
}

func TestGeoSpatialCollections_ContainsID(t *testing.T) {
tests := []struct {
name string
Expand Down
3 changes: 1 addition & 2 deletions internal/engine/openapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (

func Test_newOpenAPI(t *testing.T) {
type args struct {
config *gomagpieconfig.Config
openAPIFile string
config *gomagpieconfig.Config
}
tests := []struct {
name string
Expand Down
21 changes: 8 additions & 13 deletions internal/engine/testdata/config_collections_order_alphabetic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@ license:
name: CC0 1.0
url: https://creativecommons.org/publicdomain/zero/1.0/deed.nl
baseUrl: http://localhost:8181
ogcApi:
3dgeovolumes:
tileServer: https://example.com
collections:
- id: B
- id: Z
- id: C
tiles:
collections:
- id: Z
tileServer: https://example.com
- id: A
tileServer: https://example.com
database:
connectionString: abc
collections:
- id: B
- id: Z
- id: C
- id: Z
- id: A
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ license:
name: CC0 1.0
url: https://creativecommons.org/publicdomain/zero/1.0/deed.nl
baseUrl: http://localhost:8181
ogcApi:
3dgeovolumes:
tileServer: https://example.com
collections:
- id: B
metadata:
title: Bear
- id: Z
metadata:
title: Chicken
- id: C
metadata:
title: Bird
tiles:
collections:
- id: Z
tileServer: https://example.com
metadata:
title: Chicken
- id: A
tileServer: https://example.com
metadata:
title: Horse
database:
connectionString: abc
collections:
- id: B
metadata:
title: Bear
description: abc
- id: Z
metadata:
title: Chicken
description: abc
- id: C
metadata:
title: Bird
description: abc
- id: Z
metadata:
title: Chicken
description: abc
- id: A
metadata:
title: Horse
description: abc
21 changes: 0 additions & 21 deletions internal/engine/testdata/config_collections_unique.yaml

This file was deleted.

4 changes: 4 additions & 0 deletions internal/engine/testdata/config_minimal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ serviceIdentifier: Min
license:
name: MIT
url: https://www.tldrlegal.com/license/mit-license
database:
connectionString: example
collections:
- id: foo

This file was deleted.

16 changes: 0 additions & 16 deletions internal/engine/testdata/config_processes.yaml

This file was deleted.

Loading

0 comments on commit d6f138e

Please sign in to comment.