From be0cbeee7fb9b6e8af12745971ff80e86e0d3d32 Mon Sep 17 00:00:00 2001 From: bep Date: Mon, 11 May 2015 12:28:44 +0200 Subject: Add absURL template func Fixes #1106 --- helpers/url_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'helpers/url_test.go') diff --git a/helpers/url_test.go b/helpers/url_test.go index 1dabda273..3286c0f37 100644 --- a/helpers/url_test.go +++ b/helpers/url_test.go @@ -1,6 +1,7 @@ package helpers import ( + "github.com/spf13/viper" "github.com/stretchr/testify/assert" "strings" "testing" @@ -26,6 +27,28 @@ func TestURLize(t *testing.T) { } } +func TestAbsURL(t *testing.T) { + tests := []struct { + input string + baseURL string + expected string + }{ + {"/test/foo", "http://base/", "http://base/test/foo"}, + {"", "http://base/ace/", "http://base/ace/"}, + {"/test/2/foo/", "http://base", "http://base/test/2/foo/"}, + {"http://abs", "http://base/", "http://abs"}, + {"//schemaless", "http://base/", "//schemaless"}, + } + + for _, test := range tests { + viper.Set("BaseURL", test.baseURL) + output := AbsURL(test.input) + if output != test.expected { + t.Errorf("Expected %#v, got %#v\n", test.expected, output) + } + } +} + func TestSanitizeURL(t *testing.T) { tests := []struct { input string -- cgit v1.2.3