test/image: pass a temporary store to osbuild
When edd7b37ea added `--output-directory` to the invocation of osbuild,
it also removed `--store`.
This was a mistake: osbuild's default store is `.osbuild`, which is not
what we want. Restore the old behavior of passing a temporary directory,
but use the same for each test run.
This commit is contained in:
parent
f173714fe2
commit
b3e14a4e68
3 changed files with 19 additions and 11 deletions
|
|
@ -4,11 +4,12 @@ package constants
|
||||||
|
|
||||||
import "os/exec"
|
import "os/exec"
|
||||||
|
|
||||||
func GetOsbuildCommand(outputDirectory string) *exec.Cmd {
|
func GetOsbuildCommand(store, outputDirectory string) *exec.Cmd {
|
||||||
cmd := exec.Command(
|
cmd := exec.Command(
|
||||||
"python3",
|
"python3",
|
||||||
"-m", "osbuild",
|
"-m", "osbuild",
|
||||||
"--libdir", ".",
|
"--libdir", ".",
|
||||||
|
"--store", store,
|
||||||
"--output-directory", outputDirectory,
|
"--output-directory", outputDirectory,
|
||||||
"--json",
|
"--json",
|
||||||
"-",
|
"-",
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,10 @@ package constants
|
||||||
|
|
||||||
import "os/exec"
|
import "os/exec"
|
||||||
|
|
||||||
func GetOsbuildCommand(outputDirectory string) *exec.Cmd {
|
func GetOsbuildCommand(store, outputDirectory string) *exec.Cmd {
|
||||||
return exec.Command(
|
return exec.Command(
|
||||||
"osbuild",
|
"osbuild",
|
||||||
|
"--store", store,
|
||||||
"--output-directory", outputDirectory,
|
"--output-directory", outputDirectory,
|
||||||
"--json",
|
"--json",
|
||||||
"-",
|
"-",
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ type testcaseStruct struct {
|
||||||
var osbuildMutex sync.Mutex
|
var osbuildMutex sync.Mutex
|
||||||
|
|
||||||
// runOsbuild runs osbuild with the specified manifest and output-directory.
|
// runOsbuild runs osbuild with the specified manifest and output-directory.
|
||||||
func runOsbuild(manifest []byte, outputDirectory string) error {
|
func runOsbuild(manifest []byte, store, outputDirectory string) error {
|
||||||
// Osbuild crashes when multiple instances are run at a time.
|
// Osbuild crashes when multiple instances are run at a time.
|
||||||
// This mutex enforces that there's always just one osbuild instance.
|
// This mutex enforces that there's always just one osbuild instance.
|
||||||
// This should be removed once osbuild is fixed.
|
// This should be removed once osbuild is fixed.
|
||||||
|
|
@ -51,7 +51,7 @@ func runOsbuild(manifest []byte, outputDirectory string) error {
|
||||||
osbuildMutex.Lock()
|
osbuildMutex.Lock()
|
||||||
defer osbuildMutex.Unlock()
|
defer osbuildMutex.Unlock()
|
||||||
|
|
||||||
cmd := constants.GetOsbuildCommand(outputDirectory)
|
cmd := constants.GetOsbuildCommand(store, outputDirectory)
|
||||||
|
|
||||||
cmd.Stdin = bytes.NewReader(manifest)
|
cmd.Stdin = bytes.NewReader(manifest)
|
||||||
var outBuffer bytes.Buffer
|
var outBuffer bytes.Buffer
|
||||||
|
|
@ -350,18 +350,16 @@ func testImage(t *testing.T, testcase testcaseStruct, imagePath string) {
|
||||||
|
|
||||||
// runTestcase builds the pipeline specified in the testcase and then it
|
// runTestcase builds the pipeline specified in the testcase and then it
|
||||||
// tests the result
|
// tests the result
|
||||||
func runTestcase(t *testing.T, testcase testcaseStruct) {
|
func runTestcase(t *testing.T, testcase testcaseStruct, store string) {
|
||||||
outputDirectory, err := ioutil.TempDir("/var/tmp", "osbuild-image-tests-*")
|
outputDirectory, err := ioutil.TempDir("/var/tmp", "osbuild-image-tests-*")
|
||||||
require.NoErrorf(t, err, "cannot create temporary output directory: %#v", err)
|
require.NoError(t, err, "error creating temporary output directory")
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
err := os.RemoveAll(outputDirectory)
|
err := os.RemoveAll(outputDirectory)
|
||||||
if err != nil {
|
require.NoError(t, err, "error removing temporary output directory")
|
||||||
log.Printf("cannot remove temporary output directory: %#v\n", err)
|
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err = runOsbuild(testcase.Manifest, outputDirectory)
|
err = runOsbuild(testcase.Manifest, store, outputDirectory)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
imagePath := fmt.Sprintf("%s/%s", outputDirectory, testcase.ComposeRequest.Filename)
|
imagePath := fmt.Sprintf("%s/%s", outputDirectory, testcase.ComposeRequest.Filename)
|
||||||
|
|
@ -391,6 +389,14 @@ func getAllCases() ([]string, error) {
|
||||||
|
|
||||||
// runTests opens, parses and runs all the specified testcases
|
// runTests opens, parses and runs all the specified testcases
|
||||||
func runTests(t *testing.T, cases []string) {
|
func runTests(t *testing.T, cases []string) {
|
||||||
|
store, err := ioutil.TempDir("/var/tmp", "osbuild-image-tests-*")
|
||||||
|
require.NoError(t, err, "error creating temporary store")
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
err := os.RemoveAll(store)
|
||||||
|
require.NoError(t, err, "error removing temporary store")
|
||||||
|
}()
|
||||||
|
|
||||||
for _, path := range cases {
|
for _, path := range cases {
|
||||||
t.Run(path, func(t *testing.T) {
|
t.Run(path, func(t *testing.T) {
|
||||||
f, err := os.Open(path)
|
f, err := os.Open(path)
|
||||||
|
|
@ -414,7 +420,7 @@ func runTests(t *testing.T, cases []string) {
|
||||||
// Also the output is clearer this way.
|
// Also the output is clearer this way.
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
runTestcase(t, testcase)
|
runTestcase(t, testcase, store)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue