1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

testutil, integration: untangle image dependency

Signed-off-by: Sam Whited <sam@samwhited.com>
This commit is contained in:
Sam Whited 2019-09-24 13:33:03 -05:00
parent 30c5ec4365
commit ae0a878b86
3 changed files with 22 additions and 43 deletions

View file

@ -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"

View file

@ -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
}

View file

@ -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,
})
}