-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
47 lines (36 loc) · 994 Bytes
/
utils_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
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
// +build !windows
package network_test
import (
"errors"
"net"
"github.com/juju/testing"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/juju/network"
)
type UtilsSuite struct {
testing.IsolationSuite
}
var _ = gc.Suite(&UtilsSuite{})
func (s *UtilsSuite) TestSupportsIPv6Error(c *gc.C) {
s.PatchValue(network.NetListen, func(netFamily, bindAddress string) (net.Listener, error) {
c.Check(netFamily, gc.Equals, "tcp6")
c.Check(bindAddress, gc.Equals, "[::1]:0")
return nil, errors.New("boom!")
})
c.Check(network.SupportsIPv6(), jc.IsFalse)
}
func (s *UtilsSuite) TestSupportsIPv6OK(c *gc.C) {
s.PatchValue(network.NetListen, func(_, _ string) (net.Listener, error) {
return &mockListener{}, nil
})
c.Check(network.SupportsIPv6(), jc.IsTrue)
}
type mockListener struct {
net.Listener
}
func (*mockListener) Close() error {
return nil
}