weldr: change all OSTree related error IDs to OSTreeOptionsError

These will all be reported from the same validation function.
This commit is contained in:
Achilleas Koutsou 2022-01-14 19:57:00 +01:00 committed by Ondřej Budai
parent 26468315ab
commit 4d31c8e69d
2 changed files with 4 additions and 4 deletions

View file

@ -2229,7 +2229,7 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request
cr.OSTree.Ref = imageType.OSTreeRef()
} else if !ostree.VerifyRef(cr.OSTree.Ref) {
errors := responseError{
ID: "InvalidChars",
ID: "OSTreeOptionsError",
Msg: "Invalid ostree ref",
}
statusResponseError(writer, http.StatusBadRequest, errors)
@ -2278,7 +2278,7 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request
parent, err = ostree.ResolveRef(cr.OSTree.URL, cr.OSTree.Ref)
if err != nil {
errors := responseError{
ID: "OSTreeCommitError",
ID: "OSTreeOptionsError",
Msg: err.Error(),
}
statusResponseError(writer, http.StatusBadRequest, errors)

View file

@ -819,9 +819,9 @@ func TestCompose(t *testing.T) {
// Ref + URL = OK
{false, "POST", "/api/v1/compose?test=2", fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"refid","parent":"","url":"http://ostree/"}}`, test_distro.TestImageTypeName), http.StatusOK, `{"status": true}`, expectedComposeOSTreeURL, []string{"build_id"}},
// Ref + invalid URL = error
{false, "POST", "/api/v1/compose", fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"refid","parent":"","url":"invalid-url"}}`, test_distro.TestImageTypeName), http.StatusBadRequest, `{"status":false,"errors":[{"id":"OSTreeCommitError","msg":"Get \"invalid-url/refs/heads/refid\": unsupported protocol scheme \"\""}]}`, nil, []string{"build_id"}},
{false, "POST", "/api/v1/compose", fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"refid","parent":"","url":"invalid-url"}}`, test_distro.TestImageTypeName), http.StatusBadRequest, `{"status":false,"errors":[{"id":"OSTreeOptionsError","msg":"Get \"invalid-url/refs/heads/refid\": unsupported protocol scheme \"\""}]}`, nil, []string{"build_id"}},
// Bad Ref + URL = error
{false, "POST", "/api/v1/compose", fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"/bad/ref","parent":"","url":"http://ostree/"}}`, test_distro.TestImageTypeName), http.StatusBadRequest, `{"status":false,"errors":[{"id":"InvalidChars","msg":"Invalid ostree ref"}]}`, expectedComposeOSTreeURL, []string{"build_id"}},
{false, "POST", "/api/v1/compose", fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"/bad/ref","parent":"","url":"http://ostree/"}}`, test_distro.TestImageTypeName), http.StatusBadRequest, `{"status":false,"errors":[{"id":"OSTreeOptionsError","msg":"Invalid ostree ref"}]}`, expectedComposeOSTreeURL, []string{"build_id"}},
// Ref + Parent + URL = error
{false, "POST", "/api/v1/compose", fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"refid","parent":"parentid","url":"http://ostree/"}}`, test_distro.TestImageTypeName), http.StatusBadRequest, `{"status":false,"errors":[{"id":"OSTreeOptionsError","msg":"Supply at most one of Parent and URL"}]}`, expectedComposeOSTreeRef, []string{"build_id"}},
// Parent + URL = error