-
Gabriel Zachmann authoredGabriel Zachmann authored
utils_test.go 7.22 KiB
package utils
import "testing"
func fail(t *testing.T, expected, got []string) {
t.Errorf("Expected '%v', got '%v'", expected, got)
}
func testCombineURLs(t *testing.T, a, b, expected string) {
url := CombineURLPath(a, b)
if url != expected {
t.Errorf("Expected '%s', got '%s'", expected, url)
}
}
func TestCombineURLPathAllEmpty(t *testing.T) {
a := ""
b := ""
expected := ""
testCombineURLs(t, a, b, expected)
}
func TestCombineURLPathOneEmpty(t *testing.T) {
a := "https://example.com"
b := ""
expected := a
testCombineURLs(t, a, b, expected)
testCombineURLs(t, b, a, expected)
}
func TestCombineURLPathNoSlash(t *testing.T) {
a := "https://example.com"
b := "api"
expected := "https://example.com/api"
testCombineURLs(t, a, b, expected)
}
func TestCombineURLPathNoSlashTrailingSlash(t *testing.T) {
a := "https://example.com"
b := "api/"
expected := "https://example.com/api/"
testCombineURLs(t, a, b, expected)
}
func TestCombineURLPathOneSlashA(t *testing.T) {
a := "https://example.com/"
b := "api"
expected := "https://example.com/api"
testCombineURLs(t, a, b, expected)
}
func TestCombineURLPathOneSlashB(t *testing.T) {
a := "https://example.com"
b := "/api"
expected := "https://example.com/api"
testCombineURLs(t, a, b, expected)
}
func TestCombineURLPathBothSlash(t *testing.T) {
a := "https://example.com/"
b := "/api"
expected := "https://example.com/api"
testCombineURLs(t, a, b, expected)
}
func testIntersectList(t *testing.T, a, b, expected []string) {
intersect := IntersectSlices(a, b)
if len(intersect) != len(expected) {
fail(t, expected, intersect)
}
for i, ee := range expected {
if ee != intersect[i] {
fail(t, expected, intersect)
}
}
}
func TestIntersectSlicesAllEmpty(t *testing.T) {