Add absURL template func

Fixes #1106
This commit is contained in:
bep
2015-05-11 12:28:44 +02:00
parent bec90e0850
commit be0cbeee7f
3 changed files with 34 additions and 1 deletions

View File

@@ -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