mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Make integration tests to call the new start and create endpoints.
Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
98996a432e
commit
002afbbe77
2 changed files with 31 additions and 36 deletions
|
@ -422,14 +422,13 @@ func TestGet(t *testing.T) {
|
||||||
|
|
||||||
func startEchoServerContainer(t *testing.T, proto string) (*daemon.Daemon, *daemon.Container, string) {
|
func startEchoServerContainer(t *testing.T, proto string) (*daemon.Daemon, *daemon.Container, string) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
id string
|
id string
|
||||||
outputBuffer = bytes.NewBuffer(nil)
|
strPort string
|
||||||
strPort string
|
eng = NewTestEngine(t)
|
||||||
eng = NewTestEngine(t)
|
daemon = mkDaemonFromEngine(eng, t)
|
||||||
daemon = mkDaemonFromEngine(eng, t)
|
port = 5554
|
||||||
port = 5554
|
p nat.Port
|
||||||
p nat.Port
|
|
||||||
)
|
)
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -452,16 +451,13 @@ func startEchoServerContainer(t *testing.T, proto string) (*daemon.Daemon, *daem
|
||||||
p = nat.Port(fmt.Sprintf("%s/%s", strPort, proto))
|
p = nat.Port(fmt.Sprintf("%s/%s", strPort, proto))
|
||||||
ep[p] = struct{}{}
|
ep[p] = struct{}{}
|
||||||
|
|
||||||
jobCreate := eng.Job("create")
|
env := new(engine.Env)
|
||||||
jobCreate.Setenv("Image", unitTestImageID)
|
env.Set("Image", unitTestImageID)
|
||||||
jobCreate.SetenvList("Cmd", []string{"sh", "-c", cmd})
|
env.SetList("Cmd", []string{"sh", "-c", cmd})
|
||||||
jobCreate.SetenvList("PortSpecs", []string{fmt.Sprintf("%s/%s", strPort, proto)})
|
env.SetList("PortSpecs", []string{fmt.Sprintf("%s/%s", strPort, proto)})
|
||||||
jobCreate.SetenvJson("ExposedPorts", ep)
|
env.SetJson("ExposedPorts", ep)
|
||||||
jobCreate.Stdout.Add(outputBuffer)
|
|
||||||
if err := jobCreate.Run(); err != nil {
|
id, _, err = daemon.ContainerCreate(unitTestImageID, env)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
id = engine.Tail(outputBuffer, 1)
|
|
||||||
// FIXME: this relies on the undocumented behavior of daemon.Create
|
// FIXME: this relies on the undocumented behavior of daemon.Create
|
||||||
// which will return a nil error AND container if the exposed ports
|
// which will return a nil error AND container if the exposed ports
|
||||||
// are invalid. That behavior should be fixed!
|
// are invalid. That behavior should be fixed!
|
||||||
|
@ -472,15 +468,16 @@ func startEchoServerContainer(t *testing.T, proto string) (*daemon.Daemon, *daem
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jobStart := eng.Job("start", id)
|
|
||||||
portBindings := make(map[nat.Port][]nat.PortBinding)
|
portBindings := make(map[nat.Port][]nat.PortBinding)
|
||||||
portBindings[p] = []nat.PortBinding{
|
portBindings[p] = []nat.PortBinding{
|
||||||
{},
|
{},
|
||||||
}
|
}
|
||||||
if err := jobStart.SetenvJson("PortsBindings", portBindings); err != nil {
|
|
||||||
|
env := new(engine.Env)
|
||||||
|
if err := env.SetJson("PortsBindings", portBindings); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := jobStart.Run(); err != nil {
|
if err := daemon.ContainerStart(id, env); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -731,20 +728,20 @@ func TestContainerNameValidation(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var outputBuffer = bytes.NewBuffer(nil)
|
env := new(engine.Env)
|
||||||
job := eng.Job("create", test.Name)
|
if err := env.Import(config); err != nil {
|
||||||
if err := job.ImportEnv(config); err != nil {
|
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
job.Stdout.Add(outputBuffer)
|
|
||||||
if err := job.Run(); err != nil {
|
containerId, _, err := daemon.ContainerCreate(test.Name, env)
|
||||||
|
if err != nil {
|
||||||
if !test.Valid {
|
if !test.Valid {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
container, err := daemon.Get(engine.Tail(outputBuffer, 1))
|
container, err := daemon.Get(containerId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -759,7 +756,6 @@ func TestContainerNameValidation(t *testing.T) {
|
||||||
t.Fatalf("Container /%s has ID %s instead of %s", test.Name, c.ID, container.ID)
|
t.Fatalf("Container /%s has ID %s instead of %s", test.Name, c.ID, container.ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLinkChildContainer(t *testing.T) {
|
func TestLinkChildContainer(t *testing.T) {
|
||||||
|
|
|
@ -44,16 +44,15 @@ func mkDaemon(f Fataler) *daemon.Daemon {
|
||||||
}
|
}
|
||||||
|
|
||||||
func createNamedTestContainer(eng *engine.Engine, config *runconfig.Config, f Fataler, name string) (shortId string) {
|
func createNamedTestContainer(eng *engine.Engine, config *runconfig.Config, f Fataler, name string) (shortId string) {
|
||||||
job := eng.Job("create", name)
|
env := new(engine.Env)
|
||||||
if err := job.ImportEnv(config); err != nil {
|
if err := env.Import(config); err != nil {
|
||||||
f.Fatal(err)
|
f.Fatal(err)
|
||||||
}
|
}
|
||||||
var outputBuffer = bytes.NewBuffer(nil)
|
containerId, _, err := getDaemon(eng).ContainerCreate(name, env)
|
||||||
job.Stdout.Add(outputBuffer)
|
if err != nil {
|
||||||
if err := job.Run(); err != nil {
|
|
||||||
f.Fatal(err)
|
f.Fatal(err)
|
||||||
}
|
}
|
||||||
return engine.Tail(outputBuffer, 1)
|
return containerId
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTestContainer(eng *engine.Engine, config *runconfig.Config, f Fataler) (shortId string) {
|
func createTestContainer(eng *engine.Engine, config *runconfig.Config, f Fataler) (shortId string) {
|
||||||
|
@ -61,8 +60,8 @@ func createTestContainer(eng *engine.Engine, config *runconfig.Config, f Fataler
|
||||||
}
|
}
|
||||||
|
|
||||||
func startContainer(eng *engine.Engine, id string, t Fataler) {
|
func startContainer(eng *engine.Engine, id string, t Fataler) {
|
||||||
job := eng.Job("start", id)
|
env := new(engine.Env)
|
||||||
if err := job.Run(); err != nil {
|
if err := getDaemon(eng).ContainerStart(id, env); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue