Skip to content

Commit

Permalink
code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ARolek committed Aug 19, 2024
1 parent 0e5134f commit 1919ce1
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/env/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func TestParseURL(t *testing.T) {
type tcase struct {
in string
in any
expected *url.URL
expectedErr error
}
Expand Down Expand Up @@ -57,6 +57,10 @@ func TestParseURL(t *testing.T) {
in: "https://go-spatial.org/tegola/_20_%+off_60000_",
expectedErr: url.EscapeError(""),
},
"nil": {
in: nil,
expected: nil,
},
}

for name, tc := range tests {
Expand Down
4 changes: 4 additions & 0 deletions internal/env/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ func (t *URL) UnmarshalTOML(v any) error {
return err
}

if u == nil {
return nil
}

*t = URL(*u)
return nil
}
69 changes: 69 additions & 0 deletions internal/env/types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package env_test

import (
"errors"
"net/url"
"testing"

"github.com/go-spatial/tegola/internal/env"
"github.com/go-test/deep"
)

func TestURLUnmarshalTOML(t *testing.T) {
type tcase struct {
in any
expected env.URL
expectedErr error
}

fn := func(tc tcase) func(*testing.T) {
return func(t *testing.T) {
got := env.URL{}
err := got.UnmarshalTOML(tc.in)
if tc.expectedErr != nil {
if err == nil {
t.Errorf("expected err %v, got nil", tc.expectedErr.Error())
return
}

// compare error messages
if errors.Is(tc.expectedErr, err) {
t.Errorf("invalid error. expected %v, got %v", tc.expectedErr, err)
return
}

return
}
if err != nil {
t.Fatalf("unexpected error: %s", err)
}

if diff := deep.Equal(got, tc.expected); diff != nil {
t.Fatalf("expected does not match go: %v", diff)
}
}
}

tests := map[string]tcase{
"happy path": {
in: "https://go-spatial.org/tegola",
expected: env.URL{
Scheme: "https",
Host: "go-spatial.org",
Path: "/tegola",
},
},
"invalid url escape": {
in: "https://go-spatial.org/tegola/_20_%+off_60000_",
expectedErr: url.EscapeError(""),
},
"nil": {
in: nil,
expected: env.URL{},
},
}

for name, tc := range tests {
t.Run(name, fn(tc))
}
}

0 comments on commit 1919ce1

Please sign in to comment.