Move fakecontext, fakegit and fakestorage to internal/test
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
13771fede3
commit
062564084a
14 changed files with 83 additions and 48 deletions
|
@ -15,11 +15,11 @@ import (
|
|||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/docker/docker/integration-cli/cli/build/fakestorage"
|
||||
"github.com/docker/docker/integration-cli/daemon"
|
||||
"github.com/docker/docker/integration-cli/environment"
|
||||
testdaemon "github.com/docker/docker/internal/test/daemon"
|
||||
ienv "github.com/docker/docker/internal/test/environment"
|
||||
"github.com/docker/docker/internal/test/fakestorage"
|
||||
"github.com/docker/docker/internal/test/fixtures/plugin"
|
||||
"github.com/docker/docker/internal/test/registry"
|
||||
"github.com/docker/docker/pkg/reexec"
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/integration-cli/cli/build/fakecontext"
|
||||
"github.com/docker/docker/internal/test/fakecontext"
|
||||
"github.com/gotestyourself/gotestyourself/icmd"
|
||||
)
|
||||
|
||||
|
|
|
@ -13,10 +13,10 @@ import (
|
|||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli/build/fakecontext"
|
||||
"github.com/docker/docker/integration-cli/cli/build/fakegit"
|
||||
"github.com/docker/docker/integration-cli/cli/build/fakestorage"
|
||||
"github.com/docker/docker/integration-cli/request"
|
||||
"github.com/docker/docker/internal/test/fakecontext"
|
||||
"github.com/docker/docker/internal/test/fakegit"
|
||||
"github.com/docker/docker/internal/test/fakestorage"
|
||||
"github.com/go-check/check"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
|
|
|
@ -20,9 +20,9 @@ import (
|
|||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/docker/docker/integration-cli/cli/build/fakecontext"
|
||||
"github.com/docker/docker/integration-cli/cli/build/fakegit"
|
||||
"github.com/docker/docker/integration-cli/cli/build/fakestorage"
|
||||
"github.com/docker/docker/internal/test/fakecontext"
|
||||
"github.com/docker/docker/internal/test/fakegit"
|
||||
"github.com/docker/docker/internal/test/fakestorage"
|
||||
"github.com/docker/docker/internal/testutil"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"github.com/go-check/check"
|
||||
|
|
|
@ -18,7 +18,7 @@ import (
|
|||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/docker/docker/integration-cli/cli/build/fakecontext"
|
||||
"github.com/docker/docker/internal/test/fakecontext"
|
||||
units "github.com/docker/go-units"
|
||||
"github.com/go-check/check"
|
||||
"github.com/gotestyourself/gotestyourself/icmd"
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/docker/docker/integration-cli/cli/build/fakecontext"
|
||||
"github.com/docker/docker/internal/test/fakecontext"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/docker/go-connections/nat"
|
||||
"github.com/go-check/check"
|
||||
|
|
|
@ -25,7 +25,7 @@ import (
|
|||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/docker/docker/integration-cli/cli/build/fakecontext"
|
||||
"github.com/docker/docker/internal/test/fakecontext"
|
||||
"github.com/docker/docker/internal/testutil"
|
||||
"github.com/docker/docker/pkg/mount"
|
||||
"github.com/docker/docker/pkg/parsers/kernel"
|
||||
|
|
|
@ -8,9 +8,9 @@ import (
|
|||
"testing"
|
||||
|
||||
dclient "github.com/docker/docker/client"
|
||||
"github.com/docker/docker/integration-cli/cli/build/fakecontext"
|
||||
"github.com/docker/docker/integration-cli/request"
|
||||
"github.com/docker/docker/internal/test/daemon"
|
||||
"github.com/docker/docker/internal/test/fakecontext"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
"github.com/moby/buildkit/session"
|
||||
|
|
|
@ -9,9 +9,9 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/integration-cli/cli/build/fakecontext"
|
||||
"github.com/docker/docker/integration/internal/container"
|
||||
"github.com/docker/docker/internal/test/daemon"
|
||||
"github.com/docker/docker/internal/test/fakecontext"
|
||||
"github.com/docker/docker/pkg/stdcopy"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
|
|
|
@ -13,8 +13,8 @@ import (
|
|||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
"github.com/docker/docker/integration-cli/cli/build/fakecontext"
|
||||
"github.com/docker/docker/integration/internal/request"
|
||||
"github.com/docker/docker/internal/test/fakecontext"
|
||||
"github.com/docker/docker/pkg/jsonmessage"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package fakecontext // import "github.com/docker/docker/integration-cli/cli/build/fakecontext"
|
||||
package fakecontext // import "github.com/docker/docker/internal/test/fakecontext"
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
@ -73,7 +73,7 @@ func WithFiles(files map[string]string) func(*Fake) error {
|
|||
func WithBinaryFiles(files map[string]*bytes.Buffer) func(*Fake) error {
|
||||
return func(fakeContext *Fake) error {
|
||||
for file, content := range files {
|
||||
if err := fakeContext.Add(file, string(content.Bytes())); err != nil {
|
||||
if err := fakeContext.Add(file, content.String()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package fakegit // import "github.com/docker/docker/integration-cli/cli/build/fakegit"
|
||||
package fakegit // import "github.com/docker/docker/internal/test/fakegit"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -9,8 +9,8 @@ import (
|
|||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/docker/docker/integration-cli/cli/build/fakecontext"
|
||||
"github.com/docker/docker/integration-cli/cli/build/fakestorage"
|
||||
"github.com/docker/docker/internal/test/fakecontext"
|
||||
"github.com/docker/docker/internal/test/fakestorage"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
)
|
||||
|
|
@ -1,13 +1,17 @@
|
|||
package fakestorage // import "github.com/docker/docker/integration-cli/cli/build/fakestorage"
|
||||
package fakestorage // import "github.com/docker/docker/internal/test/fakestorage"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
)
|
||||
|
||||
var ensureHTTPServerOnce sync.Once
|
||||
|
@ -70,5 +74,15 @@ func ensureHTTPServerImage(t testingT) {
|
|||
t.Fatalf("could not build http server: %v", string(out))
|
||||
}
|
||||
|
||||
cli.DockerCmd(t, "build", "-q", "-t", "httpserver", tmp)
|
||||
c := testEnv.APIClient()
|
||||
reader, err := archive.TarWithOptions(tmp, &archive.TarOptions{})
|
||||
assert.NilError(t, err)
|
||||
resp, err := c.ImageBuild(context.Background(), reader, types.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
Tags: []string{"httpserver"},
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
_, err = io.Copy(ioutil.Discard, resp.Body)
|
||||
assert.NilError(t, err)
|
||||
}
|
|
@ -1,20 +1,24 @@
|
|||
package fakestorage // import "github.com/docker/docker/integration-cli/cli/build/fakestorage"
|
||||
package fakestorage // import "github.com/docker/docker/internal/test/fakestorage"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/integration-cli/cli"
|
||||
"github.com/docker/docker/integration-cli/cli/build"
|
||||
"github.com/docker/docker/integration-cli/cli/build/fakecontext"
|
||||
"github.com/docker/docker/api/types"
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/docker/docker/integration-cli/request"
|
||||
"github.com/docker/docker/internal/test/environment"
|
||||
"github.com/docker/docker/internal/test/fakecontext"
|
||||
"github.com/docker/docker/internal/testutil"
|
||||
"github.com/docker/go-connections/nat"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
)
|
||||
|
||||
|
@ -62,7 +66,7 @@ func New(t testingT, dir string, modifiers ...func(*fakecontext.Fake) error) Fak
|
|||
case testEnv.IsLocalDaemon():
|
||||
return newLocalFakeStorage(ctx)
|
||||
default:
|
||||
return newRemoteFileServer(t, ctx)
|
||||
return newRemoteFileServer(t, ctx, testEnv.APIClient())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -101,6 +105,7 @@ type remoteFileServer struct {
|
|||
host string // hostname/port web server is listening to on docker host e.g. 0.0.0.0:43712
|
||||
container string
|
||||
image string
|
||||
client client.APIClient
|
||||
ctx *fakecontext.Fake
|
||||
}
|
||||
|
||||
|
@ -121,18 +126,26 @@ func (f *remoteFileServer) Close() error {
|
|||
f.ctx.Close()
|
||||
}
|
||||
if f.image != "" {
|
||||
if err := cli.Docker(cli.Args("rmi", "-f", f.image)).Error; err != nil {
|
||||
if _, err := f.client.ImageRemove(context.Background(), f.image, types.ImageRemoveOptions{
|
||||
Force: true,
|
||||
}); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error closing remote file server : %v\n", err)
|
||||
}
|
||||
}
|
||||
if err := f.client.Close(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error closing remote file server : %v\n", err)
|
||||
}
|
||||
}()
|
||||
if f.container == "" {
|
||||
return nil
|
||||
}
|
||||
return cli.Docker(cli.Args("rm", "-fv", f.container)).Error
|
||||
return f.client.ContainerRemove(context.Background(), f.container, types.ContainerRemoveOptions{
|
||||
Force: true,
|
||||
RemoveVolumes: true,
|
||||
})
|
||||
}
|
||||
|
||||
func newRemoteFileServer(t testingT, ctx *fakecontext.Fake) *remoteFileServer {
|
||||
func newRemoteFileServer(t testingT, ctx *fakecontext.Fake, c client.APIClient) *remoteFileServer {
|
||||
var (
|
||||
image = fmt.Sprintf("fileserver-img-%s", strings.ToLower(testutil.GenerateRandomAlphaOnlyString(10)))
|
||||
container = fmt.Sprintf("fileserver-cnt-%s", strings.ToLower(testutil.GenerateRandomAlphaOnlyString(10)))
|
||||
|
@ -145,31 +158,39 @@ func newRemoteFileServer(t testingT, ctx *fakecontext.Fake) *remoteFileServer {
|
|||
COPY . /static`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cli.BuildCmd(t, image, build.WithoutCache, build.WithExternalBuildContext(ctx))
|
||||
resp, err := c.ImageBuild(context.Background(), ctx.AsTarReader(t), types.ImageBuildOptions{
|
||||
NoCache: true,
|
||||
Tags: []string{image},
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
_, err = io.Copy(ioutil.Discard, resp.Body)
|
||||
assert.NilError(t, err)
|
||||
|
||||
// Start the container
|
||||
cli.DockerCmd(t, "run", "-d", "-P", "--name", container, image)
|
||||
b, err := c.ContainerCreate(context.Background(), &containertypes.Config{
|
||||
Image: image,
|
||||
}, &containertypes.HostConfig{}, nil, container)
|
||||
assert.NilError(t, err)
|
||||
err = c.ContainerStart(context.Background(), b.ID, types.ContainerStartOptions{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
// Find out the system assigned port
|
||||
out := cli.DockerCmd(t, "port", container, "80/tcp").Combined()
|
||||
fileserverHostPort := strings.Trim(out, "\n")
|
||||
_, port, err := net.SplitHostPort(fileserverHostPort)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to parse file server host:port: %v", err)
|
||||
}
|
||||
|
||||
dockerHostURL, err := url.Parse(request.DaemonHost())
|
||||
if err != nil {
|
||||
t.Fatalf("unable to parse daemon host URL: %v", err)
|
||||
}
|
||||
host, _, err := net.SplitHostPort(dockerHostURL.Host)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to parse docker daemon host:port: %v", err)
|
||||
i, err := c.ContainerInspect(context.Background(), b.ID)
|
||||
assert.NilError(t, err)
|
||||
newP, err := nat.NewPort("tcp", "80")
|
||||
assert.NilError(t, err)
|
||||
ports, exists := i.NetworkSettings.Ports[newP]
|
||||
if !exists || len(ports) != 1 {
|
||||
t.Fatalf("unable to find port 80/tcp for %s", container)
|
||||
}
|
||||
host := ports[0].HostIP
|
||||
port := ports[0].HostPort
|
||||
|
||||
return &remoteFileServer{
|
||||
container: container,
|
||||
image: image,
|
||||
host: fmt.Sprintf("%s:%s", host, port),
|
||||
ctx: ctx}
|
||||
ctx: ctx,
|
||||
client: c,
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue