tests/image: move constants to a subpackage
The cmd/osbuild-image-tests package is becoming bigger than I would like to. It will be nice to split it to some smaller pieces at some point. This commit does the first step - splits off the first subpackage containing all the constants.
This commit is contained in:
parent
b109ec878e
commit
0041ae5655
6 changed files with 74 additions and 70 deletions
|
|
@ -1,32 +0,0 @@
|
|||
// +build travis
|
||||
|
||||
package main
|
||||
|
||||
import "os/exec"
|
||||
|
||||
func getOsbuildCommand(store string) *exec.Cmd {
|
||||
cmd := exec.Command(
|
||||
"python3",
|
||||
"-m", "osbuild",
|
||||
"--libdir", ".",
|
||||
"--store", store,
|
||||
"--json",
|
||||
"-",
|
||||
)
|
||||
cmd.Dir = "osbuild"
|
||||
return cmd
|
||||
}
|
||||
|
||||
var testPaths = struct {
|
||||
imageInfo string
|
||||
privateKey string
|
||||
testCasesDirectory string
|
||||
userData string
|
||||
metaData string
|
||||
}{
|
||||
imageInfo: "tools/image-info",
|
||||
privateKey: "test/keyring/id_rsa",
|
||||
testCasesDirectory: "test/cases",
|
||||
userData: "test/cloud-init/user-data",
|
||||
metaData: "test/cloud-init/meta-data",
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
// +build integration,!travis
|
||||
|
||||
package main
|
||||
|
||||
import "os/exec"
|
||||
|
||||
func getOsbuildCommand(store string) *exec.Cmd {
|
||||
return exec.Command(
|
||||
"osbuild",
|
||||
"--store", store,
|
||||
"--json",
|
||||
"-",
|
||||
)
|
||||
}
|
||||
|
||||
var testPaths = struct {
|
||||
imageInfo string
|
||||
privateKey string
|
||||
testCasesDirectory string
|
||||
userData string
|
||||
metaData string
|
||||
}{
|
||||
imageInfo: "/usr/libexec/osbuild-composer/image-info",
|
||||
privateKey: "/usr/share/tests/osbuild-composer/keyring/id_rsa",
|
||||
testCasesDirectory: "/usr/share/tests/osbuild-composer/cases",
|
||||
userData: "/usr/share/tests/osbuild-composer/cloud-init/user-data",
|
||||
metaData: "/usr/share/tests/osbuild-composer/cloud-init/meta-data",
|
||||
}
|
||||
32
cmd/osbuild-image-tests/constants/constants-travis.go
Normal file
32
cmd/osbuild-image-tests/constants/constants-travis.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// +build travis
|
||||
|
||||
package constants
|
||||
|
||||
import "os/exec"
|
||||
|
||||
func GetOsbuildCommand(store string) *exec.Cmd {
|
||||
cmd := exec.Command(
|
||||
"python3",
|
||||
"-m", "osbuild",
|
||||
"--libdir", ".",
|
||||
"--store", store,
|
||||
"--json",
|
||||
"-",
|
||||
)
|
||||
cmd.Dir = "osbuild"
|
||||
return cmd
|
||||
}
|
||||
|
||||
var TestPaths = struct {
|
||||
ImageInfo string
|
||||
PrivateKey string
|
||||
TestCasesDirectory string
|
||||
UserData string
|
||||
MetaData string
|
||||
}{
|
||||
ImageInfo: "tools/image-info",
|
||||
PrivateKey: "test/keyring/id_rsa",
|
||||
TestCasesDirectory: "test/cases",
|
||||
UserData: "test/cloud-init/user-data",
|
||||
MetaData: "test/cloud-init/meta-data",
|
||||
}
|
||||
28
cmd/osbuild-image-tests/constants/constants.go
Normal file
28
cmd/osbuild-image-tests/constants/constants.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// +build integration,!travis
|
||||
|
||||
package constants
|
||||
|
||||
import "os/exec"
|
||||
|
||||
func GetOsbuildCommand(store string) *exec.Cmd {
|
||||
return exec.Command(
|
||||
"osbuild",
|
||||
"--store", store,
|
||||
"--json",
|
||||
"-",
|
||||
)
|
||||
}
|
||||
|
||||
var TestPaths = struct {
|
||||
ImageInfo string
|
||||
PrivateKey string
|
||||
TestCasesDirectory string
|
||||
UserData string
|
||||
MetaData string
|
||||
}{
|
||||
ImageInfo: "/usr/libexec/osbuild-composer/image-info",
|
||||
PrivateKey: "/usr/share/tests/osbuild-composer/keyring/id_rsa",
|
||||
TestCasesDirectory: "/usr/share/tests/osbuild-composer/cases",
|
||||
UserData: "/usr/share/tests/osbuild-composer/cloud-init/user-data",
|
||||
MetaData: "/usr/share/tests/osbuild-composer/cloud-init/meta-data",
|
||||
}
|
||||
|
|
@ -4,7 +4,6 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
|
@ -13,6 +12,9 @@ import (
|
|||
"runtime"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/cmd/osbuild-image-tests/constants"
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
)
|
||||
|
||||
// withNetworkNamespace provides the function f with a new network namespace
|
||||
|
|
@ -97,8 +99,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,
|
||||
testPaths.userData,
|
||||
testPaths.metaData,
|
||||
constants.TestPaths.UserData,
|
||||
constants.TestPaths.MetaData,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/cmd/osbuild-image-tests/constants"
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
)
|
||||
|
||||
|
|
@ -48,7 +49,8 @@ func runOsbuild(manifest []byte, store string) (string, error) {
|
|||
// See https://github.com/osbuild/osbuild/issues/351
|
||||
osbuildMutex.Lock()
|
||||
defer osbuildMutex.Unlock()
|
||||
cmd := getOsbuildCommand(store)
|
||||
|
||||
cmd := constants.GetOsbuildCommand(store)
|
||||
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdin = bytes.NewReader(manifest)
|
||||
|
|
@ -85,7 +87,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(testPaths.imageInfo, imagePath)
|
||||
cmd := exec.Command(constants.TestPaths.ImageInfo, imagePath)
|
||||
cmd.Stderr = os.Stderr
|
||||
reader, writer := io.Pipe()
|
||||
cmd.Stdout = writer
|
||||
|
|
@ -190,7 +192,7 @@ func testSSH(t *testing.T, address string, privateKey string, ns *netNS) {
|
|||
func testBootUsingQemu(t *testing.T, imagePath string) {
|
||||
err := withNetworkNamespace(func(ns netNS) error {
|
||||
return withBootedQemuImage(imagePath, ns, func() error {
|
||||
testSSH(t, "localhost", testPaths.privateKey, &ns)
|
||||
testSSH(t, "localhost", constants.TestPaths.PrivateKey, &ns)
|
||||
return nil
|
||||
})
|
||||
})
|
||||
|
|
@ -200,7 +202,7 @@ func testBootUsingQemu(t *testing.T, imagePath string) {
|
|||
func testBootUsingNspawnImage(t *testing.T, imagePath string, outputID string) {
|
||||
err := withNetworkNamespace(func(ns netNS) error {
|
||||
return withBootedNspawnImage(imagePath, outputID, ns, func() error {
|
||||
testSSH(t, "localhost", testPaths.privateKey, &ns)
|
||||
testSSH(t, "localhost", constants.TestPaths.PrivateKey, &ns)
|
||||
return nil
|
||||
})
|
||||
})
|
||||
|
|
@ -211,7 +213,7 @@ func testBootUsingNspawnDirectory(t *testing.T, imagePath string, outputID strin
|
|||
err := withNetworkNamespace(func(ns netNS) error {
|
||||
return withExtractedTarArchive(imagePath, func(dir string) error {
|
||||
return withBootedNspawnDirectory(dir, outputID, ns, func() error {
|
||||
testSSH(t, "localhost", testPaths.privateKey, &ns)
|
||||
testSSH(t, "localhost", constants.TestPaths.PrivateKey, &ns)
|
||||
return nil
|
||||
})
|
||||
})
|
||||
|
|
@ -342,7 +344,7 @@ func runTestcase(t *testing.T, testcase testcaseStruct) {
|
|||
|
||||
// getAllCases returns paths to all testcases in the testcase directory
|
||||
func getAllCases() ([]string, error) {
|
||||
cases, err := ioutil.ReadDir(testPaths.testCasesDirectory)
|
||||
cases, err := ioutil.ReadDir(constants.TestPaths.TestCasesDirectory)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot list test cases: %#v", err)
|
||||
}
|
||||
|
|
@ -353,7 +355,7 @@ func getAllCases() ([]string, error) {
|
|||
continue
|
||||
}
|
||||
|
||||
casePath := fmt.Sprintf("%s/%s", testPaths.testCasesDirectory, c.Name())
|
||||
casePath := fmt.Sprintf("%s/%s", constants.TestPaths.TestCasesDirectory, c.Name())
|
||||
casesPaths = append(casesPaths, casePath)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue