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:
parent
d4c083ee9a
commit
8a25d045d9
1 changed files with 29 additions and 1 deletions
|
|
@ -6,12 +6,15 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
@ -101,7 +104,13 @@ func testCompose(t *testing.T, outputType string) {
|
||||||
uuid := startCompose(t, "empty", outputType)
|
uuid := startCompose(t, "empty", outputType)
|
||||||
defer deleteCompose(t, uuid)
|
defer deleteCompose(t, uuid)
|
||||||
status := waitForCompose(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())
|
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
|
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) {
|
func pushBlueprint(t *testing.T, bp *blueprint.Blueprint) {
|
||||||
tmpfile, err := ioutil.TempFile("", "osbuild-test-")
|
tmpfile, err := ioutil.TempFile("", "osbuild-test-")
|
||||||
require.Nilf(t, err, "Could not create temporary file: %v", err)
|
require.Nilf(t, err, "Could not create temporary file: %v", err)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue