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

test: Add coverage for healthcheck server #37

Merged
merged 4 commits into from
Nov 28, 2024

Conversation

ivov
Copy link
Contributor

@ivov ivov commented Nov 27, 2024

@codecov-commenter
Copy link

codecov-commenter commented Nov 27, 2024

Codecov Report

Attention: Patch coverage is 25.00000% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launcher/main.go 0.00% 3 Missing ⚠️
internal/config/config.go 0.00% 2 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

tomi
tomi previously approved these changes Nov 28, 2024
Copy link
Contributor

@tomi tomi left a comment

Choose a reason for hiding this comment

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

Tests look good 👍 Also included a suggestion on how to simplify the assertions. Feel free to use it or ignore

Comment on lines +40 to +42
if got := w.Code; got != tt.expectedStatus {
t.Errorf("handleHealthCheck() status = %v, want %v", got, tt.expectedStatus)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This comes a bit late to the party since most of the tests have already been written, but maybe we should use a package like github.com/stretchr/testify/assert to make these assertions clearer? E.g. this would then be

Suggested change
if got := w.Code; got != tt.expectedStatus {
t.Errorf("handleHealthCheck() status = %v, want %v", got, tt.expectedStatus)
}
assert.Equal(t, w.Code, tt.expectedStatus, "wrong handleHealthCheck() status")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, I'll start using testify from now on and maybe later we can revisit older tests!

Comment on lines +49 to +51
if err := json.NewDecoder(w.Body).Decode(&response); err != nil {
t.Errorf("failed to decode response body: %v", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

And this would be

Suggested change
if err := json.NewDecoder(w.Body).Decode(&response); err != nil {
t.Errorf("failed to decode response body: %v", err)
}
err := json.NewDecoder(w.Body).Decode(&response);
assert.NoError(t, err)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines 134 to 136
name: "returns default port when env var is negative",
envPort: "-1",
expectedPort: defaultPort,
Copy link
Contributor

Choose a reason for hiding this comment

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

Wonder if we should throw instead if an invalid port is configured?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored to move this to the new config style from n8n-io/n8n#8446

Copy link
Contributor

@tomi tomi left a comment

Choose a reason for hiding this comment

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

🚀

@ivov ivov merged commit 97150cf into main Nov 28, 2024
1 check passed
@ivov ivov deleted the add-coverage-for-healthcheck-server branch November 28, 2024 13:54
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.

3 participants