Skip to content

Mock jokes API call in tests to prevent CI failures#11

Merged
DMcP89 merged 3 commits intomainfrom
copilot/mock-api-call-in-tests
Oct 9, 2025
Merged

Mock jokes API call in tests to prevent CI failures#11
DMcP89 merged 3 commits intomainfrom
copilot/mock-api-call-in-tests

Conversation

Copy link
Contributor

Copilot AI commented Oct 8, 2025

  • Create testdata file for joke API response
  • Update jokes_test.go to use gock for mocking HTTP requests
  • Verify tests pass with mock data
  • Run full test suite to ensure no regressions
  • Revert unrelated formatting changes to gitstatus_test.go

Summary

Successfully updated TestGetJoke to mock the API call to https://icanhazdadjoke.com/ instead of making live requests. This prevents test failures during GitHub Actions builds caused by network issues.

Changes made:

  1. Created internal/apis/testdata/joke.txt with sample joke response
  2. Updated internal/apis/jokes_test.go to use gock library for HTTP mocking (consistent with other API tests)
  3. Added table-driven test structure following repository patterns
  4. All tests pass successfully without making external API calls
Original prompt

This section details on the original issue you should resolve

<issue_title>jokes_test.go attempts to make live API call</issue_title>
<issue_description># Problem
Currently the TestGetJoke test in jokes_test.go will attempt to make an API call to https://icanhazdadjoke.com. This can cause failures during out Github Actions build.

Solution

Update the test to mock the return from https://icanhazdadjoke.com/ instead of actually calling the API.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #10

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: DMcP89 <4146149+DMcP89@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix live API call in jokes_test.go Mock jokes API call in tests to prevent CI failures Oct 8, 2025
Copilot AI requested a review from DMcP89 October 8, 2025 03:13
@DMcP89
Copy link
Owner

DMcP89 commented Oct 8, 2025

@copilot Please remove your changes to internal/apis/gitstatus_test.go

Co-authored-by: DMcP89 <4146149+DMcP89@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 8, 2025

@copilot Please remove your changes to internal/apis/gitstatus_test.go

Reverted the changes to gitstatus_test.go in commit 6e25c8f.

@DMcP89 DMcP89 marked this pull request as ready for review October 9, 2025 18:06
@DMcP89 DMcP89 merged commit 76d0ddc into main Oct 9, 2025
3 checks passed
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.

jokes_test.go attempts to make live API call

2 participants