forked from knative/func
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction_unit_test.go
75 lines (58 loc) · 2.49 KB
/
function_unit_test.go
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
70
71
72
73
74
75
package faas
import (
"testing"
)
// TestPathToDomain validatest the calculation used to derive a default domain
// for a Function from the current directory path (used as a default
// in the absence of an explicit setting).
// NOTE: although the implementation uses os.PathSeparator and is developed with
// non-unix platforms in mind, these tests are written using unix-style paths.
func TestPathToDomain(t *testing.T) {
var noLimit = -1
tests := []struct {
Path string // input path
Limit int // upward recursion limit
Domain string // Expected returned domain value
}{
// empty input should not find a domain.
{"", noLimit, ""},
// trailing slashes ignored
{"/home/user/example.com/admin/", noLimit, "admin.example.com"},
// root path should not find a domain.
{"/", noLimit, ""},
// valid path but without a domain should find no domain.
{"/home/user", noLimit, ""},
// valid domain as the current directory should be found.
{"/home/user/example.com", noLimit, "example.com"},
// valid domain as the current directory should be found even with recursion disabled.
{"/home/user/example.com", 0, "example.com"},
// Subdomain
{"/src/example.com/www", noLimit, "www.example.com"},
// Subdomain with recursion disabled should not find the domain.
{"/src/example.com/www", 0, ""},
// Sub-subdomain
{"/src/example.com/www/test1", noLimit, "test1.www.example.com"},
// Sub-subdomain with exact recursion limit to catch the domain
{"/src/example.com/www/test1", 2, "test1.www.example.com"},
// CWD a valid TLD+1 (not suggested, but supported)
{"/src/my.example.com", noLimit, "my.example.com"},
// Multi-level TLDs
{"/src/example.co.uk", noLimit, "example.co.uk"},
// Multi-level TLDs with sub
{"/src/example.co.uk/www", noLimit, "www.example.co.uk"},
// Expected behavior is `test1.my.example.com` but will yield `test1.my`
// because .my is a TLD hence the reason why dots in directories to denote
// multiple levels of subdomain are technically supported but not
// recommended: unexpected behavior because the public suffices list is
// shifty.
{"/src/example.com/test1.my", noLimit, "test1.my"},
// Ensure that cluster.local is explicitly allowed.
{"/src/cluster.local/www", noLimit, "www.cluster.local"},
}
for _, test := range tests {
domain := pathToDomain(test.Path, test.Limit)
if domain != test.Domain {
t.Fatalf("expected path '%v' (limit %v) to yield domain '%v', got '%v'", test.Path, test.Limit, test.Domain, domain)
}
}
}