Skip to content

Commit

Permalink
rcm: reintroduce the submit compose test
Browse files Browse the repository at this point in the history
This was previously moved away because of the dnf-json requirement, but
now that rcm api contains the rpmmd structure directly, we can mock it
and use this test again.
  • Loading branch information
Martin Sehnoutka committed Feb 19, 2020
1 parent b87eac6 commit 5a31e6a
Showing 1 changed file with 67 additions and 3 deletions.
70 changes: 67 additions & 3 deletions internal/rcm/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package rcm_test

import (
"bytes"
"encoding/json"
"github.com/google/uuid"
"net/http"
"net/http/httptest"
"regexp"
"testing"

"github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/distro/fedoratest"
rpmmd_mock "github.com/osbuild/osbuild-composer/internal/mocks/rpmmd"
"github.com/osbuild/osbuild-composer/internal/rcm"
"github.com/osbuild/osbuild-composer/internal/store"
)
Expand Down Expand Up @@ -46,9 +49,9 @@ func TestBasicRcmAPI(t *testing.T) {
{"GET", "/v1/compose/7802c476-9cd1-41b7-ba81-43c1906bce73", `{"status":"RUNNING"}`, "application/json", http.StatusBadRequest, `{"error_reason":"Compose UUID does not exist"}`},
}

registry := distro.NewRegistry([]string{"."})
distroStruct := fedoratest.New()
api := rcm.New(nil, store.New(nil, distroStruct, *registry))
registry := distro.WithSingleDistro(distroStruct)
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)
Expand All @@ -66,4 +69,65 @@ func TestBasicRcmAPI(t *testing.T) {
t.Errorf("The response to %s request to %s should match this regex %s but returns %s", c.Method, c.Path, c.ExpectedBodyRegex, response_body)
}
}
}
}

func TestSubmitCompose(t *testing.T) {
// Test the most basic use case: Submit a new job and get its status.
distroStruct := fedoratest.New()
registry := distro.WithSingleDistro(distroStruct)
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"`
}
var status_reply struct {
Status string `json:"status,omitempty"`
ErrorReason string `json:"error_reason,omitempty"`
}

var cases = []struct {
Method string
Path string
Body string
ContentType string
}{
{
"POST",
"/v1/compose",
`{"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",
},
}

for n, c := range cases {
// Submit job
t.Logf("RCM API submit compose, case %d\n", n)
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)
}
decoder := json.NewDecoder(resp.Body)
decoder.DisallowUnknownFields()
err := decoder.Decode(&submit_reply)
if err != nil {
t.Fatal("Failed to decode response to /v1/compose:", err)
}
// Get the status
t.Log("RCM API get status")
resp = internalRequest(api, "GET", "/v1/compose/"+submit_reply.UUID.String(), "", "")
decoder = json.NewDecoder(resp.Body)
decoder.DisallowUnknownFields()
err = decoder.Decode(&status_reply)
if err != nil {
t.Fatal("Failed to decode response to /v1/compose/UUID:", err)
}
if status_reply.ErrorReason != "" {
t.Error("Failed to get compose status, reason:", status_reply.ErrorReason)
}
}
}

0 comments on commit 5a31e6a

Please sign in to comment.