Skip to content

chore(health): adding health check tests#19

Merged
Jacobbrewer1 merged 3 commits intomainfrom
chore/health-testing
Apr 10, 2025
Merged

chore(health): adding health check tests#19
Jacobbrewer1 merged 3 commits intomainfrom
chore/health-testing

Conversation

@Jacobbrewer1
Copy link
Owner

Describe your changes

This pull request includes several changes to the health check system to improve context handling, error handling, and testing. The most important changes include adding context checks, improving error handling for invalid statuses, and enhancing the test coverage.

Context Handling Improvements:

  • health/check.go: Added a check to ensure ctx is not nil and set it to context.Background() if it is. [1] [2]
  • health/checker.go: Added a check to ensure ctx is not nil and set it to context.Background() if it is.

Error Handling Enhancements:

  • health/check.go: Added validation to ensure statusErr.Status is valid, setting it to StatusUnknown if it is not.
  • health/status.go: Modified MarshalJSON to return an error for invalid statuses.

Test Coverage Enhancements:

Code Simplification:

  • health/result.go: Changed Details map to use pointers to Result to simplify memory management. [1] [2] [3]
  • health/time.go: Renamed Timestamp to timestamp to follow Go naming conventions for unexported variables.

Documentation:

@Jacobbrewer1 Jacobbrewer1 requested a review from Copilot April 10, 2025 07:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

health/status_test.go:54

  • When testing invalid statuses, the error message should indicate that an error is expected rather than stating 'should not return an error'. Consider updating the message to accurately reflect the expected behavior.
require.Equal(t, tt.wantErr, err, "MarshalJSON() should not return an error")

health/checker_test.go:76

  • The error message is misleading: while the expected HTTP status is ServiceUnavailable, the message indicates 200 OK. Please update the message to accurately reflect the expected status code.
require.Equal(t, http.StatusServiceUnavailable, rec.Code, "Handler() should return a 200 OK status code")

@Jacobbrewer1 Jacobbrewer1 requested a review from Copilot April 10, 2025 07:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

@Jacobbrewer1 Jacobbrewer1 requested a review from Copilot April 10, 2025 07:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

health/status_test.go:46

  • Verify that the error message produced by MarshalJSON for an invalid status exactly matches the expected error message in the test. If the Status type's String() method returns a numeric value (e.g. "999") rather than "invalid", adjust either the test or the error formatting accordingly.
wantErr: errors.New("invalid is not a valid status"),

health/response.go:1

  • Ensure that the removal of the health/response.go file does not leave any dangling references elsewhere in the codebase, which could lead to runtime issues.
package health

@Jacobbrewer1 Jacobbrewer1 enabled auto-merge (squash) April 10, 2025 07:17
@Jacobbrewer1 Jacobbrewer1 merged commit a0ccc71 into main Apr 10, 2025
4 checks passed
@Jacobbrewer1 Jacobbrewer1 deleted the chore/health-testing branch April 10, 2025 07:17
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants