-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidentification_test.go
More file actions
69 lines (57 loc) · 3.36 KB
/
identification_test.go
File metadata and controls
69 lines (57 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package urlidentification
import (
// "fmt"
"github.com/stretchr/testify/assert"
"net/url"
"testing"
)
var absoluteURL, _ = url.Parse("https://www.statusmachine.com")
var networkPathReferenceURL, _ = url.Parse("//statusmachine.com/subdir/page.html")
var relativeRefWithAbsPathURL, _ = url.Parse("/subdir/page.html")
var relativePathRefURL, _ = url.Parse("subdir/page.html")
func TestAbsolute(t *testing.T) {
assert.True(t, IsAbsoluteURL(absoluteURL), "URL should be Absolute")
assert.False(t, IsAbsoluteURL(networkPathReferenceURL), "URL should NOT be absolute")
assert.False(t, IsAbsoluteURL(relativeRefWithAbsPathURL), "URL should NOT be absolute")
assert.False(t, IsAbsoluteURL(relativePathRefURL), "URL should NOT be absolute")
}
func TestNetworkPathReference(t *testing.T) {
assert.True(t, IsNetworkPathReferenceURL(networkPathReferenceURL), "URL should look like //statusmachine.com/somepath")
assert.False(t, IsNetworkPathReferenceURL(absoluteURL), "URL doesn't look like //statusmachine.com/somepath")
assert.False(t, IsNetworkPathReferenceURL(relativeRefWithAbsPathURL), "URL doesn't look like //statusmachine.com/somepath")
assert.False(t, IsNetworkPathReferenceURL(relativePathRefURL), "URL doesn't look like //statusmachine.com/somepath")
}
func TestRelativeReferenceWithAbsolutePath(t *testing.T) {
assert.True(t, IsRelativeReferenceWithAbsolutePathURL(relativeRefWithAbsPathURL), "URL looks like /somepath")
assert.False(t, IsRelativeReferenceWithAbsolutePathURL(absoluteURL), "URL doesn't look like /somepath")
assert.False(t, IsRelativeReferenceWithAbsolutePathURL(networkPathReferenceURL), "URL doesn't look like /somepath")
assert.False(t, IsRelativeReferenceWithAbsolutePathURL(relativePathRefURL), "URL doesn't look like /somepath")
}
func TestRelativePathReference(t *testing.T) {
assert.True(t, IsRelativePathReferenceURL(relativePathRefURL), "URL looks like subdir/page.html")
assert.False(t, IsRelativePathReferenceURL(absoluteURL), "URL DOESN'T looks like subdir/page.html")
assert.False(t, IsRelativePathReferenceURL(networkPathReferenceURL), "URL DOESN'T looks like subdir/page.html")
assert.False(t, IsRelativePathReferenceURL(relativeRefWithAbsPathURL), "URL DOESN'T looks like subdir/page.html")
}
func TestIdentify(t *testing.T) {
identifiedURL, err := Identify(absoluteURL)
assert.Equal(t, identifiedURL, Absolute, "Should be Absolute")
assert.Nil(t, err, "Error should be nil")
identifiedURL2, err := Identify(networkPathReferenceURL)
assert.Equal(t, identifiedURL2, NetworkPathReference, "Should be NetworkPathReference")
assert.Nil(t, err, "Error should be nil")
identifiedURL3, err := Identify(relativeRefWithAbsPathURL)
assert.Equal(t, identifiedURL3, RelativeReferenceWithAbsolutePath, "Should be RelativeReferenceWithAbsolutePath")
assert.Nil(t, err, "Error should be nil")
identifiedURL4, err := Identify(relativePathRefURL)
assert.Equal(t, identifiedURL4, RelativePathReference, "Should be RelativePathReference")
assert.Nil(t, err, "Error should be nil")
}
func TestIdentifyURLString(t *testing.T) {
identifiedURL, err := IdentifyURLString("https://www.statusmachine.com")
assert.Equal(t, identifiedURL, Absolute, "Should be absolute")
assert.Nil(t, err, "Error should be nil")
unparseableURL, err := IdentifyURLString("%")
assert.Equal(t, unparseableURL, Unidentifiable, "Should NOT be identifiable")
assert.NotNil(t, err, "Error should NOT be nil")
}