Skip to content

Commit

Permalink
Add more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rkettelerij committed Oct 16, 2023
1 parent a8c0f47 commit 973dcfe
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
4 changes: 1 addition & 3 deletions ogc/features/datasources/geopackage/geopackage.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ type GeoPackage struct {
queryTimeout time.Duration
}

func NewGeoPackage(e *engine.Engine) *GeoPackage {
gpkgConfig := e.Config.OgcAPI.Features.Datasource.GeoPackage

func NewGeoPackage(gpkgConfig engine.GeoPackage) *GeoPackage {
g := &GeoPackage{}
switch {
case gpkgConfig.Local != nil:
Expand Down
46 changes: 37 additions & 9 deletions ogc/features/datasources/geopackage/geopackage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,43 @@ func init() {
pwd = path.Dir(filename)
}

func newAddressesGeoPackage() geoPackageBackend {
return newLocalGeoPackage(&engine.GeoPackageLocal{
GeoPackageCommon: engine.GeoPackageCommon{
Fid: "feature_id",
},
File: pwd + "/testdata/addresses.gpkg",
})
}

func TestNewGeoPackage(t *testing.T) {
type args struct {
config engine.GeoPackage
}
tests := []struct {
name string
args args
wantNrOfFeatureTablesInGpkg int
}{
{
name: "open local geopackage",
args: args{
engine.GeoPackage{
Local: &engine.GeoPackageLocal{
File: pwd + "/testdata/addresses.gpkg",
},
},
},
wantNrOfFeatureTablesInGpkg: 3,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.wantNrOfFeatureTablesInGpkg, len(NewGeoPackage(tt.args.config).featureTableByID), "NewGeoPackage(%v)", tt.args.config)
})
}
}

func TestGeoPackage_GetFeatures(t *testing.T) {
type fields struct {
backend geoPackageBackend
Expand Down Expand Up @@ -177,15 +214,6 @@ func TestGeoPackage_GetFeatures(t *testing.T) {
}
}

func newAddressesGeoPackage() geoPackageBackend {
return newLocalGeoPackage(&engine.GeoPackageLocal{
GeoPackageCommon: engine.GeoPackageCommon{
Fid: "feature_id",
},
File: pwd + "/testdata/addresses.gpkg",
})
}

func TestGeoPackage_GetFeature(t *testing.T) {
type fields struct {
backend geoPackageBackend
Expand Down
2 changes: 1 addition & 1 deletion ogc/features/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewFeatures(e *engine.Engine, router *chi.Mux) *Features {
if e.Config.OgcAPI.Features.Datasource.FakeDB {
datasource = fakedb.NewFakeDB()
} else if e.Config.OgcAPI.Features.Datasource.GeoPackage != nil {
datasource = geopackage.NewGeoPackage(e)
datasource = geopackage.NewGeoPackage(*e.Config.OgcAPI.Features.Datasource.GeoPackage)
}
e.RegisterShutdownHook(datasource.Close)

Expand Down

0 comments on commit 973dcfe

Please sign in to comment.