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

Merge pull request #12282 from cpuguy83/remove_some_integration_tests

Move integration/server_test tests to integration-cli
This commit is contained in:
Alexander Morozov 2015-04-14 11:55:05 -07:00
commit 676bf4afa5
5 changed files with 113 additions and 71 deletions

View file

@ -2,6 +2,7 @@ package main
import (
"encoding/json"
"net/url"
"testing"
"github.com/docker/docker/api/types"
@ -24,3 +25,45 @@ func TestLegacyImages(t *testing.T) {
logDone("images - checking legacy json")
}
func TestApiImagesFilter(t *testing.T) {
name := "utest:tag1"
name2 := "utest/docker:tag2"
name3 := "utest:5000/docker:tag3"
defer deleteImages(name, name2, name3)
dockerCmd(t, "tag", "busybox", name)
dockerCmd(t, "tag", "busybox", name2)
dockerCmd(t, "tag", "busybox", name3)
type image struct{ RepoTags []string }
getImages := func(filter string) []image {
v := url.Values{}
v.Set("filter", filter)
_, b, err := sockRequest("GET", "/images/json?"+v.Encode(), nil)
if err != nil {
t.Fatal(err)
}
var images []image
if err := json.Unmarshal(b, &images); err != nil {
t.Fatal(err)
}
return images
}
errMsg := "incorrect number of matches returned"
if images := getImages("utest*/*"); len(images[0].RepoTags) != 2 {
t.Fatal(errMsg)
}
if images := getImages("utest"); len(images[0].RepoTags) != 1 {
t.Fatal(errMsg)
}
if images := getImages("utest*"); len(images[0].RepoTags) != 1 {
t.Fatal(errMsg)
}
if images := getImages("*5000*/*"); len(images[0].RepoTags) != 1 {
t.Fatal(errMsg)
}
logDone("images - filter param is applied")
}

View file

@ -279,3 +279,53 @@ func TestCommitChange(t *testing.T) {
logDone("commit - commit --change")
}
// TODO: commit --run is deprecated, remove this once --run is removed
func TestCommitMergeConfigRun(t *testing.T) {
defer deleteAllContainers()
name := "commit-test"
out, _, _ := dockerCmd(t, "run", "-d", "-e=FOO=bar", "busybox", "/bin/sh", "-c", "echo testing > /tmp/foo")
id := strings.TrimSpace(out)
dockerCmd(t, "commit", `--run={"Cmd": ["cat", "/tmp/foo"]}`, id, "commit-test")
defer deleteImages("commit-test")
out, _, _ = dockerCmd(t, "run", "--name", name, "commit-test")
if strings.TrimSpace(out) != "testing" {
t.Fatal("run config in commited container was not merged")
}
type cfg struct {
Env []string
Cmd []string
}
config1 := cfg{}
if err := inspectFieldAndMarshall(id, "Config", &config1); err != nil {
t.Fatal(err)
}
config2 := cfg{}
if err := inspectFieldAndMarshall(name, "Config", &config2); err != nil {
t.Fatal(err)
}
// Env has at least PATH loaded as well here, so let's just grab the FOO one
var env1, env2 string
for _, e := range config1.Env {
if strings.HasPrefix(e, "FOO") {
env1 = e
break
}
}
for _, e := range config2.Env {
if strings.HasPrefix(e, "FOO") {
env2 = e
break
}
}
if len(config1.Env) != len(config2.Env) || env1 != env2 && env2 != "" {
t.Fatalf("expected envs to match: %v - %v", config1.Env, config2.Env)
}
logDone("commit - configs are merged with --run")
}

View file

@ -305,3 +305,11 @@ func TestCreateLabelFromImage(t *testing.T) {
logDone("create - labels from image")
}
func TestCreateHostnameWithNumber(t *testing.T) {
out, _, _ := dockerCmd(t, "run", "-h", "web.0", "busybox", "hostname")
if strings.TrimSpace(out) != "web.0" {
t.Fatalf("hostname not set, expected `web.0`, got: %s", out)
}
logDone("create - use hostname with number")
}

View file

@ -3493,3 +3493,15 @@ func TestRunPidHostWithChildIsKillable(t *testing.T) {
}
logDone("run - can kill container with pid-host and some childs of pid 1")
}
func TestRunWithTooSmallMemoryLimit(t *testing.T) {
defer deleteAllContainers()
// this memory limit is 1 byte less than the min, which is 4MB
// https://github.com/docker/docker/blob/v1.5.0/daemon/create.go#L22
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-m", "4194303", "busybox"))
if err == nil || !strings.Contains(out, "Minimum memory limit allowed is 4MB") {
t.Fatalf("expected run to fail when using too low a memory limit: %q", out)
}
logDone("run - can't set too low memory limit")
}

View file

@ -1,71 +0,0 @@
package docker
import "testing"
func TestCreateNumberHostname(t *testing.T) {
eng := NewTestEngine(t)
defer mkDaemonFromEngine(eng, t).Nuke()
config, _, _, err := parseRun([]string{"-h", "web.0", unitTestImageID, "echo test"})
if err != nil {
t.Fatal(err)
}
createTestContainer(eng, config, t)
}
func TestRunWithTooLowMemoryLimit(t *testing.T) {
eng := NewTestEngine(t)
defer mkDaemonFromEngine(eng, t).Nuke()
// Try to create a container with a memory limit of 1 byte less than the minimum allowed limit.
job := eng.Job("create")
job.Setenv("Image", unitTestImageID)
job.Setenv("Memory", "524287")
job.Setenv("CpuShares", "1000")
job.SetenvList("Cmd", []string{"/bin/cat"})
if err := job.Run(); err == nil {
t.Errorf("Memory limit is smaller than the allowed limit. Container creation should've failed!")
}
}
func TestImagesFilter(t *testing.T) {
eng := NewTestEngine(t)
defer nuke(mkDaemonFromEngine(eng, t))
if err := eng.Job("tag", unitTestImageName, "utest", "tag1").Run(); err != nil {
t.Fatal(err)
}
if err := eng.Job("tag", unitTestImageName, "utest/docker", "tag2").Run(); err != nil {
t.Fatal(err)
}
if err := eng.Job("tag", unitTestImageName, "utest:5000/docker", "tag3").Run(); err != nil {
t.Fatal(err)
}
images := getImages(eng, t, false, "utest*/*")
if len(images[0].RepoTags) != 2 {
t.Fatal("incorrect number of matches returned")
}
images = getImages(eng, t, false, "utest")
if len(images[0].RepoTags) != 1 {
t.Fatal("incorrect number of matches returned")
}
images = getImages(eng, t, false, "utest*")
if len(images[0].RepoTags) != 1 {
t.Fatal("incorrect number of matches returned")
}
images = getImages(eng, t, false, "*5000*/*")
if len(images[0].RepoTags) != 1 {
t.Fatal("incorrect number of matches returned")
}
}