store, weldr: Add support for fake composes

Yes. This goes against my desire not to change code to accommodate
tests. But there is no other good way to test compose results without
long running, and possibly fragile, composes. And this matches lorax's
behavior.

The change adds support for the ?test=1|2 query parameter to the compose
POST, and a new store function - PushTestCompose that handles creating
the fake compose results.

Passing ?test=1 will create a failed compose. Passing ?test=2 will
create a successful compose, but one without any files.

The purpose of these is to be able to test the compose result API
responses like compose/failed, etc.
This commit is contained in:
Brian C. Lane 2020-04-09 13:49:06 -07:00 committed by Tom Gundersen
parent ebeecfaf33
commit 2860398c2a
2 changed files with 90 additions and 1 deletions

View file

@ -1467,7 +1467,29 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request
return
}
composeID, err := api.store.PushCompose(imageType, bp, api.allRepositories(), packages, buildPackages, cr.Size, targets)
var composeID uuid.UUID
// Check for test parameter
q, err := url.ParseQuery(request.URL.RawQuery)
if err != nil {
errors := responseError{
ID: "InvalidChars",
Msg: fmt.Sprintf("invalid query string: %v", err),
}
statusResponseError(writer, http.StatusBadRequest, errors)
return
}
testMode := q.Get("test")
if testMode == "1" {
// Create a failed compose
composeID, err = api.store.PushTestCompose(imageType, bp, api.allRepositories(), packages, buildPackages, cr.Size, targets, false)
} else if testMode == "2" {
// Create a successful compose
composeID, err = api.store.PushTestCompose(imageType, bp, api.allRepositories(), packages, buildPackages, cr.Size, targets, true)
} else {
composeID, err = api.store.PushCompose(imageType, bp, api.allRepositories(), packages, buildPackages, cr.Size, targets)
}
// TODO: we should probably do some kind of blueprint validation in future
// for now, let's just 500 and bail out