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

chore: use require instead of t.Fatal (part 2) #2857

Merged
merged 1 commit into from
Oct 31, 2024

Conversation

mmorel-35
Copy link
Contributor

What does this PR do?

This uses require instead of t.Fatal calls

Why is it important?

This reduce the number of lines required to make an assertion.
It also make the assertion easier to understand.

Related issues

@mmorel-35 mmorel-35 requested a review from a team as a code owner October 29, 2024 18:52
Copy link

netlify bot commented Oct 29, 2024

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit edbfde9
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/6722b2238435180008de4fae
😎 Deploy Preview https://deploy-preview-2857--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Member

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! just some minor comments

@@ -919,7 +919,7 @@ func TestPrintContainerLogsOnError(t *testing.T) {
break
}

t.Fatal("Read Error:", err)
require.NoErrorf(t, err, "Read Error")
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I knew, maybe you prefer it the now ?

@@ -108,21 +106,19 @@ func TestElasticsearch(t *testing.T) {

if tt.image != baseImage8 && err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

We probably need to restructure this if/else sequence here, as it was not already very readable before the changes, and the readability does not improve after them.

modules/elasticsearch/elasticsearch_test.go Outdated Show resolved Hide resolved
modules/elasticsearch/elasticsearch_test.go Outdated Show resolved Hide resolved
@mmorel-35 mmorel-35 force-pushed the testifier/require-error branch 2 times, most recently from 07d1b2d to 9dfd622 Compare October 29, 2024 20:47
if err != nil || i > 0 {
t.Fatalf("Can't make request to nginx container from dind container")
}
require.Zerof(t, i, "Can't make request to nginx container from dind container")
Copy link
Member

Choose a reason for hiding this comment

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

Comment NOT related to this PR, but for the general maintenance of the library:

@stevenh wdyt of keeping the description messages in the checks? Should we keep them, or remove them. We are working in creating more and more contextual error messages, so at some point we'll have much better experience debugging test errors.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Personally I don't think they add value in most cases, just adding more for the developer to read. This is particularly the case for error checks.

The way I look at it is does it make it clearer to the reader why this might have failed, which this type of message I would argue doesn't as its obvious from the line above that the request didn't work.

In this particular example they checks are back to front, error check should come first.

logconsumer_test.go Outdated Show resolved Hide resolved
if resp.StatusCode != http.StatusOK {
tt.Fatalf("unexpected status code: %d", resp.StatusCode)
}
require.Equalf(tt, http.StatusOK, resp.StatusCode, "unexpected status code: %d", resp.StatusCode)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is an example of a message that people might think is helpful but isn't in my mind as the values are output anyway and is obvious from the code its a status check.

lifecycle_test.go Outdated Show resolved Hide resolved
modules/compose/compose_builder_test.go Outdated Show resolved Hide resolved
modules/elasticsearch/elasticsearch_test.go Outdated Show resolved Hide resolved
defer resp.Body.Close()
require.NoError(t, err)

if tt.image == baseImage8 && tt.passwordCustomiser == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: This would be easier to follow if we changed to switch on the image and had each case inside.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need to apply it, I did it it for the next condition

modules/neo4j/neo4j_test.go Outdated Show resolved Hide resolved
modules/weaviate/weaviate_test.go Outdated Show resolved Hide resolved
@mmorel-35 mmorel-35 force-pushed the testifier/require-error branch 2 times, most recently from d737429 to 100be4d Compare October 30, 2024 18:21
@mmorel-35 mmorel-35 requested a review from stevenh October 30, 2024 18:31
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
@mmorel-35 mmorel-35 force-pushed the testifier/require-error branch from 100be4d to edbfde9 Compare October 30, 2024 22:24
Copy link
Member

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

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

LGTM!

As a follow-up, I'd send a separate PR replacing the formatted requires, simply removing the messages, as it's now much clearer the reasons why they failed.

Thank you @mmorel-35 for your hard work cleaning up the project 🙇

Copy link
Collaborator

@stevenh stevenh left a comment

Choose a reason for hiding this comment

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

LGTM

@mdelapenya mdelapenya self-assigned this Oct 31, 2024
@mdelapenya mdelapenya added the chore Changes that do not impact the existing functionality label Oct 31, 2024
@mdelapenya mdelapenya merged commit bed5632 into testcontainers:main Oct 31, 2024
122 checks passed
@mmorel-35 mmorel-35 deleted the testifier/require-error branch October 31, 2024 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Changes that do not impact the existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants