Skip to content

Commit cc02894

Browse files
committed
Move test specific functions to a testutils package.
This way we won't vendor test related functions in docker anymore. It also moves netns related functions to a new ns package to be able to call the ns init function in tests. I think this also helps with the overall package isolation. Signed-off-by: David Calavera <david.calavera@gmail.com>
1 parent 225a52c commit cc02894

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+203
-173
lines changed

libnetwork/api/api_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/docker/libnetwork"
1717
"github.com/docker/libnetwork/netlabel"
1818
"github.com/docker/libnetwork/options"
19-
"github.com/docker/libnetwork/osl"
19+
"github.com/docker/libnetwork/testutils"
2020
"github.com/docker/libnetwork/types"
2121
)
2222

@@ -178,7 +178,7 @@ func TestJson(t *testing.T) {
178178
}
179179

180180
func TestCreateDeleteNetwork(t *testing.T) {
181-
defer osl.SetupTestOSContext(t)()
181+
defer testutils.SetupTestOSContext(t)()
182182

183183
c, err := libnetwork.New()
184184
if err != nil {
@@ -256,7 +256,7 @@ func TestCreateDeleteNetwork(t *testing.T) {
256256
}
257257

258258
func TestGetNetworksAndEndpoints(t *testing.T) {
259-
defer osl.SetupTestOSContext(t)()
259+
defer testutils.SetupTestOSContext(t)()
260260

261261
c, err := libnetwork.New()
262262
if err != nil {
@@ -529,7 +529,7 @@ func TestGetNetworksAndEndpoints(t *testing.T) {
529529
}
530530

531531
func TestProcGetServices(t *testing.T) {
532-
defer osl.SetupTestOSContext(t)()
532+
defer testutils.SetupTestOSContext(t)()
533533

534534
c, err := libnetwork.New()
535535
if err != nil {
@@ -702,7 +702,7 @@ func TestProcGetServices(t *testing.T) {
702702
}
703703

704704
func TestProcGetService(t *testing.T) {
705-
defer osl.SetupTestOSContext(t)()
705+
defer testutils.SetupTestOSContext(t)()
706706

707707
c, nw := createTestNetwork(t, "network")
708708
ep1, err := nw.CreateEndpoint("db")
@@ -754,7 +754,7 @@ func TestProcGetService(t *testing.T) {
754754
}
755755

756756
func TestProcPublishUnpublishService(t *testing.T) {
757-
defer osl.SetupTestOSContext(t)()
757+
defer testutils.SetupTestOSContext(t)()
758758

759759
c, _ := createTestNetwork(t, "network")
760760
vars := make(map[string]string)
@@ -886,7 +886,7 @@ func TestProcPublishUnpublishService(t *testing.T) {
886886
}
887887

888888
func TestAttachDetachBackend(t *testing.T) {
889-
defer osl.SetupTestOSContext(t)()
889+
defer testutils.SetupTestOSContext(t)()
890890

891891
c, nw := createTestNetwork(t, "network")
892892
ep1, err := nw.CreateEndpoint("db")
@@ -1026,7 +1026,7 @@ func TestDetectGetNetworksInvalidQueryComposition(t *testing.T) {
10261026
}
10271027

10281028
func TestDetectGetEndpointsInvalidQueryComposition(t *testing.T) {
1029-
defer osl.SetupTestOSContext(t)()
1029+
defer testutils.SetupTestOSContext(t)()
10301030

10311031
c, _ := createTestNetwork(t, "network")
10321032

@@ -1038,7 +1038,7 @@ func TestDetectGetEndpointsInvalidQueryComposition(t *testing.T) {
10381038
}
10391039

10401040
func TestDetectGetServicesInvalidQueryComposition(t *testing.T) {
1041-
defer osl.SetupTestOSContext(t)()
1041+
defer testutils.SetupTestOSContext(t)()
10421042

10431043
c, _ := createTestNetwork(t, "network")
10441044

@@ -1055,7 +1055,7 @@ func TestFindNetworkUtilPanic(t *testing.T) {
10551055
}
10561056

10571057
func TestFindNetworkUtil(t *testing.T) {
1058-
defer osl.SetupTestOSContext(t)()
1058+
defer testutils.SetupTestOSContext(t)()
10591059

10601060
c, nw := createTestNetwork(t, "network")
10611061
nid := nw.ID()
@@ -1118,7 +1118,7 @@ func TestFindNetworkUtil(t *testing.T) {
11181118
}
11191119

11201120
func TestCreateDeleteEndpoints(t *testing.T) {
1121-
defer osl.SetupTestOSContext(t)()
1121+
defer testutils.SetupTestOSContext(t)()
11221122

11231123
c, err := libnetwork.New()
11241124
if err != nil {
@@ -1244,7 +1244,7 @@ func TestCreateDeleteEndpoints(t *testing.T) {
12441244
}
12451245

12461246
func TestJoinLeave(t *testing.T) {
1247-
defer osl.SetupTestOSContext(t)()
1247+
defer testutils.SetupTestOSContext(t)()
12481248

12491249
c, err := libnetwork.New()
12501250
if err != nil {
@@ -1403,22 +1403,22 @@ func TestJoinLeave(t *testing.T) {
14031403
}
14041404

14051405
func TestFindEndpointUtilPanic(t *testing.T) {
1406-
defer osl.SetupTestOSContext(t)()
1406+
defer testutils.SetupTestOSContext(t)()
14071407
defer checkPanic(t)
14081408
c, nw := createTestNetwork(t, "network")
14091409
nid := nw.ID()
14101410
findEndpoint(c, nid, "", byID, -1)
14111411
}
14121412

14131413
func TestFindServiceUtilPanic(t *testing.T) {
1414-
defer osl.SetupTestOSContext(t)()
1414+
defer testutils.SetupTestOSContext(t)()
14151415
defer checkPanic(t)
14161416
c, _ := createTestNetwork(t, "network")
14171417
findService(c, "random_service", -1)
14181418
}
14191419

14201420
func TestFindEndpointUtil(t *testing.T) {
1421-
defer osl.SetupTestOSContext(t)()
1421+
defer testutils.SetupTestOSContext(t)()
14221422

14231423
c, nw := createTestNetwork(t, "network")
14241424
nid := nw.ID()
@@ -1687,7 +1687,7 @@ func TestwriteJSON(t *testing.T) {
16871687
}
16881688

16891689
func TestHttpHandlerUninit(t *testing.T) {
1690-
defer osl.SetupTestOSContext(t)()
1690+
defer testutils.SetupTestOSContext(t)()
16911691

16921692
c, err := libnetwork.New()
16931693
if err != nil {
@@ -1756,7 +1756,7 @@ func TestHttpHandlerUninit(t *testing.T) {
17561756
}
17571757

17581758
func TestHttpHandlerBadBody(t *testing.T) {
1759-
defer osl.SetupTestOSContext(t)()
1759+
defer testutils.SetupTestOSContext(t)()
17601760

17611761
rsp := newWriter()
17621762

@@ -1788,7 +1788,7 @@ func TestHttpHandlerBadBody(t *testing.T) {
17881788
}
17891789

17901790
func TestEndToEnd(t *testing.T) {
1791-
defer osl.SetupTestOSContext(t)()
1791+
defer testutils.SetupTestOSContext(t)()
17921792

17931793
rsp := newWriter()
17941794

@@ -2240,7 +2240,7 @@ func TestEndToEnd(t *testing.T) {
22402240
}
22412241

22422242
func TestEndToEndErrorMessage(t *testing.T) {
2243-
defer osl.SetupTestOSContext(t)()
2243+
defer testutils.SetupTestOSContext(t)()
22442244

22452245
rsp := newWriter()
22462246

libnetwork/bitseq/sequence_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package bitseq
33
import (
44
"testing"
55

6-
_ "github.com/docker/libnetwork/netutils"
6+
_ "github.com/docker/libnetwork/testutils"
77
)
88

99
func TestSequenceGetAvailableBit(t *testing.T) {

libnetwork/client/client_service_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"testing"
66

7-
_ "github.com/docker/libnetwork/netutils"
7+
_ "github.com/docker/libnetwork/testutils"
88
)
99

1010
func TestClientServiceInvalidCommand(t *testing.T) {

libnetwork/client/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"strings"
1111
"testing"
1212

13-
_ "github.com/docker/libnetwork/netutils"
13+
_ "github.com/docker/libnetwork/testutils"
1414
)
1515

1616
// nopCloser is used to provide a dummy CallFunc for Cmd()

libnetwork/cmd/dnet/dnet_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import (
77
"testing"
88
"time"
99

10-
"github.com/docker/libnetwork/netutils"
10+
"github.com/docker/libnetwork/testutils"
1111
)
1212

1313
const dnetCommandName = "dnet"
1414

1515
var origStdOut = os.Stdout
1616

1717
func TestDnetDaemonCustom(t *testing.T) {
18-
if !netutils.IsRunningInContainer() {
18+
if !testutils.IsRunningInContainer() {
1919
t.Skip("This test must run inside a container ")
2020
}
2121
customPort := 4567
@@ -36,7 +36,7 @@ func TestDnetDaemonCustom(t *testing.T) {
3636
}
3737

3838
func TestDnetDaemonInvalidCustom(t *testing.T) {
39-
if !netutils.IsRunningInContainer() {
39+
if !testutils.IsRunningInContainer() {
4040
t.Skip("This test must run inside a container ")
4141
}
4242
customPort := 4668
@@ -57,7 +57,7 @@ func TestDnetDaemonInvalidCustom(t *testing.T) {
5757
}
5858

5959
func TestDnetDaemonInvalidParams(t *testing.T) {
60-
if !netutils.IsRunningInContainer() {
60+
if !testutils.IsRunningInContainer() {
6161
t.Skip("This test must run inside a container ")
6262
}
6363
args := []string{dnetCommandName, "-d=false", "-H=tcp:/127.0.0.1:8080"}
@@ -74,7 +74,7 @@ func TestDnetDaemonInvalidParams(t *testing.T) {
7474
}
7575

7676
func TestDnetDefaultsWithFlags(t *testing.T) {
77-
if !netutils.IsRunningInContainer() {
77+
if !testutils.IsRunningInContainer() {
7878
t.Skip("This test must run inside a container ")
7979
}
8080
doneChan := make(chan bool)
@@ -97,7 +97,7 @@ func TestDnetDefaultsWithFlags(t *testing.T) {
9797
}
9898

9999
func TestDnetMain(t *testing.T) {
100-
if !netutils.IsRunningInContainer() {
100+
if !testutils.IsRunningInContainer() {
101101
t.Skip("This test must run inside a container ")
102102
}
103103
customPort := 4568

libnetwork/config/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"testing"
66

77
"github.com/docker/libnetwork/netlabel"
8-
_ "github.com/docker/libnetwork/netutils"
8+
_ "github.com/docker/libnetwork/testutils"
99
)
1010

1111
func TestInvalidConfig(t *testing.T) {

libnetwork/datastore/datastore_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"testing"
77

88
"github.com/docker/libnetwork/config"
9-
_ "github.com/docker/libnetwork/netutils"
109
"github.com/docker/libnetwork/options"
10+
_ "github.com/docker/libnetwork/testutils"
1111
"github.com/stretchr/testify/assert"
1212
)
1313

libnetwork/drivers/bridge/bridge_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import (
1111
"github.com/docker/libnetwork/iptables"
1212
"github.com/docker/libnetwork/netlabel"
1313
"github.com/docker/libnetwork/netutils"
14-
"github.com/docker/libnetwork/osl"
14+
"github.com/docker/libnetwork/testutils"
1515
"github.com/docker/libnetwork/types"
1616
"github.com/vishvananda/netlink"
1717
)
1818

1919
func TestCreateFullOptions(t *testing.T) {
20-
defer osl.SetupTestOSContext(t)()
20+
defer testutils.SetupTestOSContext(t)()
2121
d := newDriver()
2222

2323
config := &configuration{
@@ -69,7 +69,7 @@ func TestCreateFullOptions(t *testing.T) {
6969
}
7070

7171
func TestCreate(t *testing.T) {
72-
defer osl.SetupTestOSContext(t)()
72+
defer testutils.SetupTestOSContext(t)()
7373
d := newDriver()
7474

7575
if err := d.Config(nil); err != nil {
@@ -102,7 +102,7 @@ func TestCreate(t *testing.T) {
102102
}
103103

104104
func TestCreateFail(t *testing.T) {
105-
defer osl.SetupTestOSContext(t)()
105+
defer testutils.SetupTestOSContext(t)()
106106
d := newDriver()
107107

108108
if err := d.Config(nil); err != nil {
@@ -119,7 +119,7 @@ func TestCreateFail(t *testing.T) {
119119
}
120120

121121
func TestCreateMultipleNetworks(t *testing.T) {
122-
defer osl.SetupTestOSContext(t)()
122+
defer testutils.SetupTestOSContext(t)()
123123
d := newDriver()
124124
dd, _ := d.(*driver)
125125

@@ -283,7 +283,7 @@ func TestQueryEndpointInfoHairpin(t *testing.T) {
283283
}
284284

285285
func testQueryEndpointInfo(t *testing.T, ulPxyEnabled bool) {
286-
defer osl.SetupTestOSContext(t)()
286+
defer testutils.SetupTestOSContext(t)()
287287
d := newDriver()
288288
dd, _ := d.(*driver)
289289

@@ -354,7 +354,7 @@ func testQueryEndpointInfo(t *testing.T, ulPxyEnabled bool) {
354354
}
355355

356356
func TestCreateLinkWithOptions(t *testing.T) {
357-
defer osl.SetupTestOSContext(t)()
357+
defer testutils.SetupTestOSContext(t)()
358358
d := newDriver()
359359

360360
if err := d.Config(nil); err != nil {
@@ -413,7 +413,7 @@ func getPortMapping() []types.PortBinding {
413413
}
414414

415415
func TestLinkContainers(t *testing.T) {
416-
defer osl.SetupTestOSContext(t)()
416+
defer testutils.SetupTestOSContext(t)()
417417

418418
d := newDriver()
419419

@@ -630,7 +630,7 @@ func TestValidateConfig(t *testing.T) {
630630
}
631631

632632
func TestSetDefaultGw(t *testing.T) {
633-
defer osl.SetupTestOSContext(t)()
633+
defer testutils.SetupTestOSContext(t)()
634634
d := newDriver()
635635

636636
if err := d.Config(nil); err != nil {

libnetwork/drivers/bridge/interface_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package bridge
33
import (
44
"testing"
55

6-
"github.com/docker/libnetwork/osl"
6+
"github.com/docker/libnetwork/testutils"
77
"github.com/vishvananda/netlink"
88
)
99

1010
func TestInterfaceDefaultName(t *testing.T) {
11-
defer osl.SetupTestOSContext(t)()
11+
defer testutils.SetupTestOSContext(t)()
1212

1313
config := &networkConfiguration{}
1414
if _ = newInterface(config); config.BridgeName != DefaultBridgeName {
@@ -17,7 +17,7 @@ func TestInterfaceDefaultName(t *testing.T) {
1717
}
1818

1919
func TestAddressesEmptyInterface(t *testing.T) {
20-
defer osl.SetupTestOSContext(t)()
20+
defer testutils.SetupTestOSContext(t)()
2121

2222
inf := newInterface(&networkConfiguration{})
2323
addrv4, addrsv6, err := inf.addresses()

0 commit comments

Comments
 (0)