mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #35248 from tophj-ibm/add-integration-testsetup
[integration] add setupTest to integration test
This commit is contained in:
commit
78cd8e8d18
9 changed files with 47 additions and 11 deletions
|
@ -17,6 +17,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBuildWithRemoveAndForceRemove(t *testing.T) {
|
func TestBuildWithRemoveAndForceRemove(t *testing.T) {
|
||||||
|
defer setupTest(t)()
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
name string
|
name string
|
||||||
|
|
|
@ -17,6 +17,11 @@ func TestMain(m *testing.M) {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
err = environment.EnsureFrozenImagesLinux(testEnv)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
testEnv.Print()
|
testEnv.Print()
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
|
|
|
@ -17,6 +17,11 @@ func TestMain(m *testing.M) {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
err = environment.EnsureFrozenImagesLinux(testEnv)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
testEnv.Print()
|
testEnv.Print()
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
|
|
|
@ -17,6 +17,11 @@ func TestMain(m *testing.M) {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
err = environment.EnsureFrozenImagesLinux(testEnv)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
testEnv.Print()
|
testEnv.Print()
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
|
|
|
@ -33,6 +33,11 @@ func TestMain(m *testing.M) {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
err = environment.EnsureFrozenImagesLinux(testEnv)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
testEnv.Print()
|
testEnv.Print()
|
||||||
setupSuite()
|
setupSuite()
|
||||||
|
|
|
@ -19,6 +19,11 @@ func TestMain(m *testing.M) {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
err = environment.EnsureFrozenImagesLinux(testEnv)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
testEnv.Print()
|
testEnv.Print()
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
|
|
|
@ -17,6 +17,11 @@ func TestMain(m *testing.M) {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
err = environment.EnsureFrozenImagesLinux(testEnv)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
testEnv.Print()
|
testEnv.Print()
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
|
"github.com/docker/docker/integration-cli/fixtures/load"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
@ -128,3 +129,15 @@ func (e *Execution) Print() {
|
||||||
func (e *Execution) APIClient() client.APIClient {
|
func (e *Execution) APIClient() client.APIClient {
|
||||||
return e.client
|
return e.client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EnsureFrozenImagesLinux loads frozen test images into the daemon
|
||||||
|
// if they aren't already loaded
|
||||||
|
func EnsureFrozenImagesLinux(testEnv *Execution) error {
|
||||||
|
if testEnv.OSType == "linux" {
|
||||||
|
err := load.FrozenImagesLinux(testEnv.APIClient(), frozenImages...)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error loading frozen images")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -6,10 +6,11 @@ import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
dclient "github.com/docker/docker/client"
|
dclient "github.com/docker/docker/client"
|
||||||
"github.com/docker/docker/integration-cli/fixtures/load"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var frozenImages = []string{"busybox:latest", "hello-world:frozen", "debian:jessie"}
|
||||||
|
|
||||||
type protectedElements struct {
|
type protectedElements struct {
|
||||||
containers map[string]struct{}
|
containers map[string]struct{}
|
||||||
images map[string]struct{}
|
images map[string]struct{}
|
||||||
|
@ -83,7 +84,7 @@ func ProtectImages(t testingT, testEnv *Execution) {
|
||||||
images := getExistingImages(t, testEnv)
|
images := getExistingImages(t, testEnv)
|
||||||
|
|
||||||
if testEnv.OSType == "linux" {
|
if testEnv.OSType == "linux" {
|
||||||
images = append(images, ensureFrozenImagesLinux(t, testEnv)...)
|
images = append(images, frozenImages...)
|
||||||
}
|
}
|
||||||
testEnv.ProtectImage(t, images...)
|
testEnv.ProtectImage(t, images...)
|
||||||
}
|
}
|
||||||
|
@ -120,15 +121,6 @@ func tagsFromImageSummary(image types.ImageSummary) []string {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func ensureFrozenImagesLinux(t testingT, testEnv *Execution) []string {
|
|
||||||
images := []string{"busybox:latest", "hello-world:frozen", "debian:jessie"}
|
|
||||||
err := load.FrozenImagesLinux(testEnv.APIClient(), images...)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Failed to load frozen images: %s", err)
|
|
||||||
}
|
|
||||||
return images
|
|
||||||
}
|
|
||||||
|
|
||||||
// ProtectNetwork adds the specified network(s) to be protected in case of
|
// ProtectNetwork adds the specified network(s) to be protected in case of
|
||||||
// clean
|
// clean
|
||||||
func (e *Execution) ProtectNetwork(t testingT, networks ...string) {
|
func (e *Execution) ProtectNetwork(t testingT, networks ...string) {
|
||||||
|
|
Loading…
Reference in a new issue