From 44f0ba368f7190c7af1423587b72d551b3e6e921 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Wed, 8 Jul 2020 23:40:09 +0200 Subject: [PATCH] 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. --- .../constants/constants-travis.go | 14 +++++++++++++- cmd/osbuild-image-tests/constants/constants.go | 7 +++++++ cmd/osbuild-image-tests/main_test.go | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/cmd/osbuild-image-tests/constants/constants-travis.go b/cmd/osbuild-image-tests/constants/constants-travis.go index 7a786abe7..c2fffab61 100644 --- a/cmd/osbuild-image-tests/constants/constants-travis.go +++ b/cmd/osbuild-image-tests/constants/constants-travis.go @@ -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 diff --git a/cmd/osbuild-image-tests/constants/constants.go b/cmd/osbuild-image-tests/constants/constants.go index dd4fd30d1..4a966c7aa 100644 --- a/cmd/osbuild-image-tests/constants/constants.go +++ b/cmd/osbuild-image-tests/constants/constants.go @@ -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 diff --git a/cmd/osbuild-image-tests/main_test.go b/cmd/osbuild-image-tests/main_test.go index 164c46bcc..a9c49a78b 100644 --- a/cmd/osbuild-image-tests/main_test.go +++ b/cmd/osbuild-image-tests/main_test.go @@ -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