tests/image: extract constants containing paths
We need to use different values for path constants when running the tests on the Travis CI. This is the first step to achieve this. Note that this commit may be reverted when Travis CI is dropped.
This commit is contained in:
parent
d4ecebd38a
commit
03ae0007af
3 changed files with 25 additions and 13 deletions
18
cmd/osbuild-image-tests/constants.go
Normal file
18
cmd/osbuild-image-tests/constants.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package main
|
||||
|
||||
import "os/exec"
|
||||
|
||||
func getOsbuildCommand(store string) *exec.Cmd {
|
||||
return exec.Command(
|
||||
"osbuild",
|
||||
"--store", store,
|
||||
"--json",
|
||||
"-",
|
||||
)
|
||||
}
|
||||
|
||||
var imageInfoPath = "/usr/libexec/osbuild-composer/image-info"
|
||||
var privateKeyPath = "/usr/share/tests/osbuild-composer/keyring/id_rsa"
|
||||
var testCasesDirectoryPath = "/usr/share/tests/osbuild-composer/cases"
|
||||
var userDataPath = "/usr/share/tests/osbuild-composer/cloud-init/user-data"
|
||||
var metaDataPath = "/usr/share/tests/osbuild-composer/cloud-init/meta-data"
|
||||
|
|
@ -76,8 +76,8 @@ func withBootedQemuImage(image string, ns netNS, f func() error) error {
|
|||
return withTempFile("", "osbuild-image-tests-cloudinit", func(cloudInitFile *os.File) error {
|
||||
err := writeCloudInitISO(
|
||||
cloudInitFile,
|
||||
"/usr/share/tests/osbuild-composer/cloud-init/user-data",
|
||||
"/usr/share/tests/osbuild-composer/cloud-init/meta-data",
|
||||
userDataPath,
|
||||
metaDataPath,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -36,12 +36,7 @@ type testcaseStruct struct {
|
|||
|
||||
// runOsbuild runs osbuild with the specified manifest and store.
|
||||
func runOsbuild(manifest []byte, store string) (string, error) {
|
||||
cmd := exec.Command(
|
||||
"osbuild",
|
||||
"--store", store,
|
||||
"--json",
|
||||
"-",
|
||||
)
|
||||
cmd := getOsbuildCommand(store)
|
||||
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdin = bytes.NewReader(manifest)
|
||||
|
|
@ -104,7 +99,7 @@ func testImageInfo(imagePath string, rawImageInfoExpected []byte) error {
|
|||
return fmt.Errorf("cannot decode expected image info: %v", err)
|
||||
}
|
||||
|
||||
cmd := exec.Command("/usr/libexec/osbuild-composer/image-info", imagePath)
|
||||
cmd := exec.Command(imageInfoPath, imagePath)
|
||||
cmd.Stderr = os.Stderr
|
||||
reader, writer := io.Pipe()
|
||||
cmd.Stdout = writer
|
||||
|
|
@ -148,7 +143,7 @@ func trySSHOnce(ns netNS) error {
|
|||
ctx,
|
||||
"ssh",
|
||||
"-p", "22",
|
||||
"-i", "/usr/share/tests/osbuild-composer/keyring/id_rsa",
|
||||
"-i", privateKeyPath,
|
||||
"-o", "StrictHostKeyChecking=no",
|
||||
"-o", "UserKnownHostsFile=/dev/null",
|
||||
"redhat@localhost",
|
||||
|
|
@ -302,8 +297,7 @@ func runTestcase(testcase testcaseStruct) error {
|
|||
|
||||
// getAllCases returns paths to all testcases in the testcase directory
|
||||
func getAllCases() ([]string, error) {
|
||||
const casesDirectory = "/usr/share/tests/osbuild-composer/cases"
|
||||
cases, err := ioutil.ReadDir(casesDirectory)
|
||||
cases, err := ioutil.ReadDir(testCasesDirectoryPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot list test cases: %v", err)
|
||||
}
|
||||
|
|
@ -314,7 +308,7 @@ func getAllCases() ([]string, error) {
|
|||
continue
|
||||
}
|
||||
|
||||
casePath := fmt.Sprintf("%s/%s", casesDirectory, c.Name())
|
||||
casePath := fmt.Sprintf("%s/%s", testCasesDirectoryPath, c.Name())
|
||||
casesPaths = append(casesPaths, casePath)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue