rcm: introduce rpmmd member of the api structure

This is needed for unit tests, because it wasn't possible to mock the
rpmmd module before. This also requires that the checksum is moved to
the compose request and evaluated in the endpoint handler instead of
push compose. I think it makes sense to have the checksum in the compose
request directly.

Also a "module platform ID" is required now, but we don't have the
"global" distribution any more, so this patch introduces mapping from a
distribution to the module platform ID.
This commit is contained in:
Martin Sehnoutka 2020-02-19 11:50:38 +01:00 committed by Tom Gundersen
parent d1c766abe7
commit 923a0b0b97
5 changed files with 72 additions and 20 deletions

View file

@ -2,14 +2,16 @@ package rcm_test
import (
"bytes"
"encoding/json"
"github.com/google/uuid"
"net/http"
"net/http/httptest"
"regexp"
"testing"
"github.com/google/uuid"
"github.com/osbuild/osbuild-composer/internal/distro/fedoratest"
distro_mock "github.com/osbuild/osbuild-composer/internal/mocks/distro"
rpmmd_mock "github.com/osbuild/osbuild-composer/internal/mocks/rpmmd"
"github.com/osbuild/osbuild-composer/internal/rcm"
"github.com/osbuild/osbuild-composer/internal/store"
)
@ -49,7 +51,7 @@ func TestBasicRcmAPI(t *testing.T) {
registry := distro_mock.NewRegistry()
distroStruct := fedoratest.New()
api := rcm.New(nil, store.New(nil, distroStruct, *registry))
api := rcm.New(nil, store.New(nil, distroStruct, *registry), rpmmd_mock.NewRPMMDMock(rpmmd_mock.BaseFixture()))
for _, c := range cases {
resp := internalRequest(api, c.Method, c.Path, c.Body, c.ContentType)
@ -71,9 +73,9 @@ func TestBasicRcmAPI(t *testing.T) {
func TestSubmitCompose(t *testing.T) {
// Test the most basic use case: Submit a new job and get its status.
registry := distro_mock.NewRegistry()
distroStruct := fedoratest.New()
api := rcm.New(nil, store.New(nil, distroStruct, *registry))
registry := distro_mock.NewRegistry()
api := rcm.New(nil, store.New(nil, distroStruct, *registry), rpmmd_mock.NewRPMMDMock(rpmmd_mock.BaseFixture()))
var submit_reply struct {
UUID uuid.UUID `json:"compose_id"`
@ -92,7 +94,12 @@ func TestSubmitCompose(t *testing.T) {
{
"POST",
"/v1/compose",
`{"distribution": "fedora-30", "image_types": ["qcow2"], "architectures":["x86_64"], "repositories": [{"url": "aaa"}]}`,
`{"distribution": "fedora-30",
"image_types": ["qcow2"],
"architectures":["x86_64"],
"repositories": [{
"url": "http://download.fedoraproject.org/pub/fedora/linux/releases/30/Everything/x86_64/os/"
}]}`,
"application/json",
},
}
@ -100,7 +107,6 @@ func TestSubmitCompose(t *testing.T) {
for n, c := range cases {
// Submit job
t.Logf("RCM API submit compose, case %d\n", n)
//resp := internalRequest(api, "POST", "/v1/compose", `{"distribution": "fedora-30", "image_types": ["test_output"], "architectures":["test_arch"], "repositories": [{"url": "aaa", "checksum": "bbb"}]}`, "application/json")
resp := internalRequest(api, c.Method, c.Path, c.Body, c.ContentType)
if resp.StatusCode != http.StatusOK {
t.Fatal("Failed to call /v1/compose, HTTP status code:", resp.StatusCode)