forked from newrelic/sidecar
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathaddresses_test.go
53 lines (44 loc) · 1.37 KB
/
addresses_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
package main
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func Test_Addresses(t *testing.T) {
Convey("setupIPBlocks()", t, func() {
Convey("Sets up the right number of blocks", func() {
setupIPBlocks()
So(len(privateBlocks), ShouldEqual, 3)
})
})
Convey("isPrivateIP()", t, func() {
Convey("Can tell whether an address is private", func() {
So(isPrivateIP("172.16.54.3"), ShouldBeTrue)
So(isPrivateIP("12.1.1.1"), ShouldBeFalse)
})
})
Convey("findPrivateAddresses()", t, func() {
// Note that this actually looks at interfaces on the machine.
// Almost all machines will pass this test. It's possible it might
// fail on a machine that has only a public Internet IP.
Convey("Finds at least one private address", func() {
addresses, err := findPrivateAddresses()
So(err, ShouldBeNil)
So(len(addresses), ShouldBeGreaterThan, 0)
})
})
Convey("getPublishedIP()", t, func() {
ip := "10.10.10.10"
Convey("Returns the advertised IP if supplied", func() {
result, err := getPublishedIP([]string{}, ip)
So(err, ShouldBeNil)
So(result, ShouldEqual, ip)
})
// See caveat for findPrivateAddresses() above
Convey("Returns an address", func() {
addresses, _ := findPrivateAddresses()
result, err := getPublishedIP([]string{}, "")
So(err, ShouldBeNil)
So(result, ShouldResemble, addresses[0].String())
})
})
}