-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
e2e: redefine ExitWithError() to require exit code #22270
e2e: redefine ExitWithError() to require exit code #22270
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: edsantiago The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think conceptionally this is fine. We can then extend it to check that stderr is always checked, i.e. if no message is given to ExitWithError()
then stderr must be empty which is needed for command like podman run alpine false
As far as remote vs local goes, we can always do
IsRemote{ matcher1 } else { matcher2 }
where it is actually required.
test/e2e/checkpoint_image_test.go
Outdated
@@ -35,7 +35,7 @@ var _ = Describe("Podman checkpoint", func() { | |||
checkpointImage := "foobar-checkpoint" | |||
session := podmanTest.Podman([]string{"container", "checkpoint", "--create-image", checkpointImage, "foobar"}) | |||
session.WaitWithDefaultTimeout() | |||
Expect(session).To(ExitWithError()) | |||
Expect(session).To(ExitWithError(125, "no container with name or ID \"foobar\" found: no such container")) | |||
Expect(session.ErrorToString()).To(ContainSubstring("no container with name or ID \"foobar\" found")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the line already checks the stderr
// FIXME: once all ExitWithError()s have been migrated to new form, | ||
// change interface to (int, ...string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 that is important for proper type hints and compile time enforcement
I like this. LGTM so far. |
Thanks. I'm slowly replacing |
46e3908
to
a43c29a
Compare
a43c29a
to
85f145f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pointing out a couple of instances demonstrating the value of this.
This has grown to just about what I think is reasonable for review. Maybe a little over (sorry). I will pause here, accept feedback, then proceed with the process once this merges.
test/e2e/exec_test.go
Outdated
It("podman exec without command", func() { | ||
session := podmanTest.Podman([]string{"exec", "foobar"}) | ||
session.WaitWithDefaultTimeout() | ||
Expect(session).Should(Exit(125)) | ||
Expect(session).Should(ExitWithError(125, "no container with name or ID \"foobar\" found: no such container")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is why I'm "wasting" my time on this seemingly-trivial exercise.
This entire test was pointless. I'm sure the author wanted it to fail with "must provide a non-empty command", but in reality it was failing with "container foobar does not exist and I'm not even going to bother checking the rest of the args".
I added this test (as intended) as a piggyback onto simple command
below.
It("podman generate systemd bad restart policy", func() { | ||
session := podmanTest.Podman([]string{"generate", "systemd", "--restart-policy", "never", "foobar"}) | ||
session.WaitWithDefaultTimeout() | ||
Expect(session).To(ExitWithError()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another completely pointless test: this was failing with "I'm gonna check the container name first, before even checking options, and foobar doesn't exist, so this test doesn't even test what you think it's testing". Fortunately this was a dup, and the "bogus" test below was already testing this functionality.
test/e2e/generate_systemd_test.go
Outdated
}) | ||
|
||
It("podman generate systemd bad timeout value", func() { | ||
session := podmanTest.Podman([]string{"generate", "systemd", "--time", "-1", "foobar"}) | ||
session.WaitWithDefaultTimeout() | ||
Expect(session).To(ExitWithError()) | ||
Expect(session).To(ExitWithError(125, "invalid argument \"-1\" for \"-t, --time\" flag: strconv.ParseUint: parsing \"-1\": invalid syntax")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hint, if you like to avoid all the quoting you can use backticks to create a "raw" string without any required escaping, i.e.
`invalid argument "-1" for "-t, --time" flag: strconv.ParseUint: parsing "-1": invalid syntax`
Not required of course but IMO makes it easer to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I prefer the backtick form too, but its use in our code base is rare. I'm in the process of fixing these (only in my changes) and will repush.
test/e2e/create_staticip_test.go
Outdated
@@ -74,7 +73,7 @@ var _ = Describe("Podman create with --ip flag", func() { | |||
// test1 container is running with the given IP. | |||
result = podmanTest.Podman([]string{"start", "-a", "test2"}) | |||
result.WaitWithDefaultTimeout() | |||
Expect(result).To(ExitWithError()) | |||
Expect(result).To(ExitWithError(125)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK we dropped CNI tests so could you just simply this block below and only match the netavark message?
overall LGTM, very good improvements |
85f145f
to
1b933a1
Compare
test/e2e/create_staticip_test.go
Outdated
} else if podmanTest.NetworkBackend == Netavark { | ||
Expect(result.ErrorToString()).To(ContainSubstring("requested ip address %s is already allocated", ip)) | ||
} | ||
Expect(result).To(ExitWithError(125, " is already allocated")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Luap99 is this what you meant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes although if we do not want to loose the ip I suggest using
fmt.Sprintf("requested ip address %s is already allocated", ip)
to create the proper error string
But I do not think it is super important one way or another so I am fine with the current version as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. I think ExitWithError(xxx, fmt.Sprintf()
)` looks clunky, but tighter testing is better testing. So done.
ContainSubstring()
is kind of nice in how it takes varargs. I think that's nicely readable, but I just didn't want to complicate this PR even more by adding that to ExitWithError()
. Would that be worth pursuing once this exercise is done and I tighten up the ExitWithError()
signature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ContainSubstring() is kind of nice in how it takes varargs. I think that's nicely readable, but I just didn't want to complicate this PR even more by adding that to ExitWithError(). Would that be worth pursuing once this exercise is done and I tighten up the ExitWithError() signature?
Yes I think that would be valuable but definitely not worth to block this work over it.
...and an optional error-message string, to be checked against stderr. This is a starting point and baby-steps progress toward containers#18188. There are 249 ExitWithError() checks in test/e2e. It will take weeks to fix them all. This commit enables new functionality: Expect(ExitWithError(125, "expected substring")) ...while also allowing the current empty-args form. Once all 249 empty-args uses are modernized, the matcher code will be cleaned up. I expect it will take several months of light effort to get all e2e tests transitioned to the new form. I am choosing to do so in pieces, for (relative) ease of review. This PR: 1) makes the initial changes described above; and 2) updates a small subset of e2e _test.go files such that: a) ExitWithError() is given an exit code and error string; and b) Exit(Nonzero) is changed to ExitWithError(Nonzero, "string") (when possible) Signed-off-by: Ed Santiago <[email protected]>
1b933a1
to
2d91598
Compare
LGTM |
/lgtm |
Followup to containers#22270: wherever possible/practical, extend command error checks to include explicit exit status codes and error strings. This commit handles all remaining test/e2e/p*_test.go Signed-off-by: Ed Santiago <[email protected]>
Followup to containers#22270: wherever possible/practical, extend command error checks to include explicit exit status codes and error strings. This commit handles a subset of test/e2e/run_xxx_test.go Signed-off-by: Ed Santiago <[email protected]>
Followup to containers#22270: wherever possible/practical, extend command error checks to include explicit exit status codes and error strings. This commit handles test/e2e/s*_test.go Signed-off-by: Ed Santiago <[email protected]>
Followup to containers#22270: wherever possible/practical, extend command error checks to include explicit exit status codes and error strings. This commit handles all remaining test/e2e/r*_test.go Signed-off-by: Ed Santiago <[email protected]>
Followup to containers#22270: wherever possible/practical, extend command error checks to include explicit exit status codes and error strings. This commit handles only one file, test/e2e/rmi_test.go , because my changes are significant enough to merit individual review. Signed-off-by: Ed Santiago <[email protected]>
Final followup to containers#22270. That PR added a temporary convention allowing a new form of ExitWithError(), one with an exit code and stderr substring. In order to allow bite-size progress, the old no-args form was still allowed. This PR removes support for no-args ExitWithError(). This PR also adds one piece of new functionality: passing "" (empty string) as the stderr arg means "expect exit code but fail if there's anything at all in stderr". Signed-off-by: Ed Santiago <[email protected]>
...and an optional error-message string, to be checked against stderr.
This is a starting point and baby-steps progress toward #18188. There are 249 ExitWithError() checks in test/e2e. It will take weeks to fix them all. This commit enables new functionality:
...while also allowing the current empty-args form. Once all 249 empty-args uses are modernized, the matcher code will be cleaned up.
I expect it will take several months of light effort to get all e2e tests transitioned to the new form. I am choosing to do so in pieces, for (relative) ease of review. This PR:
a) ExitWithError() is given an exit code and error string; and
b) Exit(Nonzero) is changed to ExitWithError(Nonzero, "string") (when possible)