The API allowed composes to have multiple architectures, image types and repositories. Turns out that's not exactly what we want it is not clear how to combine the lits of each. Each architecture might not combine with each image type, and it is not clear which repositories are need for each image build. Lastly, while allowing different image builds to have different distros in the same compose does not appear immediately useful, there is no particular reason to disallow that. This patch reworks the way composes are specified. The intention remains the same, to be able to submit several image builds as one compose. But rather than taking arrays of image types and architectures, take one array of image builds instead, each of which consists of one distro, one architecture, one image build and an array of repositories. In a follow-up patch they will also each contain an array of upload targets. This means that each image build will have the same sort of structure as a compose request in the weldr API. The reason we want to submit an array of them rather than have them as individual composes, is that in a follow-up patch we will introduce the concept of a "finalizer", or "call-back" or something to that effect, which will be triggered when all the images have been built successfully. The use-case is, as always, koji, which requires this. Signed-off-by: Tom Gundersen <teg@jklm.no>
69 lines
2 KiB
Go
69 lines
2 KiB
Go
// osbuild-rcm-tests run tests against running osbuild-composer instance that was spawned using the
|
|
// osbuild-rcm.socket unit. It defines the expected use cases of the RCM API.
|
|
|
|
// +build integration
|
|
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestRCM(t *testing.T) {
|
|
// This is the first request the user sends to osbuild.
|
|
submitBody := `
|
|
{
|
|
"image_builds":
|
|
[
|
|
{
|
|
"distribution": "fedora-31",
|
|
"architecture": "x86_64",
|
|
"image_type": "qcow2",
|
|
"repositories":
|
|
[
|
|
{
|
|
"baseurl": "http://download.fedoraproject.org/pub/fedora/linux/releases/30/Everything/x86_64/os/"
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
`
|
|
// This is what the user gets back.
|
|
var submitResponse struct {
|
|
UUID uuid.UUID `json:"compose_id"`
|
|
}
|
|
// Then it is possible to get the status on the /v1/compose/<UUID> endpoint.
|
|
// And finally this is the response from getting the status.
|
|
var statusResponse struct {
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
// osbuild instance running on localhost
|
|
socket := "http://127.0.0.1:80/"
|
|
endpoint := "v1/compose"
|
|
|
|
// Case 1: POST request
|
|
|
|
resp, err := http.Post(socket+endpoint, "application/json", strings.NewReader(submitBody))
|
|
require.Nilf(t, err, "Failed to submit a compose: %v", err)
|
|
require.Equalf(t, resp.StatusCode, 200, "Error: the %v returned non 200 status. Full response: %v", endpoint, resp)
|
|
err = json.NewDecoder(resp.Body).Decode(&submitResponse)
|
|
require.Nilf(t, err, "Failed to decode JSON response from %v", endpoint)
|
|
|
|
// Case 2: GET status
|
|
|
|
statusEndpoint := endpoint + "/" + submitResponse.UUID.String()
|
|
resp, err = http.Get(socket + statusEndpoint)
|
|
require.Nilf(t, err, "Failed to get a status: %v", err)
|
|
require.Equalf(t, resp.StatusCode, 200, "Error: the %v returned non 200 status. Full response: %v", endpoint, resp)
|
|
err = json.NewDecoder(resp.Body).Decode(&statusResponse)
|
|
require.Nilf(t, err, "Failed to decode JSON response from %v", endpoint)
|
|
|
|
}
|