Raise unexpected errors instead of silently moving on when the QA framework fabricates a resource via the API
Problem
In the QA framework when a resource fabricates via the API, first it checks if the resource already exists (via a GET
), and if that fails it tries to POST
.
The problem is that if the GET
fails for an unexpected reason, the resource will still try to POST
and that can fail if the resource actually does exist. And so we might see an error like:
QA::Resource::ApiFabricator::ResourceFabricationFailedError:
Fabrication of QA::Resource::Sandbox using the API failed (400) with `{"message":"Failed to save group {:path=\u003e[\"has already been taken\"]}"}`
...and it's not immediately obvious that the problem was that the GET
failed. We also don't see the reason the GET
failed.
Proposal
I think an easy way to solve that is to stop raising a
ResourceNotFoundError
errorunless response.code == HTTP_STATUS_OK
(https://gitlab.com/gitlab-org/gitlab/blob/34968253a211d6aef0da07a1f5caca13bb5a6af4/qa/qa/resource/api_fabricator.rb#L68-70), and instead createHTTP_STATUS_NOT_FOUND = 404
, changeunless response.code == HTTP_STATUS_OK
toif response.code == HTTP_STATUS_NOT_FOUND
, return whenresponse.code == HTTP_STATUS_OK
, and raise any other unexpected error.
That way, unexpected API errors aren't swallowed.