From 8a25d045d9d2e13685f5eab1e313114328f96c91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Budai?= Date: Thu, 14 May 2020 14:23:21 +0200 Subject: [PATCH] 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. --- cmd/osbuild-tests/main_test.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/cmd/osbuild-tests/main_test.go b/cmd/osbuild-tests/main_test.go index f1d2c75a5..1656e1fac 100644 --- a/cmd/osbuild-tests/main_test.go +++ b/cmd/osbuild-tests/main_test.go @@ -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)