1
0
Эх сурвалжийг харах

e2e test

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 4 жил өмнө
parent
commit
8b90814de6

+ 1 - 1
api/compose/api.go

@@ -65,7 +65,7 @@ type CreateOptions struct {
 
 // StartOptions group options of the Start API
 type StartOptions struct {
-	// Attach will attach to service containers and pipe stdout/stderr to channel
+	// Attach will attach to service containers and send container logs and events
 	Attach ContainerEventListener
 }
 

+ 7 - 0
cli/cmd/compose/up.go

@@ -133,6 +133,13 @@ func runCreateStart(ctx context.Context, opts upOptions, services []string) erro
 		return err
 	}
 
+	if opts.exitCodeFrom != "" {
+		_, err := project.GetService(opts.exitCodeFrom)
+		if err != nil {
+			return err
+		}
+	}
+
 	_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
 		err := c.ComposeService().Create(ctx, project, compose.CreateOptions{
 			RemoveOrphans: opts.removeOrphans,

+ 11 - 12
local/e2e/compose/cascade_stop_test.go

@@ -30,20 +30,19 @@ func TestCascadeStop(t *testing.T) {
 	const projectName = "compose-e2e-logs"
 
 	t.Run("abort-on-container-exit", func(t *testing.T) {
-		res := c.RunDockerCmd("compose", "-f", "./fixtures/cascade-stop-test/compose.yaml", "--project-name", projectName, "up", "--abort-on-container-exit")
-		res.Assert(t, icmd.Expected{Out: `/does_not_exist: No such file or directory`})
-		res.Assert(t, icmd.Expected{Out: `should_fail_1 exited with code 1`})
-		res.Assert(t, icmd.Expected{Out: `Aborting on container exit...`})
-		res.Assert(t, icmd.Expected{Out: `ERROR 1`})
-		res.Assert(t, icmd.Expected{ExitCode: 1})
+		res := c.RunDockerOrExitError("compose", "-f", "./fixtures/cascade-stop-test/compose.yaml", "--project-name", projectName, "up", "--abort-on-container-exit")
+		res.Assert(t, icmd.Expected{ExitCode: 1, Out: `should_fail_1 exited with code 1`})
+		res.Assert(t, icmd.Expected{ExitCode: 1, Out: `Aborting on container exit...`})
 	})
 
 	t.Run("exit-code-from", func(t *testing.T) {
-		res := c.RunDockerCmd("compose", "-f", "./fixtures/cascade-stop-test/compose.yaml", "--project-name", projectName, "up", "--exit-code-from=sleep")
-		res.Assert(t, icmd.Expected{Out: `/does_not_exist: No such file or directory`})
-		res.Assert(t, icmd.Expected{Out: `should_fail_1 exited with code 1`})
-		res.Assert(t, icmd.Expected{Out: `Aborting on container exit...`})
-		res.Assert(t, icmd.Expected{Out: `ERROR 143`})
-		res.Assert(t, icmd.Expected{ExitCode: 143})
+		res := c.RunDockerOrExitError("compose", "-f", "./fixtures/cascade-stop-test/compose.yaml", "--project-name", projectName, "up", "--exit-code-from=sleep")
+		res.Assert(t, icmd.Expected{ExitCode: 137, Out: `should_fail_1 exited with code 1`})
+		res.Assert(t, icmd.Expected{ExitCode: 137, Out: `Aborting on container exit...`})
+	})
+
+	t.Run("exit-code-from unknown", func(t *testing.T) {
+		res := c.RunDockerOrExitError("compose", "-f", "./fixtures/cascade-stop-test/compose.yaml", "--project-name", projectName, "up", "--exit-code-from=unknown")
+		res.Assert(t, icmd.Expected{ExitCode: 1, Err: `no such service: unknown`})
 	})
 }

+ 1 - 1
local/e2e/compose/fixtures/cascade-stop-test/compose.yaml

@@ -4,4 +4,4 @@ services:
     command: ls /does_not_exist
   sleep: # will be killed
     image: busybox:1.27.2
-    command: sleep 10
+    command: ping localhost