Procházet zdrojové kódy

testutil, integration: untangle image dependency

Signed-off-by: Sam Whited <sam@samwhited.com>
Sam Whited před 5 roky
rodič
revize
ae0a878b86

+ 22 - 2
integration/image/remove_unix_test.go

@@ -7,6 +7,8 @@ import (
 	"io"
 	"io/ioutil"
 	"os"
+	"path/filepath"
+	"runtime"
 	"strconv"
 	"strings"
 	"syscall"
@@ -14,6 +16,10 @@ import (
 	"unsafe"
 
 	"github.com/docker/docker/api/types"
+	_ "github.com/docker/docker/daemon/graphdriver/register" // register graph drivers
+	"github.com/docker/docker/daemon/images"
+	"github.com/docker/docker/layer"
+	"github.com/docker/docker/pkg/idtools"
 	"github.com/docker/docker/testutil/daemon"
 	"github.com/docker/docker/testutil/fakecontext"
 	"gotest.tools/assert"
@@ -31,13 +37,27 @@ func TestRemoveImageGarbageCollector(t *testing.T) {
 
 	// Create daemon with overlay2 graphdriver because vfs uses disk differently
 	// and this test case would not work with it.
-	d := daemon.New(t, daemon.WithStorageDriver("overlay2"), daemon.WithImageService)
+	d := daemon.New(t, daemon.WithStorageDriver("overlay2"))
 	d.Start(t)
 	defer d.Stop(t)
 
 	ctx := context.Background()
 	client := d.NewClientT(t)
-	i := d.ImageService()
+
+	layerStores := make(map[string]layer.Store)
+	layerStores[runtime.GOOS], _ = layer.NewStoreFromOptions(layer.StoreOptions{
+		Root:                      d.Root,
+		MetadataStorePathTemplate: filepath.Join(d.RootDir(), "image", "%s", "layerdb"),
+		GraphDriver:               d.StorageDriver(),
+		GraphDriverOptions:        nil,
+		IDMapping:                 &idtools.IdentityMapping{},
+		PluginGetter:              nil,
+		ExperimentalEnabled:       false,
+		OS:                        runtime.GOOS,
+	})
+	i := images.NewImageService(images.ImageServiceConfig{
+		LayerStores: layerStores,
+	})
 
 	img := "test-garbage-collector"
 

+ 0 - 7
testutil/daemon/daemon.go

@@ -17,7 +17,6 @@ import (
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types/events"
 	"github.com/docker/docker/client"
-	"github.com/docker/docker/daemon/images"
 	"github.com/docker/docker/opts"
 	"github.com/docker/docker/pkg/ioutils"
 	"github.com/docker/docker/pkg/stringid"
@@ -72,7 +71,6 @@ type Daemon struct {
 	init                       bool
 	dockerdBinary              string
 	log                        logT
-	imageService               *images.ImageService
 
 	// swarm related field
 	swarmListenAddr string
@@ -721,8 +719,3 @@ func cleanupRaftDir(t testing.TB, rootPath string) {
 		}
 	}
 }
-
-// ImageService returns the Daemon's ImageService
-func (d *Daemon) ImageService() *images.ImageService {
-	return d.imageService
-}

+ 0 - 34
testutil/daemon/ops_unix.go

@@ -1,34 +0,0 @@
-// +build !windows
-
-package daemon
-
-import (
-	"path/filepath"
-	"runtime"
-
-	"github.com/docker/docker/daemon/images"
-	"github.com/docker/docker/layer"
-
-	// register graph drivers
-	_ "github.com/docker/docker/daemon/graphdriver/register"
-	"github.com/docker/docker/pkg/idtools"
-)
-
-// WithImageService sets imageService options
-func WithImageService(d *Daemon) {
-	layerStores := make(map[string]layer.Store)
-	os := runtime.GOOS
-	layerStores[os], _ = layer.NewStoreFromOptions(layer.StoreOptions{
-		Root:                      d.Root,
-		MetadataStorePathTemplate: filepath.Join(d.RootDir(), "image", "%s", "layerdb"),
-		GraphDriver:               d.storageDriver,
-		GraphDriverOptions:        nil,
-		IDMapping:                 &idtools.IdentityMapping{},
-		PluginGetter:              nil,
-		ExperimentalEnabled:       false,
-		OS:                        os,
-	})
-	d.imageService = images.NewImageService(images.ImageServiceConfig{
-		LayerStores: layerStores,
-	})
-}