-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Tests look good 👍 Also included a suggestion on how to simplify the assertions. Feel free to use it or ignore
if got := w.Code; got != tt.expectedStatus { | ||
t.Errorf("handleHealthCheck() status = %v, want %v", got, tt.expectedStatus) | ||
} |
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 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
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") |
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.
Good idea, I'll start using testify
from now on and maybe later we can revisit older tests!
if err := json.NewDecoder(w.Body).Decode(&response); err != nil { | ||
t.Errorf("failed to decode response body: %v", err) | ||
} |
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.
And this would be
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) |
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.
name: "returns default port when env var is negative", | ||
envPort: "-1", | ||
expectedPort: defaultPort, |
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.
Wonder if we should throw instead if an invalid port is configured?
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.
Refactored to move this to the new config style from n8n-io/n8n#8446
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.
🚀
https://linear.app/n8n/issue/PAY-2247/write-tests-for-launcher