weldr: add support for toml format in /blueprints/freeze
This is needed for lorax parity. When multiple blueprints are being frozen in toml mode, the API returns an error. This is the same behaviour as in the /blueprints/info route. Fixes #667
This commit is contained in:
parent
1f580738db
commit
d65057e164
3 changed files with 114 additions and 22 deletions
|
|
@ -14,6 +14,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/uuid"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
|
|
@ -135,6 +136,40 @@ func TestRoute(t *testing.T, api API, external bool, method, path, body string,
|
|||
require.Equal(t, expected, reply)
|
||||
}
|
||||
|
||||
func TestTOMLRoute(t *testing.T, api API, external bool, method, path, body string, expectedStatus int, expectedTOML string, ignoreFields ...string) {
|
||||
t.Helper()
|
||||
|
||||
resp := SendHTTP(api, external, method, path, body)
|
||||
if resp == nil {
|
||||
t.Skip("This test is for internal testing only")
|
||||
}
|
||||
|
||||
replyTOML, err := ioutil.ReadAll(resp.Body)
|
||||
require.NoErrorf(t, err, "%s: could not read response body", path)
|
||||
|
||||
assert.Equalf(t, expectedStatus, resp.StatusCode, "SendHTTP failed for path %s: %v", path, string(replyTOML))
|
||||
|
||||
if expectedTOML == "" {
|
||||
require.Lenf(t, replyTOML, 0, "%s: expected no response body, but got:\n%s", path, replyTOML)
|
||||
}
|
||||
|
||||
var reply, expected interface{}
|
||||
err = toml.Unmarshal(replyTOML, &reply)
|
||||
require.NoErrorf(t, err, "%s: json.Unmarshal failed for\n%s", path, string(replyTOML))
|
||||
|
||||
if expectedTOML == "*" {
|
||||
return
|
||||
}
|
||||
|
||||
err = toml.Unmarshal([]byte(expectedTOML), &expected)
|
||||
require.NoErrorf(t, err, "%s: expected TOML is invalid", path)
|
||||
|
||||
dropFields(reply, ignoreFields...)
|
||||
dropFields(expected, ignoreFields...)
|
||||
|
||||
require.Equal(t, expected, reply)
|
||||
}
|
||||
|
||||
func TestNonJsonRoute(t *testing.T, api API, external bool, method, path, body string, expectedStatus int, expectedResponse string) {
|
||||
response := SendHTTP(api, external, method, path, body)
|
||||
assert.Equalf(t, expectedStatus, response.StatusCode, "%s: status mismatch", path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue