ostree: include ref in error message when invalid

This commit is contained in:
Achilleas Koutsou 2022-01-14 20:09:19 +01:00 committed by Ondřej Budai
parent 417d913439
commit db345d75dd
2 changed files with 2 additions and 2 deletions

View file

@ -61,7 +61,7 @@ func ResolveParams(params OSTreeRequest, imageType distro.ImageType) (OSTreeRequ
if resolved.Ref == "" {
resolved.Ref = imageType.OSTreeRef()
} else if !VerifyRef(params.Ref) { // only verify if specified in params
return resolved, fmt.Errorf("Invalid ostree ref")
return resolved, fmt.Errorf("Invalid ostree ref %q", params.Ref)
}
resolved.URL = params.URL

View file

@ -821,7 +821,7 @@ func TestCompose(t *testing.T) {
// 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":"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":"OSTreeOptionsError","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 \"/bad/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