Weldr API: return the actual getImageType() error in composeHandler()
Refactor the `composeHandler()` method to send the actual error returned by `getImageType()` as an API response. Modify tests to handle the changed error message in API calls. Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
parent
dc8a93b3f6
commit
a9b676e43e
2 changed files with 13 additions and 8 deletions
|
|
@ -2177,8 +2177,8 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request
|
||||||
imageType, err := api.getImageType(distroName, cr.ComposeType)
|
imageType, err := api.getImageType(distroName, cr.ComposeType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors := responseError{
|
errors := responseError{
|
||||||
ID: "UnknownComposeType",
|
ID: "ComposeError",
|
||||||
Msg: fmt.Sprintf("Unknown compose type for architecture: %s", cr.ComposeType),
|
Msg: fmt.Sprintf("Failed to get compose type %q: %v", cr.ComposeType, err),
|
||||||
}
|
}
|
||||||
statusResponseError(writer, http.StatusBadRequest, errors)
|
statusResponseError(writer, http.StatusBadRequest, errors)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -771,7 +771,7 @@ func TestCompose(t *testing.T) {
|
||||||
{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":"InvalidChars","msg":"Invalid ostree ref"}]}`, expectedComposeOSTreeURL, []string{"build_id"}},
|
||||||
{false, "POST", "/api/v1/compose", fmt.Sprintf(`{"blueprint_name": "test-distro-2","compose_type": "%s","branch": "master"}`, test_distro.TestImageTypeName), http.StatusOK, `{"status": true}`, expectedComposeGoodDistro, []string{"build_id"}},
|
{false, "POST", "/api/v1/compose", fmt.Sprintf(`{"blueprint_name": "test-distro-2","compose_type": "%s","branch": "master"}`, test_distro.TestImageTypeName), http.StatusOK, `{"status": true}`, expectedComposeGoodDistro, []string{"build_id"}},
|
||||||
{false, "POST", "/api/v1/compose", fmt.Sprintf(`{"blueprint_name": "test-fedora-1","compose_type": "%s","branch": "master"}`, test_distro.TestImageTypeName), http.StatusBadRequest, `{"status": false,"errors":[{"id":"DistroError", "msg":"Unknown distribution: fedora-1"}]}`, nil, []string{"build_id"}},
|
{false, "POST", "/api/v1/compose", fmt.Sprintf(`{"blueprint_name": "test-fedora-1","compose_type": "%s","branch": "master"}`, test_distro.TestImageTypeName), http.StatusBadRequest, `{"status": false,"errors":[{"id":"DistroError", "msg":"Unknown distribution: fedora-1"}]}`, nil, []string{"build_id"}},
|
||||||
{false, "POST", "/api/v1/compose", `{"blueprint_name": "test-distro-2","compose_type": "imaginary_type","branch": "master"}`, http.StatusBadRequest, `{"status": false,"errors":[{"id":"UnknownComposeType", "msg":"Unknown compose type for architecture: imaginary_type"}]}`, nil, []string{"build_id"}},
|
{false, "POST", "/api/v1/compose", `{"blueprint_name": "test-distro-2","compose_type": "imaginary_type","branch": "master"}`, http.StatusBadRequest, `{"status": false,"errors":[{"id":"ComposeError", "msg":"Failed to get compose type \"imaginary_type\": invalid image type: imaginary_type"}]}`, nil, []string{"build_id"}},
|
||||||
}
|
}
|
||||||
|
|
||||||
tempdir, err := ioutil.TempDir("", "weldr-tests-")
|
tempdir, err := ioutil.TempDir("", "weldr-tests-")
|
||||||
|
|
@ -1637,7 +1637,8 @@ func TestComposePOST_ImageTypeDenylist(t *testing.T) {
|
||||||
fmt.Sprintf(`{"blueprint_name": "test","compose_type": "%s","branch": "master"}`, test_distro.TestImageTypeName),
|
fmt.Sprintf(`{"blueprint_name": "test","compose_type": "%s","branch": "master"}`, test_distro.TestImageTypeName),
|
||||||
map[string][]string{test_distro.TestDistro2Name: {test_distro.TestImageTypeName}},
|
map[string][]string{test_distro.TestDistro2Name: {test_distro.TestImageTypeName}},
|
||||||
http.StatusBadRequest,
|
http.StatusBadRequest,
|
||||||
fmt.Sprintf(`{"status":false,"errors":[{"id":"UnknownComposeType","msg":"Unknown compose type for architecture: %s"}]}`, test_distro.TestImageTypeName),
|
fmt.Sprintf(`{"status":false,"errors":[{"id":"ComposeError","msg":"Failed to get compose type \"%[1]s\": image type \"%[1]s\" for distro \"%[2]s\" is denied by configuration"}]}`,
|
||||||
|
test_distro.TestImageTypeName, test_distro.TestDistro2Name),
|
||||||
expectedComposeLocal,
|
expectedComposeLocal,
|
||||||
[]string{"build_id"},
|
[]string{"build_id"},
|
||||||
},
|
},
|
||||||
|
|
@ -1655,7 +1656,8 @@ func TestComposePOST_ImageTypeDenylist(t *testing.T) {
|
||||||
fmt.Sprintf(`{"blueprint_name": "test","compose_type": "%s","branch": "master"}`, test_distro.TestImageTypeName),
|
fmt.Sprintf(`{"blueprint_name": "test","compose_type": "%s","branch": "master"}`, test_distro.TestImageTypeName),
|
||||||
map[string][]string{test_distro.TestDistro2Name: {test_distro.TestImageTypeName, test_distro.TestImageType2Name}},
|
map[string][]string{test_distro.TestDistro2Name: {test_distro.TestImageTypeName, test_distro.TestImageType2Name}},
|
||||||
http.StatusBadRequest,
|
http.StatusBadRequest,
|
||||||
fmt.Sprintf(`{"status":false,"errors":[{"id":"UnknownComposeType","msg":"Unknown compose type for architecture: %s"}]}`, test_distro.TestImageTypeName),
|
fmt.Sprintf(`{"status":false,"errors":[{"id":"ComposeError","msg":"Failed to get compose type \"%[1]s\": image type \"%[1]s\" for distro \"%[2]s\" is denied by configuration"}]}`,
|
||||||
|
test_distro.TestImageTypeName, test_distro.TestDistro2Name),
|
||||||
expectedComposeLocal,
|
expectedComposeLocal,
|
||||||
[]string{"build_id"},
|
[]string{"build_id"},
|
||||||
},
|
},
|
||||||
|
|
@ -1664,7 +1666,8 @@ func TestComposePOST_ImageTypeDenylist(t *testing.T) {
|
||||||
fmt.Sprintf(`{"blueprint_name": "test","compose_type": "%s","branch": "master"}`, test_distro.TestImageType2Name),
|
fmt.Sprintf(`{"blueprint_name": "test","compose_type": "%s","branch": "master"}`, test_distro.TestImageType2Name),
|
||||||
map[string][]string{test_distro.TestDistro2Name: {test_distro.TestImageTypeName, test_distro.TestImageType2Name}},
|
map[string][]string{test_distro.TestDistro2Name: {test_distro.TestImageTypeName, test_distro.TestImageType2Name}},
|
||||||
http.StatusBadRequest,
|
http.StatusBadRequest,
|
||||||
fmt.Sprintf(`{"status":false,"errors":[{"id":"UnknownComposeType","msg":"Unknown compose type for architecture: %s"}]}`, test_distro.TestImageType2Name),
|
fmt.Sprintf(`{"status":false,"errors":[{"id":"ComposeError","msg":"Failed to get compose type \"%[1]s\": image type \"%[1]s\" for distro \"%[2]s\" is denied by configuration"}]}`,
|
||||||
|
test_distro.TestImageType2Name, test_distro.TestDistro2Name),
|
||||||
expectedComposeLocal2,
|
expectedComposeLocal2,
|
||||||
[]string{"build_id"},
|
[]string{"build_id"},
|
||||||
},
|
},
|
||||||
|
|
@ -1673,7 +1676,8 @@ func TestComposePOST_ImageTypeDenylist(t *testing.T) {
|
||||||
fmt.Sprintf(`{"blueprint_name": "test","compose_type": "%s","branch": "master"}`, test_distro.TestImageTypeName),
|
fmt.Sprintf(`{"blueprint_name": "test","compose_type": "%s","branch": "master"}`, test_distro.TestImageTypeName),
|
||||||
map[string][]string{"*": {test_distro.TestImageTypeName}},
|
map[string][]string{"*": {test_distro.TestImageTypeName}},
|
||||||
http.StatusBadRequest,
|
http.StatusBadRequest,
|
||||||
fmt.Sprintf(`{"status":false,"errors":[{"id":"UnknownComposeType","msg":"Unknown compose type for architecture: %s"}]}`, test_distro.TestImageTypeName),
|
fmt.Sprintf(`{"status":false,"errors":[{"id":"ComposeError","msg":"Failed to get compose type \"%[1]s\": image type \"%[1]s\" for distro \"%[2]s\" is denied by configuration"}]}`,
|
||||||
|
test_distro.TestImageTypeName, test_distro.TestDistro2Name),
|
||||||
expectedComposeLocal,
|
expectedComposeLocal,
|
||||||
[]string{"build_id"},
|
[]string{"build_id"},
|
||||||
},
|
},
|
||||||
|
|
@ -1682,7 +1686,8 @@ func TestComposePOST_ImageTypeDenylist(t *testing.T) {
|
||||||
fmt.Sprintf(`{"blueprint_name": "test","compose_type": "%s","branch": "master"}`, test_distro.TestImageTypeName),
|
fmt.Sprintf(`{"blueprint_name": "test","compose_type": "%s","branch": "master"}`, test_distro.TestImageTypeName),
|
||||||
map[string][]string{test_distro.TestDistro2Name: {"*"}},
|
map[string][]string{test_distro.TestDistro2Name: {"*"}},
|
||||||
http.StatusBadRequest,
|
http.StatusBadRequest,
|
||||||
fmt.Sprintf(`{"status":false,"errors":[{"id":"UnknownComposeType","msg":"Unknown compose type for architecture: %s"}]}`, test_distro.TestImageTypeName),
|
fmt.Sprintf(`{"status":false,"errors":[{"id":"ComposeError","msg":"Failed to get compose type \"%[1]s\": image type \"%[1]s\" for distro \"%[2]s\" is denied by configuration"}]}`,
|
||||||
|
test_distro.TestImageTypeName, test_distro.TestDistro2Name),
|
||||||
expectedComposeLocal,
|
expectedComposeLocal,
|
||||||
[]string{"build_id"},
|
[]string{"build_id"},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue