tests: add a smoke test that logs exist

Our current tests cannot currently check if the logs can reach all the way
from the worker to the weldr API. This commit adds a simple check that
the /compose/log route returns at least something.

Also the logs are printed when the compose fails.
This commit is contained in:
Ondřej Budai 2020-05-14 14:23:21 +02:00 committed by Lars Karlitski
parent d4c083ee9a
commit 8a25d045d9

View file

@ -6,12 +6,15 @@ import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"os"
"os/exec"
"time"
"github.com/BurntSushi/toml"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/osbuild/osbuild-composer/internal/blueprint"
"github.com/stretchr/testify/require"
@ -101,7 +104,13 @@ func testCompose(t *testing.T, outputType string) {
uuid := startCompose(t, "empty", outputType)
defer deleteCompose(t, uuid)
status := waitForCompose(t, uuid)
require.Equalf(t, "FINISHED", status, "Unexpected compose result: %s", status)
logs := getLogs(t, uuid)
assert.NotEmpty(t, logs, "logs are empty after the build is finished/failed")
if !assert.Equalf(t, "FINISHED", status, "Unexpected compose result: %s", status) {
log.Print("logs from the build: ", logs)
t.FailNow()
}
runComposerCLI(t, false, "compose", "image", uuid.String())
}
@ -157,6 +166,25 @@ func getComposeStatus(t *testing.T, quiet bool, uuid uuid.UUID) string {
return reply.QueueStatus
}
func getLogs(t *testing.T, uuid uuid.UUID) string {
cmd := exec.Command("composer-cli", "compose", "log", uuid.String())
cmd.Stderr = os.Stderr
stdoutReader, err := cmd.StdoutPipe()
require.NoError(t, err)
err = cmd.Start()
require.NoError(t, err)
var buffer bytes.Buffer
_, err = buffer.ReadFrom(stdoutReader)
require.NoError(t, err)
err = cmd.Wait()
require.NoError(t, err)
return buffer.String()
}
func pushBlueprint(t *testing.T, bp *blueprint.Blueprint) {
tmpfile, err := ioutil.TempFile("", "osbuild-test-")
require.Nilf(t, err, "Could not create temporary file: %v", err)