-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
wtfismyip_test.go
48 lines (43 loc) · 986 Bytes
/
wtfismyip_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 main
import (
"github.com/stretchr/testify/assert"
"testing"
)
type fakeWtfismyipClient struct {
}
func (wtfismyip fakeWtfismyipClient) getIpAddress(ipv6 bool) (string, error) {
if ipv6 {
return "9afb:8b5f:078a:b914:e59e:f927:b0fa:ff31", nil
}
return "194.52.151.172", nil
}
func TestUnusedFromRecordsProduceEmptyIpAddresses(t *testing.T) {
c := configuration{
Records: []Record{
{
Domain: "example.com",
Host: "www",
IpV6: false,
IpV4: false,
},
},
}
ipv4, ipv6 := getIpAddresses(c, fakeWtfismyipClient{})
assert.Equal(t, "", ipv4)
assert.Equal(t, "", ipv6)
}
func TestUsedFromRecordsProduceIPPaddresses(t *testing.T) {
c := configuration{
Records: []Record{
{
Domain: "example.com",
Host: "www",
IpV6: true,
IpV4: true,
},
},
}
ipv4, ipv6 := getIpAddresses(c, fakeWtfismyipClient{})
assert.Equal(t, "194.52.151.172", ipv4)
assert.Equal(t, "9afb:8b5f:078a:b914:e59e:f927:b0fa:ff31", ipv6)
}