Browse code

Rename integration/util to integration/internal

Both names have no real sense, but one allows to make sure these packages
aren't used outside of `integration`.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Vincent Demeester authored on 2018/02/10 03:13:26
Showing 35 changed files
... ...
@@ -17,7 +17,7 @@ source "$MAKEDIR/.go-autogen"
17 17
 
18 18
 integration_api_dirs=${TEST_INTEGRATION_DIR:-"$(
19 19
 	find ./integration -type d |
20
-	grep -vE '(^./integration($|/util)|/testdata)')"}
20
+	grep -vE '(^./integration($|/internal)|/testdata)')"}
21 21
 
22 22
 run_test_integration() {
23 23
 	[[ "$TESTFLAGS" != *-check.f* ]] && run_test_integration_suites
... ...
@@ -13,7 +13,7 @@ import (
13 13
 	"github.com/docker/docker/api/types"
14 14
 	"github.com/docker/docker/api/types/filters"
15 15
 	"github.com/docker/docker/integration-cli/cli/build/fakecontext"
16
-	"github.com/docker/docker/integration/util/request"
16
+	"github.com/docker/docker/integration/internal/request"
17 17
 	"github.com/docker/docker/pkg/jsonmessage"
18 18
 	"github.com/stretchr/testify/assert"
19 19
 	"github.com/stretchr/testify/require"
... ...
@@ -7,7 +7,7 @@ import (
7 7
 
8 8
 	"github.com/docker/docker/api/types/container"
9 9
 	"github.com/docker/docker/api/types/network"
10
-	"github.com/docker/docker/integration/util/request"
10
+	"github.com/docker/docker/integration/internal/request"
11 11
 	"github.com/docker/docker/internal/testutil"
12 12
 	"github.com/gotestyourself/gotestyourself/skip"
13 13
 )
... ...
@@ -9,7 +9,7 @@ import (
9 9
 	"github.com/docker/docker/api/types/container"
10 10
 	"github.com/docker/docker/api/types/network"
11 11
 	"github.com/docker/docker/api/types/strslice"
12
-	"github.com/docker/docker/integration/util/request"
12
+	"github.com/docker/docker/integration/internal/request"
13 13
 	"github.com/stretchr/testify/require"
14 14
 )
15 15
 
... ...
@@ -10,7 +10,7 @@ import (
10 10
 	"github.com/docker/docker/api/types/network"
11 11
 	"github.com/docker/docker/api/types/strslice"
12 12
 	"github.com/docker/docker/client"
13
-	"github.com/docker/docker/integration/util/request"
13
+	"github.com/docker/docker/integration/internal/request"
14 14
 	"github.com/gotestyourself/gotestyourself/poll"
15 15
 	"github.com/stretchr/testify/require"
16 16
 )
... ...
@@ -9,7 +9,7 @@ import (
9 9
 	"github.com/docker/docker/api/types/container"
10 10
 	"github.com/docker/docker/api/types/network"
11 11
 	"github.com/docker/docker/client"
12
-	"github.com/docker/docker/integration/util/request"
12
+	"github.com/docker/docker/integration/internal/request"
13 13
 	"github.com/gotestyourself/gotestyourself/poll"
14 14
 	"github.com/gotestyourself/gotestyourself/skip"
15 15
 	"github.com/stretchr/testify/assert"
... ...
@@ -10,7 +10,7 @@ import (
10 10
 	"github.com/docker/docker/api/types/network"
11 11
 	"github.com/docker/docker/api/types/strslice"
12 12
 	"github.com/docker/docker/client"
13
-	"github.com/docker/docker/integration/util/request"
13
+	"github.com/docker/docker/integration/internal/request"
14 14
 	"github.com/gotestyourself/gotestyourself/poll"
15 15
 	"github.com/gotestyourself/gotestyourself/skip"
16 16
 	"github.com/stretchr/testify/require"
... ...
@@ -10,7 +10,7 @@ import (
10 10
 
11 11
 	"github.com/docker/docker/api/types"
12 12
 	"github.com/docker/docker/api/types/container"
13
-	"github.com/docker/docker/integration/util/request"
13
+	"github.com/docker/docker/integration/internal/request"
14 14
 	"github.com/docker/docker/pkg/stdcopy"
15 15
 	"github.com/gotestyourself/gotestyourself/poll"
16 16
 	"github.com/gotestyourself/gotestyourself/skip"
... ...
@@ -14,7 +14,7 @@ import (
14 14
 	"github.com/docker/docker/api/types"
15 15
 	"github.com/docker/docker/api/types/container"
16 16
 	"github.com/docker/docker/api/types/network"
17
-	"github.com/docker/docker/integration/util/request"
17
+	"github.com/docker/docker/integration/internal/request"
18 18
 	"github.com/docker/go-connections/nat"
19 19
 	"github.com/gotestyourself/gotestyourself/poll"
20 20
 	"github.com/gotestyourself/gotestyourself/skip"
... ...
@@ -8,7 +8,7 @@ import (
8 8
 	"github.com/docker/docker/api/types/container"
9 9
 	"github.com/docker/docker/api/types/filters"
10 10
 	"github.com/docker/docker/api/types/network"
11
-	"github.com/docker/docker/integration/util/request"
11
+	"github.com/docker/docker/integration/internal/request"
12 12
 	"github.com/stretchr/testify/assert"
13 13
 	"github.com/stretchr/testify/require"
14 14
 )
... ...
@@ -8,7 +8,7 @@ import (
8 8
 	"github.com/docker/docker/api/types"
9 9
 	"github.com/docker/docker/api/types/container"
10 10
 	"github.com/docker/docker/api/types/network"
11
-	"github.com/docker/docker/integration/util/request"
11
+	"github.com/docker/docker/integration/internal/request"
12 12
 	"github.com/docker/docker/internal/testutil"
13 13
 	"github.com/docker/docker/pkg/stringid"
14 14
 	"github.com/gotestyourself/gotestyourself/poll"
... ...
@@ -10,7 +10,7 @@ import (
10 10
 	"github.com/docker/docker/api/types/container"
11 11
 	"github.com/docker/docker/api/types/network"
12 12
 	req "github.com/docker/docker/integration-cli/request"
13
-	"github.com/docker/docker/integration/util/request"
13
+	"github.com/docker/docker/integration/internal/request"
14 14
 	"github.com/docker/docker/internal/testutil"
15 15
 	"github.com/gotestyourself/gotestyourself/poll"
16 16
 	"github.com/stretchr/testify/assert"
... ...
@@ -10,7 +10,7 @@ import (
10 10
 	"github.com/docker/docker/api/types"
11 11
 	"github.com/docker/docker/api/types/container"
12 12
 	"github.com/docker/docker/api/types/network"
13
-	"github.com/docker/docker/integration/util/request"
13
+	"github.com/docker/docker/integration/internal/request"
14 14
 	"github.com/gotestyourself/gotestyourself/poll"
15 15
 	"github.com/gotestyourself/gotestyourself/skip"
16 16
 	"github.com/stretchr/testify/assert"
... ...
@@ -11,7 +11,7 @@ import (
11 11
 	"github.com/docker/docker/api/types/container"
12 12
 	"github.com/docker/docker/api/types/network"
13 13
 	"github.com/docker/docker/client"
14
-	"github.com/docker/docker/integration/util/request"
14
+	"github.com/docker/docker/integration/internal/request"
15 15
 	"github.com/gotestyourself/gotestyourself/icmd"
16 16
 	"github.com/gotestyourself/gotestyourself/poll"
17 17
 	"github.com/gotestyourself/gotestyourself/skip"
... ...
@@ -14,7 +14,7 @@ import (
14 14
 	"github.com/docker/docker/api/types/container"
15 15
 	"github.com/docker/docker/api/types/strslice"
16 16
 	"github.com/docker/docker/client"
17
-	"github.com/docker/docker/integration/util/request"
17
+	"github.com/docker/docker/integration/internal/request"
18 18
 	"github.com/docker/docker/pkg/stdcopy"
19 19
 	"github.com/gotestyourself/gotestyourself/poll"
20 20
 	"github.com/gotestyourself/gotestyourself/skip"
... ...
@@ -6,7 +6,7 @@ import (
6 6
 
7 7
 	"github.com/docker/docker/api/types"
8 8
 	"github.com/docker/docker/api/types/container"
9
-	"github.com/docker/docker/integration/util/request"
9
+	"github.com/docker/docker/integration/internal/request"
10 10
 	"github.com/stretchr/testify/assert"
11 11
 	"github.com/stretchr/testify/require"
12 12
 )
... ...
@@ -9,7 +9,7 @@ import (
9 9
 	"testing"
10 10
 
11 11
 	"github.com/docker/docker/api/types"
12
-	"github.com/docker/docker/integration/util/request"
12
+	"github.com/docker/docker/integration/internal/request"
13 13
 	"github.com/docker/docker/internal/testutil"
14 14
 )
15 15
 
16 16
new file mode 100644
... ...
@@ -0,0 +1,51 @@
0
+package request // import "github.com/docker/docker/integration/internal/request"
1
+
2
+import (
3
+	"net"
4
+	"net/http"
5
+	"testing"
6
+	"time"
7
+
8
+	"github.com/docker/docker/client"
9
+	"github.com/docker/go-connections/sockets"
10
+	"github.com/docker/go-connections/tlsconfig"
11
+	"github.com/stretchr/testify/require"
12
+)
13
+
14
+// NewAPIClient returns a docker API client configured from environment variables
15
+func NewAPIClient(t *testing.T, ops ...func(*client.Client) error) client.APIClient {
16
+	ops = append([]func(*client.Client) error{client.FromEnv}, ops...)
17
+	clt, err := client.NewClientWithOpts(ops...)
18
+	require.NoError(t, err)
19
+	return clt
20
+}
21
+
22
+// NewTLSAPIClient returns a docker API client configured with the
23
+// provided TLS settings
24
+func NewTLSAPIClient(t *testing.T, host, cacertPath, certPath, keyPath string) (client.APIClient, error) {
25
+	opts := tlsconfig.Options{
26
+		CAFile:             cacertPath,
27
+		CertFile:           certPath,
28
+		KeyFile:            keyPath,
29
+		ExclusiveRootPools: true,
30
+	}
31
+	config, err := tlsconfig.Client(opts)
32
+	require.Nil(t, err)
33
+	tr := &http.Transport{
34
+		TLSClientConfig: config,
35
+		DialContext: (&net.Dialer{
36
+			KeepAlive: 30 * time.Second,
37
+			Timeout:   30 * time.Second,
38
+		}).DialContext,
39
+	}
40
+	proto, addr, _, err := client.ParseHost(host)
41
+	require.Nil(t, err)
42
+
43
+	sockets.ConfigureTransport(tr, proto, addr)
44
+
45
+	httpClient := &http.Client{
46
+		Transport:     tr,
47
+		CheckRedirect: client.CheckRedirect,
48
+	}
49
+	return client.NewClientWithOpts(client.WithHost(host), client.WithHTTPClient(httpClient))
50
+}
0 51
new file mode 100644
... ...
@@ -0,0 +1,26 @@
0
+package requirement // import "github.com/docker/docker/integration/internal/requirement"
1
+
2
+import (
3
+	"net/http"
4
+	"strings"
5
+	"testing"
6
+	"time"
7
+)
8
+
9
+// HasHubConnectivity checks to see if https://hub.docker.com is
10
+// accessible from the present environment
11
+func HasHubConnectivity(t *testing.T) bool {
12
+	// Set a timeout on the GET at 15s
13
+	var timeout = 15 * time.Second
14
+	var url = "https://hub.docker.com"
15
+
16
+	client := http.Client{Timeout: timeout}
17
+	resp, err := client.Get(url)
18
+	if err != nil && strings.Contains(err.Error(), "use of closed network connection") {
19
+		t.Fatalf("Timeout for GET request on %s", url)
20
+	}
21
+	if resp != nil {
22
+		resp.Body.Close()
23
+	}
24
+	return err == nil
25
+}
0 26
new file mode 100644
... ...
@@ -0,0 +1,36 @@
0
+package swarm
1
+
2
+import (
3
+	"fmt"
4
+	"testing"
5
+
6
+	swarmtypes "github.com/docker/docker/api/types/swarm"
7
+	"github.com/docker/docker/integration-cli/daemon"
8
+	"github.com/docker/docker/internal/test/environment"
9
+	"github.com/stretchr/testify/require"
10
+)
11
+
12
+const (
13
+	dockerdBinary    = "dockerd"
14
+	defaultSwarmPort = 2477
15
+)
16
+
17
+// NewSwarm creates a swarm daemon for testing
18
+func NewSwarm(t *testing.T, testEnv *environment.Execution) *daemon.Swarm {
19
+	d := &daemon.Swarm{
20
+		Daemon: daemon.New(t, "", dockerdBinary, daemon.Config{
21
+			Experimental: testEnv.DaemonInfo.ExperimentalBuild,
22
+		}),
23
+		// TODO: better method of finding an unused port
24
+		Port: defaultSwarmPort,
25
+	}
26
+	// TODO: move to a NewSwarm constructor
27
+	d.ListenAddr = fmt.Sprintf("0.0.0.0:%d", d.Port)
28
+
29
+	// avoid networking conflicts
30
+	args := []string{"--iptables=false", "--swarm-default-advertise-addr=lo"}
31
+	d.StartWithBusybox(t, args...)
32
+
33
+	require.NoError(t, d.Init(swarmtypes.InitRequest{}))
34
+	return d
35
+}
... ...
@@ -5,7 +5,7 @@ import (
5 5
 	"testing"
6 6
 
7 7
 	"github.com/docker/docker/api/types"
8
-	"github.com/docker/docker/integration/util/request"
8
+	"github.com/docker/docker/integration/internal/request"
9 9
 	"github.com/stretchr/testify/assert"
10 10
 	"github.com/stretchr/testify/require"
11 11
 )
... ...
@@ -23,7 +23,7 @@ import (
23 23
 	eventtypes "github.com/docker/docker/api/types/events"
24 24
 	networktypes "github.com/docker/docker/api/types/network"
25 25
 	"github.com/docker/docker/client"
26
-	"github.com/docker/docker/integration/util/request"
26
+	"github.com/docker/docker/integration/internal/request"
27 27
 	"github.com/docker/docker/internal/test/environment"
28 28
 	"github.com/docker/docker/pkg/authorization"
29 29
 	"github.com/gotestyourself/gotestyourself/skip"
... ...
@@ -16,7 +16,7 @@ import (
16 16
 	networktypes "github.com/docker/docker/api/types/network"
17 17
 	volumetypes "github.com/docker/docker/api/types/volume"
18 18
 	"github.com/docker/docker/client"
19
-	"github.com/docker/docker/integration/util/requirement"
19
+	"github.com/docker/docker/integration/internal/requirement"
20 20
 	"github.com/gotestyourself/gotestyourself/skip"
21 21
 	"github.com/stretchr/testify/require"
22 22
 )
... ...
@@ -8,7 +8,7 @@ import (
8 8
 	"github.com/docker/docker/api/types/filters"
9 9
 	swarmtypes "github.com/docker/docker/api/types/swarm"
10 10
 	"github.com/docker/docker/client"
11
-	"github.com/docker/docker/integration/util/swarm"
11
+	"github.com/docker/docker/integration/internal/swarm"
12 12
 	"github.com/gotestyourself/gotestyourself/skip"
13 13
 	"github.com/stretchr/testify/assert"
14 14
 	"github.com/stretchr/testify/require"
... ...
@@ -10,7 +10,7 @@ import (
10 10
 	"github.com/docker/docker/api/types/filters"
11 11
 	swarmtypes "github.com/docker/docker/api/types/swarm"
12 12
 	"github.com/docker/docker/client"
13
-	"github.com/docker/docker/integration/util/swarm"
13
+	"github.com/docker/docker/integration/internal/swarm"
14 14
 	"github.com/gotestyourself/gotestyourself/poll"
15 15
 	"github.com/stretchr/testify/assert"
16 16
 	"github.com/stretchr/testify/require"
... ...
@@ -9,7 +9,7 @@ import (
9 9
 	"github.com/docker/docker/api/types/filters"
10 10
 	swarmtypes "github.com/docker/docker/api/types/swarm"
11 11
 	"github.com/docker/docker/client"
12
-	"github.com/docker/docker/integration/util/swarm"
12
+	"github.com/docker/docker/integration/internal/swarm"
13 13
 	"github.com/gotestyourself/gotestyourself/poll"
14 14
 	"github.com/gotestyourself/gotestyourself/skip"
15 15
 	"github.com/stretchr/testify/assert"
... ...
@@ -8,7 +8,7 @@ import (
8 8
 	"github.com/docker/docker/api/types/container"
9 9
 	"github.com/docker/docker/api/types/network"
10 10
 	"github.com/docker/docker/client"
11
-	"github.com/docker/docker/integration/util/swarm"
11
+	"github.com/docker/docker/integration/internal/swarm"
12 12
 	"github.com/stretchr/testify/assert"
13 13
 	"github.com/stretchr/testify/require"
14 14
 )
... ...
@@ -11,7 +11,7 @@ import (
11 11
 	"github.com/docker/docker/api/types/filters"
12 12
 	"github.com/docker/docker/api/types/network"
13 13
 	"github.com/docker/docker/api/types/strslice"
14
-	"github.com/docker/docker/integration/util/request"
14
+	"github.com/docker/docker/integration/internal/request"
15 15
 	"github.com/stretchr/testify/require"
16 16
 )
17 17
 
... ...
@@ -7,7 +7,7 @@ import (
7 7
 	"testing"
8 8
 
9 9
 	req "github.com/docker/docker/integration-cli/request"
10
-	"github.com/docker/docker/integration/util/request"
10
+	"github.com/docker/docker/integration/internal/request"
11 11
 	"github.com/stretchr/testify/assert"
12 12
 	"github.com/stretchr/testify/require"
13 13
 	"golang.org/x/net/context"
... ...
@@ -4,7 +4,7 @@ import (
4 4
 	"fmt"
5 5
 	"testing"
6 6
 
7
-	"github.com/docker/docker/integration/util/request"
7
+	"github.com/docker/docker/integration/internal/request"
8 8
 	"github.com/stretchr/testify/assert"
9 9
 	"github.com/stretchr/testify/require"
10 10
 	"golang.org/x/net/context"
... ...
@@ -4,8 +4,8 @@ import (
4 4
 	"testing"
5 5
 
6 6
 	"github.com/docker/docker/api/types"
7
-	"github.com/docker/docker/integration/util/request"
8
-	"github.com/docker/docker/integration/util/requirement"
7
+	"github.com/docker/docker/integration/internal/request"
8
+	"github.com/docker/docker/integration/internal/requirement"
9 9
 	"github.com/gotestyourself/gotestyourself/skip"
10 10
 	"github.com/stretchr/testify/assert"
11 11
 	"golang.org/x/net/context"
... ...
@@ -3,7 +3,7 @@ package system // import "github.com/docker/docker/integration/system"
3 3
 import (
4 4
 	"testing"
5 5
 
6
-	"github.com/docker/docker/integration/util/request"
6
+	"github.com/docker/docker/integration/internal/request"
7 7
 	"github.com/stretchr/testify/assert"
8 8
 	"github.com/stretchr/testify/require"
9 9
 	"golang.org/x/net/context"
10 10
deleted file mode 100644
... ...
@@ -1,51 +0,0 @@
1
-package request // import "github.com/docker/docker/integration/util/request"
2
-
3
-import (
4
-	"net"
5
-	"net/http"
6
-	"testing"
7
-	"time"
8
-
9
-	"github.com/docker/docker/client"
10
-	"github.com/docker/go-connections/sockets"
11
-	"github.com/docker/go-connections/tlsconfig"
12
-	"github.com/stretchr/testify/require"
13
-)
14
-
15
-// NewAPIClient returns a docker API client configured from environment variables
16
-func NewAPIClient(t *testing.T, ops ...func(*client.Client) error) client.APIClient {
17
-	ops = append([]func(*client.Client) error{client.FromEnv}, ops...)
18
-	clt, err := client.NewClientWithOpts(ops...)
19
-	require.NoError(t, err)
20
-	return clt
21
-}
22
-
23
-// NewTLSAPIClient returns a docker API client configured with the
24
-// provided TLS settings
25
-func NewTLSAPIClient(t *testing.T, host, cacertPath, certPath, keyPath string) (client.APIClient, error) {
26
-	opts := tlsconfig.Options{
27
-		CAFile:             cacertPath,
28
-		CertFile:           certPath,
29
-		KeyFile:            keyPath,
30
-		ExclusiveRootPools: true,
31
-	}
32
-	config, err := tlsconfig.Client(opts)
33
-	require.Nil(t, err)
34
-	tr := &http.Transport{
35
-		TLSClientConfig: config,
36
-		DialContext: (&net.Dialer{
37
-			KeepAlive: 30 * time.Second,
38
-			Timeout:   30 * time.Second,
39
-		}).DialContext,
40
-	}
41
-	proto, addr, _, err := client.ParseHost(host)
42
-	require.Nil(t, err)
43
-
44
-	sockets.ConfigureTransport(tr, proto, addr)
45
-
46
-	httpClient := &http.Client{
47
-		Transport:     tr,
48
-		CheckRedirect: client.CheckRedirect,
49
-	}
50
-	return client.NewClientWithOpts(client.WithHost(host), client.WithHTTPClient(httpClient))
51
-}
52 1
deleted file mode 100644
... ...
@@ -1,26 +0,0 @@
1
-package requirement // import "github.com/docker/docker/integration/util/requirement"
2
-
3
-import (
4
-	"net/http"
5
-	"strings"
6
-	"testing"
7
-	"time"
8
-)
9
-
10
-// HasHubConnectivity checks to see if https://hub.docker.com is
11
-// accessible from the present environment
12
-func HasHubConnectivity(t *testing.T) bool {
13
-	// Set a timeout on the GET at 15s
14
-	var timeout = 15 * time.Second
15
-	var url = "https://hub.docker.com"
16
-
17
-	client := http.Client{Timeout: timeout}
18
-	resp, err := client.Get(url)
19
-	if err != nil && strings.Contains(err.Error(), "use of closed network connection") {
20
-		t.Fatalf("Timeout for GET request on %s", url)
21
-	}
22
-	if resp != nil {
23
-		resp.Body.Close()
24
-	}
25
-	return err == nil
26
-}
27 1
deleted file mode 100644
... ...
@@ -1,36 +0,0 @@
1
-package swarm
2
-
3
-import (
4
-	"fmt"
5
-	"testing"
6
-
7
-	swarmtypes "github.com/docker/docker/api/types/swarm"
8
-	"github.com/docker/docker/integration-cli/daemon"
9
-	"github.com/docker/docker/internal/test/environment"
10
-	"github.com/stretchr/testify/require"
11
-)
12
-
13
-const (
14
-	dockerdBinary    = "dockerd"
15
-	defaultSwarmPort = 2477
16
-)
17
-
18
-// NewSwarm creates a swarm daemon for testing
19
-func NewSwarm(t *testing.T, testEnv *environment.Execution) *daemon.Swarm {
20
-	d := &daemon.Swarm{
21
-		Daemon: daemon.New(t, "", dockerdBinary, daemon.Config{
22
-			Experimental: testEnv.DaemonInfo.ExperimentalBuild,
23
-		}),
24
-		// TODO: better method of finding an unused port
25
-		Port: defaultSwarmPort,
26
-	}
27
-	// TODO: move to a NewSwarm constructor
28
-	d.ListenAddr = fmt.Sprintf("0.0.0.0:%d", d.Port)
29
-
30
-	// avoid networking conflicts
31
-	args := []string{"--iptables=false", "--swarm-default-advertise-addr=lo"}
32
-	d.StartWithBusybox(t, args...)
33
-
34
-	require.NoError(t, d.Init(swarmtypes.InitRequest{}))
35
-	return d
36
-}