diff options
Diffstat (limited to 'config/config_test.go')
-rw-r--r-- | config/config_test.go | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/config/config_test.go b/config/config_test.go index 2cfec81..1f91add 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -56,7 +56,7 @@ func TestCustomBaseURLWithTrailingSlash(t *testing.T) { } if cfg.RootURL() != "http://example.org" { - t.Fatalf(`Unexpected root URL, got "%s"`, cfg.BaseURL()) + t.Fatalf(`Unexpected root URL, got "%s"`, cfg.RootURL()) } if cfg.BasePath() != "/folder" { @@ -64,6 +64,42 @@ func TestCustomBaseURLWithTrailingSlash(t *testing.T) { } } +func TestBaseURLWithoutScheme(t *testing.T) { + os.Clearenv() + os.Setenv("BASE_URL", "example.org/folder/") + cfg := NewConfig() + + if cfg.BaseURL() != "http://localhost" { + t.Fatalf(`Unexpected base URL, got "%s"`, cfg.BaseURL()) + } + + if cfg.RootURL() != "http://localhost" { + t.Fatalf(`Unexpected root URL, got "%s"`, cfg.RootURL()) + } + + if cfg.BasePath() != "" { + t.Fatalf(`Unexpected base path, got "%s"`, cfg.BasePath()) + } +} + +func TestBaseURLWithInvalidScheme(t *testing.T) { + os.Clearenv() + os.Setenv("BASE_URL", "ftp://example.org/folder/") + cfg := NewConfig() + + if cfg.BaseURL() != "http://localhost" { + t.Fatalf(`Unexpected base URL, got "%s"`, cfg.BaseURL()) + } + + if cfg.RootURL() != "http://localhost" { + t.Fatalf(`Unexpected root URL, got "%s"`, cfg.RootURL()) + } + + if cfg.BasePath() != "" { + t.Fatalf(`Unexpected base path, got "%s"`, cfg.BasePath()) + } +} + func TestDefaultBaseURL(t *testing.T) { os.Clearenv() cfg := NewConfig() |