fossa-cli
fossa-cli copied to clipboard
More descriptive API mocking errors
Overview
I lost some time trying to figure out why my API expectations were failing when the request being sent was exactly what I expected it to be.
It turned out that the problem was that I had forgotten to mock the endpoint.
This PR avoids future me having to scratch his head for 10 minutes by distinguishing between "this request does not match any expected requests" and "this request's endpoint has not been mocked".
Acceptance criteria
- The tests still pass
- If you break a test by making a request that is not expected, it should say that
- If you break a test by calling an unmocked endpoint, it should say that
- The hack that I used to distinguish between unexpected requests and unmocked endpoints isn't too horrible
Testing plan
Run the unit tests. They should all still pass
make test
Edit ArchiveUploaderSpec.hs
. Comment out line 42:
-- expectQueueArchiveBuild Fixtures.firstArchive
Run the tests again
make test ARGS="ArchiveUploader"
The results should show that the failure was because there was no matching request:
test/Test/MockApi.hs:174:18:
1) App.Fossa.ArchiveUploader.archiveUploadSourceUnit should do the archive upload workflow for multiple archives
Unexpected call:
NoMatchingRequest: QueueArchiveBuild (Archive {archiveName = "second-archive-test", archiveVersion = "0.0.1"})
Unsatisfied expectations:
GetOrganization
GetApiOpts
GetSignedUploadUrl (PackageRevision {packageName = "first-archive-test", packageVersion = "0.0.1"})
GetSignedUploadUrl (PackageRevision {packageName = "second-archive-test", packageVersion = "0.0.1"})
Revert that change to ArchiveUploaderSpec
. Now comment out where we mock out QueueArchiveBuild
on line 219 of MockApi.hs
:
-- matchExpectation a@(QueueArchiveBuild{}) (ApiExpectation _ requestExpectation b@(QueueArchiveBuild{}) resp) = checkResult requestExpectation a b resp
Run the tests again. You should see failures, and it should be clear that they're due to an unmocked endpoint:
test/Test/MockApi.hs:174:18:
1) App.Fossa.ArchiveUploader.archiveUploadSourceUnit should do the archive upload workflow for a single archive
Unexpected call:
UnmockedEndpoint: QueueArchiveBuild (Archive {archiveName = "first-archive-test", archiveVersion = "0.0.1"})
Unsatisfied expectations:
GetOrganization
GetApiOpts
GetSignedUploadUrl (PackageRevision {packageName = "first-archive-test", packageVersion = "0.0.1"})
QueueArchiveBuild (Archive {archiveName = "first-archive-test", archiveVersion = "0.0.1"})