|
@@ -5,7 +5,7 @@ import "testing"
|
|
|
func TestGetAbsoluteURLWithAbsolutePath(t *testing.T) {
|
|
func TestGetAbsoluteURLWithAbsolutePath(t *testing.T) {
|
|
|
expected := `https://example.org/path/file.ext`
|
|
expected := `https://example.org/path/file.ext`
|
|
|
input := `/path/file.ext`
|
|
input := `/path/file.ext`
|
|
|
- output, err := GetAbsoluteURL("https://example.org/folder/", input)
|
|
|
|
|
|
|
+ output, err := AbsoluteURL("https://example.org/folder/", input)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Error(err)
|
|
t.Error(err)
|
|
@@ -19,7 +19,7 @@ func TestGetAbsoluteURLWithAbsolutePath(t *testing.T) {
|
|
|
func TestGetAbsoluteURLWithRelativePath(t *testing.T) {
|
|
func TestGetAbsoluteURLWithRelativePath(t *testing.T) {
|
|
|
expected := `https://example.org/folder/path/file.ext`
|
|
expected := `https://example.org/folder/path/file.ext`
|
|
|
input := `path/file.ext`
|
|
input := `path/file.ext`
|
|
|
- output, err := GetAbsoluteURL("https://example.org/folder/", input)
|
|
|
|
|
|
|
+ output, err := AbsoluteURL("https://example.org/folder/", input)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Error(err)
|
|
t.Error(err)
|
|
@@ -33,7 +33,7 @@ func TestGetAbsoluteURLWithRelativePath(t *testing.T) {
|
|
|
func TestGetAbsoluteURLWithRelativePaths(t *testing.T) {
|
|
func TestGetAbsoluteURLWithRelativePaths(t *testing.T) {
|
|
|
expected := `https://example.org/path/file.ext`
|
|
expected := `https://example.org/path/file.ext`
|
|
|
input := `path/file.ext`
|
|
input := `path/file.ext`
|
|
|
- output, err := GetAbsoluteURL("https://example.org/folder", input)
|
|
|
|
|
|
|
+ output, err := AbsoluteURL("https://example.org/folder", input)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Error(err)
|
|
t.Error(err)
|
|
@@ -47,7 +47,7 @@ func TestGetAbsoluteURLWithRelativePaths(t *testing.T) {
|
|
|
func TestWhenInputIsAlreadyAbsolute(t *testing.T) {
|
|
func TestWhenInputIsAlreadyAbsolute(t *testing.T) {
|
|
|
expected := `https://example.org/path/file.ext`
|
|
expected := `https://example.org/path/file.ext`
|
|
|
input := `https://example.org/path/file.ext`
|
|
input := `https://example.org/path/file.ext`
|
|
|
- output, err := GetAbsoluteURL("https://example.org/folder/", input)
|
|
|
|
|
|
|
+ output, err := AbsoluteURL("https://example.org/folder/", input)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Error(err)
|
|
t.Error(err)
|
|
@@ -61,7 +61,7 @@ func TestWhenInputIsAlreadyAbsolute(t *testing.T) {
|
|
|
func TestGetAbsoluteURLWithProtocolRelative(t *testing.T) {
|
|
func TestGetAbsoluteURLWithProtocolRelative(t *testing.T) {
|
|
|
expected := `https://static.example.org/path/file.ext`
|
|
expected := `https://static.example.org/path/file.ext`
|
|
|
input := `//static.example.org/path/file.ext`
|
|
input := `//static.example.org/path/file.ext`
|
|
|
- output, err := GetAbsoluteURL("https://www.example.org/", input)
|
|
|
|
|
|
|
+ output, err := AbsoluteURL("https://www.example.org/", input)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Error(err)
|
|
t.Error(err)
|
|
@@ -75,7 +75,7 @@ func TestGetAbsoluteURLWithProtocolRelative(t *testing.T) {
|
|
|
func TestGetRootURL(t *testing.T) {
|
|
func TestGetRootURL(t *testing.T) {
|
|
|
expected := `https://example.org/`
|
|
expected := `https://example.org/`
|
|
|
input := `https://example.org/path/file.ext`
|
|
input := `https://example.org/path/file.ext`
|
|
|
- output := GetRootURL(input)
|
|
|
|
|
|
|
+ output := RootURL(input)
|
|
|
|
|
|
|
|
if expected != output {
|
|
if expected != output {
|
|
|
t.Errorf(`Unexpected output, got "%s" instead of "%s"`, output, expected)
|
|
t.Errorf(`Unexpected output, got "%s" instead of "%s"`, output, expected)
|
|
@@ -85,7 +85,7 @@ func TestGetRootURL(t *testing.T) {
|
|
|
func TestGetRootURLWithProtocolRelativePath(t *testing.T) {
|
|
func TestGetRootURLWithProtocolRelativePath(t *testing.T) {
|
|
|
expected := `https://static.example.org/`
|
|
expected := `https://static.example.org/`
|
|
|
input := `//static.example.org/path/file.ext`
|
|
input := `//static.example.org/path/file.ext`
|
|
|
- output := GetRootURL(input)
|
|
|
|
|
|
|
+ output := RootURL(input)
|
|
|
|
|
|
|
|
if expected != output {
|
|
if expected != output {
|
|
|
t.Errorf(`Unexpected output, got "%s" instead of "%s"`, output, expected)
|
|
t.Errorf(`Unexpected output, got "%s" instead of "%s"`, output, expected)
|
|
@@ -105,3 +105,13 @@ func TestIsHTTPS(t *testing.T) {
|
|
|
t.Error("Unable to recognize malformed URL")
|
|
t.Error("Unable to recognize malformed URL")
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+func TestGetDomain(t *testing.T) {
|
|
|
|
|
+ expected := `static.example.org`
|
|
|
|
|
+ input := `http://static.example.org/`
|
|
|
|
|
+ output := Domain(input)
|
|
|
|
|
+
|
|
|
|
|
+ if expected != output {
|
|
|
|
|
+ t.Errorf(`Unexpected output, got "%s" instead of "%s"`, output, expected)
|
|
|
|
|
+ }
|
|
|
|
|
+}
|