Merge pull request #19118 from Luap99/ginkgo

test/e2e: several fixes
This commit is contained in:
OpenShift Merge Robot
2023-07-05 07:23:50 -04:00
committed by GitHub
21 changed files with 94 additions and 159 deletions

View File

@ -56,7 +56,6 @@ type PodmanTestIntegration struct {
SignaturePolicyPath string SignaturePolicyPath string
CgroupManager string CgroupManager string
Host HostOS Host HostOS
Timings []string
TmpDir string TmpDir string
RemoteStartErr error RemoteStartErr error
} }
@ -82,9 +81,6 @@ type testResultsSortedLength struct{ testResultsSorted }
func (a testResultsSorted) Less(i, j int) bool { return a[i].length < a[j].length } func (a testResultsSorted) Less(i, j int) bool { return a[i].length < a[j].length }
var testResults []testResult
var testResultsMutex sync.Mutex
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
if reexec.Init() { if reexec.Init() {
return return
@ -107,6 +103,7 @@ var (
err error err error
podmanTest *PodmanTestIntegration podmanTest *PodmanTestIntegration
safeIPOctets [2]uint8 safeIPOctets [2]uint8
timingsFile *os.File
_ = BeforeEach(func() { _ = BeforeEach(func() {
tempdir, err = CreateTempDirInTempDir() tempdir, err = CreateTempDirInTempDir()
@ -129,9 +126,18 @@ var (
}) })
) )
const (
// lockdir - do not use directly use LockTmpDir
lockdir = "libpodlock"
// imageCacheDir - do not use directly use ImageCacheDir
imageCacheDir = "imagecachedir"
)
var _ = SynchronizedBeforeSuite(func() []byte { var _ = SynchronizedBeforeSuite(func() []byte {
globalTmpDir := GinkgoT().TempDir()
// make cache dir // make cache dir
ImageCacheDir = filepath.Join(os.TempDir(), "imagecachedir") ImageCacheDir = filepath.Join(globalTmpDir, imageCacheDir)
if err := os.MkdirAll(ImageCacheDir, 0700); err != nil { if err := os.MkdirAll(ImageCacheDir, 0700); err != nil {
GinkgoWriter.Printf("%q\n", err) GinkgoWriter.Printf("%q\n", err)
os.Exit(1) os.Exit(1)
@ -140,7 +146,7 @@ var _ = SynchronizedBeforeSuite(func() []byte {
// Cache images // Cache images
cwd, _ := os.Getwd() cwd, _ := os.Getwd()
INTEGRATION_ROOT = filepath.Join(cwd, "../../") INTEGRATION_ROOT = filepath.Join(cwd, "../../")
podman := PodmanTestSetup(os.TempDir()) podman := PodmanTestSetup(GinkgoT().TempDir())
// Pull cirros but don't put it into the cache // Pull cirros but don't put it into the cache
pullImages := []string{CIRROS_IMAGE, fedoraToolbox, volumeTest} pullImages := []string{CIRROS_IMAGE, fedoraToolbox, volumeTest}
@ -158,23 +164,8 @@ var _ = SynchronizedBeforeSuite(func() []byte {
// tests are remote, this is a no-op // tests are remote, this is a no-op
populateCache(podman) populateCache(podman)
host := GetHostDistributionInfo() if err := os.MkdirAll(filepath.Join(globalTmpDir, lockdir), 0700); err != nil {
if host.Distribution == "rhel" && strings.HasPrefix(host.Version, "7") { GinkgoWriter.Printf("%q\n", err)
f, err := os.OpenFile("/proc/sys/user/max_user_namespaces", os.O_WRONLY, 0644)
if err != nil {
GinkgoWriter.Println("Unable to enable userspace on RHEL 7")
os.Exit(1)
}
_, err = f.WriteString("15000")
if err != nil {
GinkgoWriter.Println("Unable to enable userspace on RHEL 7")
os.Exit(1)
}
f.Close()
}
path, err := os.MkdirTemp("", "libpodlock")
if err != nil {
GinkgoWriter.Println(err)
os.Exit(1) os.Exit(1)
} }
@ -183,11 +174,19 @@ var _ = SynchronizedBeforeSuite(func() []byte {
podman.StopRemoteService() podman.StopRemoteService()
} }
return []byte(path) // remove temporary podman files, images are now cached in ImageCacheDir
rmAll(podman.PodmanBinary, podman.TempDir)
return []byte(globalTmpDir)
}, func(data []byte) { }, func(data []byte) {
cwd, _ := os.Getwd() cwd, _ := os.Getwd()
INTEGRATION_ROOT = filepath.Join(cwd, "../../") INTEGRATION_ROOT = filepath.Join(cwd, "../../")
LockTmpDir = string(data) globalTmpDir := string(data)
ImageCacheDir = filepath.Join(globalTmpDir, imageCacheDir)
LockTmpDir = filepath.Join(globalTmpDir, lockdir)
timingsFile, err = os.Create(fmt.Sprintf("%s/timings-%d", LockTmpDir, GinkgoParallelProcess()))
Expect(err).ToNot(HaveOccurred())
}) })
func (p *PodmanTestIntegration) Setup() { func (p *PodmanTestIntegration) Setup() {
@ -196,13 +195,8 @@ func (p *PodmanTestIntegration) Setup() {
} }
var _ = SynchronizedAfterSuite(func() { var _ = SynchronizedAfterSuite(func() {
f, err := os.Create(fmt.Sprintf("%s/timings-%d", LockTmpDir, GinkgoParallelProcess())) timingsFile.Close()
Expect(err).ToNot(HaveOccurred()) timingsFile = nil
defer f.Close()
for _, result := range testResults {
_, err := f.WriteString(fmt.Sprintf("%s\t\t%f\n", result.name, result.length))
Expect(err).ToNot(HaveOccurred(), "write timings")
}
}, },
func() { func() {
testTimings := make(testResultsSorted, 0, 2000) testTimings := make(testResultsSorted, 0, 2000)
@ -232,30 +226,18 @@ var _ = SynchronizedAfterSuite(func() {
GinkgoWriter.Printf("%s\t\t%f\n", result.name, result.length) GinkgoWriter.Printf("%s\t\t%f\n", result.name, result.length)
} }
// previous runroot cwd, _ := os.Getwd()
tempdir, err := CreateTempDirInTempDir() rmAll(getPodmanBinary(cwd), ImageCacheDir)
if err != nil {
os.Exit(1)
}
podmanTest := PodmanTestCreate(tempdir)
defer os.RemoveAll(tempdir)
if err := os.RemoveAll(podmanTest.Root); err != nil {
GinkgoWriter.Printf("%q\n", err)
}
// If running remote, we need to stop the associated podman system service
if podmanTest.RemoteTest {
podmanTest.StopRemoteService()
}
// for localized tests, this removes the image cache dir and for remote tests
// this is a no-op
podmanTest.removeCache(podmanTest.ImageCacheDir)
// LockTmpDir can already be removed
os.RemoveAll(LockTmpDir)
}) })
func getPodmanBinary(cwd string) string {
podmanBinary := filepath.Join(cwd, "../../bin/podman")
if os.Getenv("PODMAN_BINARY") != "" {
podmanBinary = os.Getenv("PODMAN_BINARY")
}
return podmanBinary
}
// PodmanTestCreate creates a PodmanTestIntegration instance for the tests // PodmanTestCreate creates a PodmanTestIntegration instance for the tests
func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration { func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration {
var podmanRemoteBinary string var podmanRemoteBinary string
@ -264,10 +246,7 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration {
cwd, _ := os.Getwd() cwd, _ := os.Getwd()
root := filepath.Join(tempDir, "root") root := filepath.Join(tempDir, "root")
podmanBinary := filepath.Join(cwd, "../../bin/podman") podmanBinary := getPodmanBinary(cwd)
if os.Getenv("PODMAN_BINARY") != "" {
podmanBinary = os.Getenv("PODMAN_BINARY")
}
podmanRemoteBinary = filepath.Join(cwd, "../../bin/podman-remote") podmanRemoteBinary = filepath.Join(cwd, "../../bin/podman-remote")
if os.Getenv("PODMAN_REMOTE_BINARY") != "" { if os.Getenv("PODMAN_REMOTE_BINARY") != "" {
@ -342,8 +321,6 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration {
storageOptions = "--storage-driver " + storageFs storageOptions = "--storage-driver " + storageFs
} }
ImageCacheDir = filepath.Join(os.TempDir(), "imagecachedir")
p := &PodmanTestIntegration{ p := &PodmanTestIntegration{
PodmanTest: PodmanTest{ PodmanTest: PodmanTest{
PodmanBinary: podmanBinary, PodmanBinary: podmanBinary,
@ -467,9 +444,8 @@ func (p *PodmanTestIntegration) InspectContainer(name string) []define.InspectCo
func processTestResult(r SpecReport) { func processTestResult(r SpecReport) {
tr := testResult{length: r.RunTime.Seconds(), name: r.FullText()} tr := testResult{length: r.RunTime.Seconds(), name: r.FullText()}
testResultsMutex.Lock() _, err := timingsFile.WriteString(fmt.Sprintf("%s\t\t%f\n", tr.name, tr.length))
testResults = append(testResults, tr) Expect(err).ToNot(HaveOccurred(), "write timings")
testResultsMutex.Unlock()
} }
func GetPortLock(port string) *lockfile.LockFile { func GetPortLock(port string) *lockfile.LockFile {
@ -657,7 +633,7 @@ func (p *PodmanTestIntegration) Cleanup() {
p.StopRemoteService() p.StopRemoteService()
// Nuke tempdir // Nuke tempdir
p.removeCache(p.TempDir) rmAll(p.PodmanBinary, p.TempDir)
// Clean up the registries configuration file ENV variable set in Create // Clean up the registries configuration file ENV variable set in Create
resetRegistriesConfigEnv() resetRegistriesConfigEnv()
@ -993,11 +969,13 @@ func populateCache(podman *PodmanTestIntegration) {
GinkgoWriter.Printf("-----------------------------\n") GinkgoWriter.Printf("-----------------------------\n")
} }
func (p *PodmanTestIntegration) removeCache(path string) { // rmAll removes the direcory and its content,, when running rootless we use
// podman unshare to prevent any subuid/gid problems
func rmAll(podmanBin string, path string) {
// Remove cache dirs // Remove cache dirs
if isRootless() { if isRootless() {
// If rootless, os.RemoveAll() is failed due to permission denied // If rootless, os.RemoveAll() is failed due to permission denied
cmd := exec.Command(p.PodmanBinary, "unshare", "rm", "-rf", path) cmd := exec.Command(podmanBin, "unshare", "rm", "-rf", path)
cmd.Stdout = GinkgoWriter cmd.Stdout = GinkgoWriter
cmd.Stderr = GinkgoWriter cmd.Stderr = GinkgoWriter
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {

View File

@ -243,8 +243,7 @@ var _ = Describe("Podman cp", func() {
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0)) Expect(session).Should(Exit(0))
tmpDir, err := os.MkdirTemp("", "") tmpDir := GinkgoT().TempDir()
Expect(err).ToNot(HaveOccurred())
session = podmanTest.Podman([]string{"cp", container + ":/", tmpDir}) session = podmanTest.Podman([]string{"cp", container + ":/", tmpDir})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()

View File

@ -204,9 +204,7 @@ var _ = Describe("Podman create", func() {
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125)) Expect(session).Should(Exit(125))
tmpDir, err := os.MkdirTemp("", "") tmpDir := GinkgoT().TempDir()
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tmpDir)
podName := "rudolph" podName := "rudolph"
ctrName := "prancer" ctrName := "prancer"

View File

@ -1382,10 +1382,7 @@ USER test1`
}) })
It("podman generate kube omit secret if empty", func() { It("podman generate kube omit secret if empty", func() {
dir, err := os.MkdirTemp(tempdir, "podman") dir := GinkgoT().TempDir()
Expect(err).ShouldNot(HaveOccurred())
defer os.RemoveAll(dir)
podCreate := podmanTest.Podman([]string{"run", "-d", "--pod", "new:" + "noSecretsPod", "--name", "noSecretsCtr", "--volume", dir + ":/foobar", ALPINE}) podCreate := podmanTest.Podman([]string{"run", "-d", "--pod", "new:" + "noSecretsPod", "--name", "noSecretsCtr", "--volume", dir + ":/foobar", ALPINE})
podCreate.WaitWithDefaultTimeout() podCreate.WaitWithDefaultTimeout()

View File

@ -544,10 +544,8 @@ var _ = Describe("Podman generate systemd", func() {
}) })
It("podman generate systemd pod with containers --new", func() { It("podman generate systemd pod with containers --new", func() {
tmpDir, err := os.MkdirTemp("", "") tmpDir := GinkgoT().TempDir()
Expect(err).ToNot(HaveOccurred())
tmpFile := tmpDir + "podID" tmpFile := tmpDir + "podID"
defer os.RemoveAll(tmpDir)
n := podmanTest.Podman([]string{"pod", "create", "--pod-id-file", tmpFile, "--name", "foo"}) n := podmanTest.Podman([]string{"pod", "create", "--pod-id-file", tmpFile, "--name", "foo"})
n.WaitWithDefaultTimeout() n.WaitWithDefaultTimeout()

View File

@ -1,8 +1,6 @@
package integration package integration
import ( import (
"os"
. "github.com/containers/podman/v4/test/utils" . "github.com/containers/podman/v4/test/utils"
. "github.com/onsi/ginkgo/v2" . "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
@ -128,10 +126,8 @@ var _ = Describe("Podman kill", func() {
}) })
It("podman kill --cidfile", func() { It("podman kill --cidfile", func() {
tmpDir, err := os.MkdirTemp("", "") tmpDir := GinkgoT().TempDir()
Expect(err).ToNot(HaveOccurred())
tmpFile := tmpDir + "cid" tmpFile := tmpDir + "cid"
defer os.RemoveAll(tmpDir)
session := podmanTest.Podman([]string{"run", "-dt", "--cidfile", tmpFile, ALPINE, "top"}) session := podmanTest.Podman([]string{"run", "-dt", "--cidfile", tmpFile, ALPINE, "top"})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
@ -148,15 +144,11 @@ var _ = Describe("Podman kill", func() {
}) })
It("podman kill multiple --cidfile", func() { It("podman kill multiple --cidfile", func() {
tmpDir1, err := os.MkdirTemp("", "") tmpDir1 := GinkgoT().TempDir()
Expect(err).ToNot(HaveOccurred())
tmpFile1 := tmpDir1 + "cid" tmpFile1 := tmpDir1 + "cid"
defer os.RemoveAll(tmpDir1)
tmpDir2, err := os.MkdirTemp("", "") tmpDir2 := GinkgoT().TempDir()
Expect(err).ToNot(HaveOccurred())
tmpFile2 := tmpDir2 + "cid" tmpFile2 := tmpDir2 + "cid"
defer os.RemoveAll(tmpDir2)
session := podmanTest.Podman([]string{"run", "-dt", "--cidfile", tmpFile1, ALPINE, "top"}) session := podmanTest.Podman([]string{"run", "-dt", "--cidfile", tmpFile1, ALPINE, "top"})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()

View File

@ -321,12 +321,9 @@ var _ = Describe("Podman pause", func() {
}) })
It("podman pause --cidfile", func() { It("podman pause --cidfile", func() {
tmpDir, err := os.MkdirTemp("", "") tmpDir := GinkgoT().TempDir()
Expect(err).ToNot(HaveOccurred())
tmpFile := tmpDir + "cid" tmpFile := tmpDir + "cid"
defer os.RemoveAll(tmpDir)
session := podmanTest.Podman([]string{"create", "--cidfile", tmpFile, ALPINE, "top"}) session := podmanTest.Podman([]string{"create", "--cidfile", tmpFile, ALPINE, "top"})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0)) Expect(session).Should(Exit(0))
@ -350,8 +347,7 @@ var _ = Describe("Podman pause", func() {
}) })
It("podman pause multiple --cidfile", func() { It("podman pause multiple --cidfile", func() {
tmpDir, err := os.MkdirTemp("", "") tmpDir := GinkgoT().TempDir()
Expect(err).ToNot(HaveOccurred())
tmpFile1 := tmpDir + "cid-1" tmpFile1 := tmpDir + "cid-1"
tmpFile2 := tmpDir + "cid-2" tmpFile2 := tmpDir + "cid-2"

View File

@ -1729,10 +1729,7 @@ func milliCPUToQuota(milliCPU string) int {
} }
func createSourceTarFile(fileName, fileContent, tarFilePath string) error { func createSourceTarFile(fileName, fileContent, tarFilePath string) error {
dir, err := os.MkdirTemp("", "podmanTest") dir := GinkgoT().TempDir()
if err != nil {
return err
}
file, err := os.Create(filepath.Join(dir, fileName)) file, err := os.Create(filepath.Join(dir, fileName))
if err != nil { if err != nil {

View File

@ -215,10 +215,8 @@ var _ = Describe("Podman pod rm", func() {
}) })
It("podman pod start/remove single pod via --pod-id-file", func() { It("podman pod start/remove single pod via --pod-id-file", func() {
tmpDir, err := os.MkdirTemp("", "") tmpDir := GinkgoT().TempDir()
Expect(err).ToNot(HaveOccurred())
tmpFile := tmpDir + "podID" tmpFile := tmpDir + "podID"
defer os.RemoveAll(tmpDir)
podName := "rudolph" podName := "rudolph"
@ -244,9 +242,7 @@ var _ = Describe("Podman pod rm", func() {
}) })
It("podman pod start/remove multiple pods via --pod-id-file", func() { It("podman pod start/remove multiple pods via --pod-id-file", func() {
tmpDir, err := os.MkdirTemp("", "") tmpDir := GinkgoT().TempDir()
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tmpDir)
podIDFiles := []string{} podIDFiles := []string{}
for _, i := range "0123456789" { for _, i := range "0123456789" {

View File

@ -153,10 +153,8 @@ var _ = Describe("Podman pod start", func() {
}) })
It("podman pod start single pod via --pod-id-file", func() { It("podman pod start single pod via --pod-id-file", func() {
tmpDir, err := os.MkdirTemp("", "") tmpDir := GinkgoT().TempDir()
Expect(err).ToNot(HaveOccurred())
tmpFile := tmpDir + "podID" tmpFile := tmpDir + "podID"
defer os.RemoveAll(tmpDir)
podName := "rudolph" podName := "rudolph"
@ -177,9 +175,7 @@ var _ = Describe("Podman pod start", func() {
}) })
It("podman pod start multiple pods via --pod-id-file", func() { It("podman pod start multiple pods via --pod-id-file", func() {
tmpDir, err := os.MkdirTemp("", "") tmpDir := GinkgoT().TempDir()
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tmpDir)
podIDFiles := []string{} podIDFiles := []string{}
for _, i := range "0123456789" { for _, i := range "0123456789" {
@ -209,10 +205,8 @@ var _ = Describe("Podman pod start", func() {
}) })
It("podman pod create --infra-conmon-pod create + start", func() { It("podman pod create --infra-conmon-pod create + start", func() {
tmpDir, err := os.MkdirTemp("", "") tmpDir := GinkgoT().TempDir()
Expect(err).ToNot(HaveOccurred())
tmpFile := tmpDir + "podID" tmpFile := tmpDir + "podID"
defer os.RemoveAll(tmpDir)
podName := "rudolph" podName := "rudolph"
// Create a pod with --infra-conmon-pid. // Create a pod with --infra-conmon-pid.

View File

@ -1,8 +1,6 @@
package integration package integration
import ( import (
"os"
. "github.com/onsi/ginkgo/v2" . "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec" . "github.com/onsi/gomega/gexec"
@ -158,10 +156,8 @@ var _ = Describe("Podman pod stop", func() {
}) })
It("podman pod start/stop single pod via --pod-id-file", func() { It("podman pod start/stop single pod via --pod-id-file", func() {
tmpDir, err := os.MkdirTemp("", "") tmpDir := GinkgoT().TempDir()
Expect(err).ToNot(HaveOccurred())
tmpFile := tmpDir + "podID" tmpFile := tmpDir + "podID"
defer os.RemoveAll(tmpDir)
podName := "rudolph" podName := "rudolph"
@ -187,9 +183,7 @@ var _ = Describe("Podman pod stop", func() {
}) })
It("podman pod start/stop multiple pods via --pod-id-file", func() { It("podman pod start/stop multiple pods via --pod-id-file", func() {
tmpDir, err := os.MkdirTemp("", "") tmpDir := GinkgoT().TempDir()
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(tmpDir)
podIDFiles := []string{} podIDFiles := []string{}
for _, i := range "0123456789" { for _, i := range "0123456789" {

View File

@ -2,7 +2,6 @@ package integration
import ( import (
"fmt" "fmt"
"os"
"time" "time"
. "github.com/containers/podman/v4/test/utils" . "github.com/containers/podman/v4/test/utils"
@ -229,12 +228,9 @@ var _ = Describe("Podman restart", func() {
}) })
It("podman restart --cidfile", func() { It("podman restart --cidfile", func() {
tmpDir, err := os.MkdirTemp("", "") tmpDir := GinkgoT().TempDir()
Expect(err).ToNot(HaveOccurred())
tmpFile := tmpDir + "cid" tmpFile := tmpDir + "cid"
defer os.RemoveAll(tmpDir)
session := podmanTest.Podman([]string{"create", "--cidfile", tmpFile, ALPINE, "top"}) session := podmanTest.Podman([]string{"create", "--cidfile", tmpFile, ALPINE, "top"})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0)) Expect(session).Should(Exit(0))
@ -252,13 +248,10 @@ var _ = Describe("Podman restart", func() {
}) })
It("podman restart multiple --cidfile", func() { It("podman restart multiple --cidfile", func() {
tmpDir, err := os.MkdirTemp("", "") tmpDir := GinkgoT().TempDir()
Expect(err).ToNot(HaveOccurred())
tmpFile1 := tmpDir + "cid-1" tmpFile1 := tmpDir + "cid-1"
tmpFile2 := tmpDir + "cid-2" tmpFile2 := tmpDir + "cid-2"
defer os.RemoveAll(tmpDir)
session := podmanTest.Podman([]string{"run", "--cidfile", tmpFile1, "-d", ALPINE, "top"}) session := podmanTest.Podman([]string{"run", "--cidfile", tmpFile1, "-d", ALPINE, "top"})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0)) Expect(session).Should(Exit(0))

View File

@ -2,7 +2,6 @@ package integration
import ( import (
"fmt" "fmt"
"os"
. "github.com/onsi/ginkgo/v2" . "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
@ -122,12 +121,9 @@ var _ = Describe("Podman rm", func() {
}) })
It("podman rm --cidfile", func() { It("podman rm --cidfile", func() {
tmpDir, err := os.MkdirTemp("", "") tmpDir := GinkgoT().TempDir()
Expect(err).ToNot(HaveOccurred())
tmpFile := tmpDir + "cid" tmpFile := tmpDir + "cid"
defer os.RemoveAll(tmpDir)
session := podmanTest.Podman([]string{"create", "--cidfile", tmpFile, ALPINE, "ls"}) session := podmanTest.Podman([]string{"create", "--cidfile", tmpFile, ALPINE, "ls"})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0)) Expect(session).Should(Exit(0))
@ -143,13 +139,10 @@ var _ = Describe("Podman rm", func() {
}) })
It("podman rm multiple --cidfile", func() { It("podman rm multiple --cidfile", func() {
tmpDir, err := os.MkdirTemp("", "") tmpDir := GinkgoT().TempDir()
Expect(err).ToNot(HaveOccurred())
tmpFile1 := tmpDir + "cid-1" tmpFile1 := tmpDir + "cid-1"
tmpFile2 := tmpDir + "cid-2" tmpFile2 := tmpDir + "cid-2"
defer os.RemoveAll(tmpDir)
session := podmanTest.Podman([]string{"create", "--cidfile", tmpFile1, ALPINE, "ls"}) session := podmanTest.Podman([]string{"create", "--cidfile", tmpFile1, ALPINE, "ls"})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0)) Expect(session).Should(Exit(0))

View File

@ -2,7 +2,6 @@ package integration
import ( import (
"fmt" "fmt"
"os"
"strings" "strings"
. "github.com/onsi/ginkgo/v2" . "github.com/onsi/ginkgo/v2"
@ -258,13 +257,9 @@ var _ = Describe("Podman stop", func() {
}) })
It("podman stop --cidfile", func() { It("podman stop --cidfile", func() {
tmpDir := GinkgoT().TempDir()
tmpDir, err := os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())
tmpFile := tmpDir + "cid" tmpFile := tmpDir + "cid"
defer os.RemoveAll(tmpDir)
session := podmanTest.Podman([]string{"create", "--cidfile", tmpFile, ALPINE, "top"}) session := podmanTest.Podman([]string{"create", "--cidfile", tmpFile, ALPINE, "top"})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0)) Expect(session).Should(Exit(0))
@ -282,14 +277,10 @@ var _ = Describe("Podman stop", func() {
}) })
It("podman stop multiple --cidfile", func() { It("podman stop multiple --cidfile", func() {
tmpDir := GinkgoT().TempDir()
tmpDir, err := os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())
tmpFile1 := tmpDir + "cid-1" tmpFile1 := tmpDir + "cid-1"
tmpFile2 := tmpDir + "cid-2" tmpFile2 := tmpDir + "cid-2"
defer os.RemoveAll(tmpDir)
session := podmanTest.Podman([]string{"run", "--cidfile", tmpFile1, "-d", ALPINE, "top"}) session := podmanTest.Podman([]string{"run", "--cidfile", tmpFile1, "-d", ALPINE, "top"})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0)) Expect(session).Should(Exit(0))

View File

@ -4,7 +4,7 @@ go 1.18
require ( require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 github.com/cpuguy83/go-md2man/v2 v2.0.2
github.com/onsi/ginkgo/v2 v2.9.6 github.com/onsi/ginkgo/v2 v2.11.0
github.com/vbatts/git-validation v1.2.0 github.com/vbatts/git-validation v1.2.0
golang.org/x/tools v0.10.0 golang.org/x/tools v0.10.0
) )

View File

@ -17,9 +17,9 @@ github.com/hashicorp/go-version v1.3.0 h1:McDWVJIU/y+u1BRV06dPaLfLCaT7fUTJLp5r04
github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/onsi/ginkgo/v2 v2.9.6 h1:QPnYLUAuyyKYVInVqnaBV+4k+r6LZ27+iBGAOcqNPHE= github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU=
github.com/onsi/ginkgo/v2 v2.9.6/go.mod h1:cxrmXWykAwTwhQsJOPfdIDiJ+l2RYq7U8hFU+M/1uw0= github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM=
github.com/onsi/gomega v1.27.7 h1:fVih9JD6ogIiHUN6ePK7HJidyEDpWGVB5mzM7cWNXoU= github.com/onsi/gomega v1.27.8 h1:gegWiwZjBsf2DgiSbf5hpokZ98JVDMcWkUiigk6/KXc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=

View File

@ -32,6 +32,9 @@ func BuildGenerateCommand() command.Command {
{Name: "template-data", KeyPath: "CustomTemplateData", {Name: "template-data", KeyPath: "CustomTemplateData",
UsageArgument: "template-data-file", UsageArgument: "template-data-file",
Usage: "If specified, generate will use the contents of the file passed as data to be rendered in the test file template"}, Usage: "If specified, generate will use the contents of the file passed as data to be rendered in the test file template"},
{Name: "tags", KeyPath: "Tags",
UsageArgument: "build-tags",
Usage: "If specified, generate will create a test file that uses the given build tags (i.e. `--tags e2e,!unit` will add `//go:build e2e,!unit`)"},
}, },
&conf, &conf,
types.GinkgoFlagSections{}, types.GinkgoFlagSections{},
@ -59,6 +62,7 @@ You can also pass a <filename> of the form "file.go" and generate will emit "fil
} }
type specData struct { type specData struct {
BuildTags string
Package string Package string
Subject string Subject string
PackageImportPath string PackageImportPath string
@ -93,6 +97,7 @@ func generateTestFileForSubject(subject string, conf GeneratorsConfig) {
} }
data := specData{ data := specData{
BuildTags: getBuildTags(conf.Tags),
Package: determinePackageName(packageName, conf.Internal), Package: determinePackageName(packageName, conf.Internal),
Subject: formattedName, Subject: formattedName,
PackageImportPath: getPackageImportPath(), PackageImportPath: getPackageImportPath(),

View File

@ -1,6 +1,7 @@
package generators package generators
var specText = `package {{.Package}} var specText = `{{.BuildTags}}
package {{.Package}}
import ( import (
{{.GinkgoImport}} {{.GinkgoImport}}
@ -14,7 +15,8 @@ var _ = {{.GinkgoPackage}}Describe("{{.Subject}}", func() {
}) })
` `
var agoutiSpecText = `package {{.Package}} var agoutiSpecText = `{{.BuildTags}}
package {{.Package}}
import ( import (
{{.GinkgoImport}} {{.GinkgoImport}}

View File

@ -1,6 +1,7 @@
package generators package generators
import ( import (
"fmt"
"go/build" "go/build"
"os" "os"
"path/filepath" "path/filepath"
@ -14,6 +15,7 @@ type GeneratorsConfig struct {
Agouti, NoDot, Internal bool Agouti, NoDot, Internal bool
CustomTemplate string CustomTemplate string
CustomTemplateData string CustomTemplateData string
Tags string
} }
func getPackageAndFormattedName() (string, string, string) { func getPackageAndFormattedName() (string, string, string) {
@ -62,3 +64,13 @@ func determinePackageName(name string, internal bool) string {
return name + "_test" return name + "_test"
} }
// getBuildTags returns the resultant string to be added.
// If the input string is not empty, then returns a `//go:build {}` string,
// otherwise returns an empty string.
func getBuildTags(tags string) string {
if tags != "" {
return fmt.Sprintf("//go:build %s\n", tags)
}
return ""
}

View File

@ -1,3 +1,3 @@
package types package types
const VERSION = "2.9.6" const VERSION = "2.11.0"

View File

@ -11,7 +11,7 @@ github.com/google/pprof/profile
# github.com/hashicorp/go-version v1.3.0 # github.com/hashicorp/go-version v1.3.0
## explicit ## explicit
github.com/hashicorp/go-version github.com/hashicorp/go-version
# github.com/onsi/ginkgo/v2 v2.9.6 # github.com/onsi/ginkgo/v2 v2.11.0
## explicit; go 1.18 ## explicit; go 1.18
github.com/onsi/ginkgo/v2/config github.com/onsi/ginkgo/v2/config
github.com/onsi/ginkgo/v2/formatter github.com/onsi/ginkgo/v2/formatter