Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🥒 Cucumber PoC 🥒 #9824

Merged
merged 9 commits into from Sep 27, 2022
Merged

🥒 Cucumber PoC 🥒 #9824

merged 9 commits into from Sep 27, 2022

Conversation

laurazard
Copy link
Member

@laurazard laurazard commented Sep 9, 2022

What I did:

I got a bit curious from what we discussed regarding a PoC using Cucumber, so I started playing around with it! It needs a ton of refactoring/reorganizing (it's currently really ugly), and a good look regarding the testing utils and parallelization.

So far, steps implemented are:

  • (Given) a compose file [xxx]: sets the compose file to get piped into the compose command
  • (When) I run "compose [command]": runs the specified compose command with the given fixture piped in
  • (Then) output contains [xxx]: checks that the output of the last command contains [xxx]
  • (...) exit code is [i]: checks that the exit code of the last command is [i]
  • (...) [service] service is [status]: runs compose ps, checks that the specific service is the desired status

This allows us to define tests such as:

Feature: Simple service up

Background:
    Given a compose file
        """
        services:
          simple:
            image: alpine
            command: top
        """

Scenario: compose up
    When I run "compose up -d"
    Then the output contains "simple-1  Started"
    And service "simple" is "running"

Run the cucumber feature tests with go test -v -run ^TestCucumberFeatures$ github.com/docker/compose/v2/pkg/e2e/cucumber

Output should look something like:

image

Signed-off-by: Laura Brehm [email protected]

(not mandatory) A picture of a cute animal, if possible in relation with what you did

87

@laurazard laurazard force-pushed the cucumber-test branch 7 times, most recently from 84049b7 to 59a652f Compare Sep 12, 2022
@laurazard
Copy link
Member Author

laurazard commented Sep 12, 2022

For comparison:

	t.Run("abort-on-container-exit", func(t *testing.T) {
		res := c.RunDockerComposeCmdNoCheck(t, "-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.RunDockerComposeCmdNoCheck(t, "-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.RunDockerComposeCmdNoCheck(t, "-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`})
	})

turns into:

Feature: Stop

Background:
    Given a compose file
        """
        services:
          should_fail:
            image: alpine
            command: ls /does_not_exist
          sleep: # will be killed
            image: alpine
            command: ping localhost
        """

Scenario: Cascade stop
    When I run "compose up --abort-on-container-exit"
    Then the output contains "should_fail-1 exited with code 1"
    And the output contains "Aborting on container exit..."
    And the exit code is 1

Scenario: Exit code from
    When I run "compose up --exit-code-from sleep"
    Then the output contains "should_fail-1 exited with code 1"
    And the output contains "Aborting on container exit..."
    And the exit code is 137

Scenario: Exit code from unknown service
    When I run "compose up --exit-code-from unknown"
    Then the output contains "no such service: unknown"
    And the exit code is 1

@laurazard laurazard marked this pull request as ready for review Sep 22, 2022
@laurazard laurazard requested a review from a team Sep 22, 2022
Copy link
Member

@nicksieger nicksieger left a comment

Really like where this is going so far. I think it's worth trying out.

I'm wondering if deleting the corresponding existing tests that these cucumber tests replace would help with evaluating it? That way we can compare the current e2e test with a cucumber version in the same PR.

go.mod Outdated
@@ -2,6 +2,8 @@ module github.com/docker/compose/v2

go 1.18

replace github.com/cucumber/godog => github.com/laurazard/godog v0.0.0-20220922095256-4c4b17abdae7
Copy link
Member

@nicksieger nicksieger Sep 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's behind the need for this replace, out of curiosity?

Copy link
Member Author

@laurazard laurazard Sep 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cucumber/godog currently allows for passing in a testing.T instance to run scenarios as subtests with, but it does not make that testing.T instance available to the scenario initializer, which was needed for passing to our e2e.NewCLI() that uses some of it's helper functions. I'll make a PR to see if I can contribute that upstream soon :)

@laurazard
Copy link
Member Author

laurazard commented Sep 22, 2022

Thanks! :)

I removed cascade_stop_test.go which was replaced by stop.feature and compose_down_test.go which was replaced by down.feature, and their corresponding fixtures, so the comparison is clearer in the PR.

go.mod Outdated Show resolved Hide resolved
@laurazard
Copy link
Member Author

laurazard commented Sep 23, 2022

From here, moved the new tests into a new e2e module to separate out test dependencies.

e2e/go.mod Show resolved Hide resolved
github.com/docker/cli => github.com/docker/cli v20.10.3-0.20220309205733-2b52f62e9627+incompatible
github.com/docker/docker => github.com/docker/docker v20.10.3-0.20220309172631-83b51522df43+incompatible
Copy link
Member

@thaJeztah thaJeztah Sep 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, it's a bit messy to do so, but it may be good to have make targets to verify vendoring / go mod files to make sure they're kept in sync (to prevent situations where the e2e tests test with different versions than the main module) - (replace rules are a pain! 😞).

In containerd there's some script to do that; called from https://github.com/containerd/containerd/blob/39f7cd73e7cc3e1d24f3557adfce5b68484136f7/Makefile#L441-L456

Copy link
Member Author

@laurazard laurazard Sep 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! That's definitely a concern now having two separate sets of dependencies to keep in sync. I'll take a look at it, thanks :)

Copy link
Member Author

@laurazard laurazard Sep 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thaJeztah took a look at it and added a Makefile target validate-modules here to verify it, using the script from containerd :)

@laurazard
Copy link
Member Author

laurazard commented Sep 27, 2022

The CI isn't triggering 😢 Cursory google search seems to suggest I close and reopen the PR, so I'm going to try that.

@laurazard laurazard closed this Sep 27, 2022
@laurazard laurazard reopened this Sep 27, 2022
laurazard added 6 commits Sep 27, 2022
(run with `go test -v -run ^TestCucumberFeatures$ github.com/docker/compose/v2/pkg/e2e/cucumber`)

Signed-off-by: Laura Brehm <[email protected]>
Signed-off-by: Laura Brehm <[email protected]>
@laurazard laurazard requested a review from a team Sep 27, 2022
glours
glours approved these changes Sep 27, 2022
Copy link
Contributor

@glours glours left a comment

Looks cool, we'll need to figure out how to import fixtures for tests using huge compose files

verify-go-modules.sh Outdated Show resolved Hide resolved
verify-go-modules.sh Outdated Show resolved Hide resolved
verify-go-modules.sh Outdated Show resolved Hide resolved
milas
milas approved these changes Sep 27, 2022
Copy link
Member

@milas milas left a comment

🥒 🥒 🥒 🥒

@laurazard
Copy link
Member Author

laurazard commented Sep 27, 2022

🥳

@laurazard laurazard merged commit 25c4bce into docker:v2 Sep 27, 2022
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants