Skip to content

Commit

Permalink
chore: Add test not to break legacy mode again
Browse files Browse the repository at this point in the history
  • Loading branch information
rg0now committed May 10, 2024
1 parent 868704f commit 374ecc5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion pkg/config/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ import (

func TestParseURI(t *testing.T) {
// file
u, err := getURI("/tmp/a")
u, err := getURI("file:///tmp/a")
assert.NoError(t, err, "file URI parse")
assert.Equal(t, "file", u.Scheme, "file URI scheme")
assert.Equal(t, "", u.Host, "file URI host")
assert.Equal(t, "/tmp/a", u.Path, "file URI path")

// default is http
u, err = getURI("/tmp/a")
assert.NoError(t, err, "file URI parse")
assert.Equal(t, "http", u.Scheme, "file URI scheme")
assert.Equal(t, "", u.Host, "file URI host")
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/client/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func decodeConfigList(r []byte) ([]*stnrv1.StunnerConfig, error) {

// getURI tries to parse an address or an URL or a file name into an URL.
func getURI(addr string) (*url.URL, error) {
// make sure we have a working HTTP scheme
// default URL scheme is "http"
if !strings.HasPrefix(addr, "http://") && !strings.HasPrefix(addr, "https://") &&
!strings.HasPrefix(addr, "ws://") && !strings.HasPrefix(addr, "wss://") &&
!strings.HasPrefix(addr, "file://") {
Expand Down

0 comments on commit 374ecc5

Please sign in to comment.