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
|
@ -424,7 +424,6 @@ func startEchoServerContainer(t *testing.T, proto string) (*daemon.Daemon, *daem
|
|||
var (
|
||||
err error
|
||||
id string
|
||||
outputBuffer = bytes.NewBuffer(nil)
|
||||
strPort string
|
||||
eng = NewTestEngine(t)
|
||||
daemon = mkDaemonFromEngine(eng, t)
|
||||
|
@ -452,16 +451,13 @@ func startEchoServerContainer(t *testing.T, proto string) (*daemon.Daemon, *daem
|
|||
p = nat.Port(fmt.Sprintf("%s/%s", strPort, proto))
|
||||
ep[p] = struct{}{}
|
||||
|
||||
jobCreate := eng.Job("create")
|
||||
jobCreate.Setenv("Image", unitTestImageID)
|
||||
jobCreate.SetenvList("Cmd", []string{"sh", "-c", cmd})
|
||||
jobCreate.SetenvList("PortSpecs", []string{fmt.Sprintf("%s/%s", strPort, proto)})
|
||||
jobCreate.SetenvJson("ExposedPorts", ep)
|
||||
jobCreate.Stdout.Add(outputBuffer)
|
||||
if err := jobCreate.Run(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
id = engine.Tail(outputBuffer, 1)
|
||||
env := new(engine.Env)
|
||||
env.Set("Image", unitTestImageID)
|
||||
env.SetList("Cmd", []string{"sh", "-c", cmd})
|
||||
env.SetList("PortSpecs", []string{fmt.Sprintf("%s/%s", strPort, proto)})
|
||||
env.SetJson("ExposedPorts", ep)
|
||||
|
||||
id, _, err = daemon.ContainerCreate(unitTestImageID, env)
|
||||
// FIXME: this relies on the undocumented behavior of daemon.Create
|
||||
// which will return a nil error AND container if the exposed ports
|
||||
// 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[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)
|
||||
}
|
||||
if err := jobStart.Run(); err != nil {
|
||||
if err := daemon.ContainerStart(id, env); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
@ -731,20 +728,20 @@ func TestContainerNameValidation(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var outputBuffer = bytes.NewBuffer(nil)
|
||||
job := eng.Job("create", test.Name)
|
||||
if err := job.ImportEnv(config); err != nil {
|
||||
env := new(engine.Env)
|
||||
if err := env.Import(config); err != nil {
|
||||
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 {
|
||||
continue
|
||||
}
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
container, err := daemon.Get(engine.Tail(outputBuffer, 1))
|
||||
container, err := daemon.Get(containerId)
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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) {
|
||||
job := eng.Job("create", name)
|
||||
if err := job.ImportEnv(config); err != nil {
|
||||
env := new(engine.Env)
|
||||
if err := env.Import(config); err != nil {
|
||||
f.Fatal(err)
|
||||
}
|
||||
var outputBuffer = bytes.NewBuffer(nil)
|
||||
job.Stdout.Add(outputBuffer)
|
||||
if err := job.Run(); err != nil {
|
||||
containerId, _, err := getDaemon(eng).ContainerCreate(name, env)
|
||||
if err != nil {
|
||||
f.Fatal(err)
|
||||
}
|
||||
return engine.Tail(outputBuffer, 1)
|
||||
return containerId
|
||||
}
|
||||
|
||||
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) {
|
||||
job := eng.Job("start", id)
|
||||
if err := job.Run(); err != nil {
|
||||
env := new(engine.Env)
|
||||
if err := getDaemon(eng).ContainerStart(id, env); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue