-
Notifications
You must be signed in to change notification settings - Fork 10
/
channel_test.go
48 lines (38 loc) · 1.13 KB
/
channel_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
package namecheck_test
import (
"testing"
"github.com/haritsfahreza/namecheck"
)
func TestFindChannelByCode(t *testing.T) {
t.Run("success", func(t *testing.T) {
channel, err := namecheck.FindChannelByCode(nil, ".com")
if err != nil {
t.Errorf("Error must be nil. expected: %s actual: %s", "nil", err.Error())
return
}
if channel.Code != ".com" {
t.Errorf("Invalid channel code. expected: %s actual: %s", ".com", channel.Code)
return
}
})
t.Run("failed invalid code", func(t *testing.T) {
_, err := namecheck.FindChannelByCode(nil, "invalidcode")
if err == nil {
t.Errorf("Error must not be nil. expected: %s actual: %v", "no channel found", err)
return
}
})
}
func TestFindChannelsByType(t *testing.T) {
channels := namecheck.FindChannelsByType(nil, namecheck.TypeDomain)
if len(channels) <= 0 {
t.Errorf("Channels must not be empty. expected: %s actual: %d", "> 0", len(channels))
return
}
for _, ch := range channels {
if ch.Type != namecheck.TypeDomain {
t.Errorf("Invalid channel type on channel %s. expected: %s actual: %s", ch.Code, namecheck.TypeDomain, ch.Type)
return
}
}
}