test: set PYTHONPATH for image-info on travis

Create a GetImageInfoCommand analogous to GetOsbuildCommand that
will adjust the PYTHONPATH for image-info on travis so that the
osbuild python module is accessible.
This commit is contained in:
Christian Kellner 2020-07-08 23:40:09 +02:00 committed by Ondřej Budai
parent 84022a7889
commit 44f0ba368f
3 changed files with 21 additions and 2 deletions

View file

@ -2,7 +2,10 @@
package constants
import "os/exec"
import (
"os"
"os/exec"
)
func GetOsbuildCommand(store, outputDirectory string) *exec.Cmd {
cmd := exec.Command(
@ -18,6 +21,15 @@ func GetOsbuildCommand(store, outputDirectory string) *exec.Cmd {
return cmd
}
func GetImageInfoCommand(imagePath string) *exec.Cmd {
cmd := exec.Command(
"tools/image-info",
imagePath,
)
cmd.Env = append(os.Environ(), "PYTHONPATH=osbuild")
return cmd
}
var TestPaths = struct {
ImageInfo string
PrivateKey string

View file

@ -14,6 +14,13 @@ func GetOsbuildCommand(store, outputDirectory string) *exec.Cmd {
)
}
func GetImageInfoCommand(imagePath string) *exec.Cmd {
return exec.Command(
"/usr/libexec/osbuild-composer/image-info",
imagePath,
)
}
var TestPaths = struct {
ImageInfo string
PrivateKey string

View file

@ -73,7 +73,7 @@ func testImageInfo(t *testing.T, imagePath string, rawImageInfoExpected []byte)
err := json.Unmarshal(rawImageInfoExpected, &imageInfoExpected)
require.NoErrorf(t, err, "cannot decode expected image info: %#v", err)
cmd := exec.Command(constants.TestPaths.ImageInfo, imagePath)
cmd := constants.GetImageInfoCommand(imagePath)
cmd.Stderr = os.Stderr
reader, writer := io.Pipe()
cmd.Stdout = writer