Skip to content

Commit

Permalink
refactor(srid): Lift CRS/SRS/SRID code to own file - add test
Browse files Browse the repository at this point in the history
  • Loading branch information
rkettelerij committed Jul 1, 2024
1 parent 0243987 commit 2bb4144
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
49 changes: 49 additions & 0 deletions internal/ogc/features/domain/spatialref_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package domain

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetOrDefault(t *testing.T) {
tests := []struct {
name string
srid SRID
expected int
}{
{"Positive SRID", SRID(28992), 28992},
{"Zero SRID", SRID(0), WGS84SRID},
{"Negative SRID", SRID(-1), WGS84SRID},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expected, tt.srid.GetOrDefault())
})
}
}

func TestEpsgToSrid(t *testing.T) {
tests := []struct {
name string
srs string
expected SRID
expectError bool
}{
{"Valid EPSG", "EPSG:28992", SRID(28992), false},
{"Invalid prefix", "INVALID:28992", SRID(-1), true},
{"Non-numeric EPSG code", "EPSG:ABC", SRID(-1), true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := EpsgToSrid(tt.srs)
if tt.expectError {
assert.Error(t, err)
} else {
assert.NoError(t, err)
assert.Equal(t, tt.expected, result)
}
})
}
}
4 changes: 2 additions & 2 deletions internal/ogc/features/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (f *Features) Feature() http.HandlerFunc {
handleCollectionNotFound(w, collectionID)
return
}
featureID, err := getFeatureID(r)
featureID, err := parseFeatureID(r)
if err != nil {
engine.RenderProblem(engine.ProblemBadRequest, w, err.Error())
return
Expand Down Expand Up @@ -217,7 +217,7 @@ func (f *Features) Feature() http.HandlerFunc {
}
}

func getFeatureID(r *http.Request) (any, error) {
func parseFeatureID(r *http.Request) (any, error) {
var featureID any
featureID, err := uuid.Parse(chi.URLParam(r, "featureId"))
if err != nil {
Expand Down

0 comments on commit 2bb4144

Please sign in to comment.