-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnetsetgo_test.go
72 lines (58 loc) · 1.98 KB
/
netsetgo_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
66
67
68
69
70
71
72
package netsetgo_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/teddyking/netsetgo"
"errors"
"github.com/teddyking/netsetgo/netsetgofakes"
)
var _ = Describe("netsetgo", func() {
var (
fakeHostConfigurer *netsetgofakes.FakeConfigurer
fakeContainerConfigurer *netsetgofakes.FakeConfigurer
netConfig NetworkConfig
pid int
netset *Netset
)
BeforeEach(func() {
fakeHostConfigurer = &netsetgofakes.FakeConfigurer{}
fakeContainerConfigurer = &netsetgofakes.FakeConfigurer{}
netConfig = NetworkConfig{BridgeName: "tower"}
pid = 100
netset = New(fakeHostConfigurer, fakeContainerConfigurer)
})
Describe("ConfigureHost()", func() {
It("configures the host", func() {
Expect(netset.ConfigureHost(netConfig, pid)).To(Succeed())
Expect(fakeHostConfigurer.ApplyCallCount()).To(Equal(1))
netConfigArg, pidArg := fakeHostConfigurer.ApplyArgsForCall(0)
Expect(netConfigArg).To(Equal(netConfig))
Expect(pidArg).To(Equal(pid))
})
Context("when the HostConfigurer returns an error", func() {
BeforeEach(func() {
fakeHostConfigurer.ApplyReturns(errors.New("error configuring host"))
})
It("returns the error", func() {
Expect(netset.ConfigureHost(netConfig, pid)).NotTo(Succeed())
})
})
})
Describe("ConfigureContainer()", func() {
It("configures the container", func() {
Expect(netset.ConfigureContainer(netConfig, pid)).To(Succeed())
Expect(fakeContainerConfigurer.ApplyCallCount()).To(Equal(1))
netConfigArg, pidArg := fakeContainerConfigurer.ApplyArgsForCall(0)
Expect(netConfigArg).To(Equal(netConfig))
Expect(pidArg).To(Equal(pid))
})
Context("when the ContainerConfigurer returns an error", func() {
BeforeEach(func() {
fakeContainerConfigurer.ApplyReturns(errors.New("error configuring container"))
})
It("returns the error", func() {
Expect(netset.ConfigureContainer(netConfig, pid)).NotTo(Succeed())
})
})
})
})