-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
65 lines (42 loc) · 1.57 KB
/
main_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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestValidateHostname(t *testing.T) {
t.Run("ReturnsTrueIfHostnameHasAtLeast2LabelsAndOnlyAlphaNumericAndHyphenCharacters", func(t *testing.T) {
// act
valid := validateHostname("estafette.io")
assert.True(t, valid)
})
t.Run("ReturnsTrueIfHostnameIsUppercase", func(t *testing.T) {
// act
valid := validateHostname("ESTAFETTE.IO")
assert.True(t, valid)
})
t.Run("ReturnsTrueIfHostnameStartsWithWildcard", func(t *testing.T) {
// act
valid := validateHostname("*.estafette.io")
assert.True(t, valid)
})
t.Run("ReturnsFalseIfHostnameHasWildcardAfterFirstCharacter", func(t *testing.T) {
// act
valid := validateHostname("*.estafette.io")
assert.True(t, valid)
})
t.Run("ReturnsFalseIfHostHasLabelsLongerThan63Characters", func(t *testing.T) {
// act
valid := validateHostname("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl.estafette.io")
assert.False(t, valid)
})
t.Run("ReturnsFalseIfHostIsLongerThan253Characters", func(t *testing.T) {
// act
valid := validateHostname("ab.abcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz.estafette.io")
assert.False(t, valid)
})
t.Run("ReturnsFalseIfHostHasOtherCharacterThanAlphaNumericOrHyphen", func(t *testing.T) {
// act
valid := validateHostname("gke_site.estafette.io")
assert.False(t, valid)
})
}