Inline PodmanBase into callers

Eliminate this helper / indirection, and pass around
PodmanExecOptions explicitly.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
Miloslav Trmač
2025-01-22 22:45:33 +01:00
parent f17590b2bd
commit d509bb0823
4 changed files with 31 additions and 19 deletions

View File

@ -441,7 +441,10 @@ func (p *PodmanTestIntegration) pullImage(image string, toCache bool) {
}()
}
for try := 0; try < 3; try++ {
podmanSession := p.PodmanBase([]string{"pull", image}, toCache, true)
podmanSession := p.PodmanExecBaseWithOptions([]string{"pull", image}, PodmanExecOptions{
NoEvents: toCache,
NoCache: true,
})
pull := PodmanSessionIntegration{podmanSession}
pull.Wait(440)
if pull.ExitCode() == 0 {
@ -1124,7 +1127,9 @@ func rmAll(podmanBin string, path string) {
// PodmanNoCache calls the podman command with no configured imagecache
func (p *PodmanTestIntegration) PodmanNoCache(args []string) *PodmanSessionIntegration {
podmanSession := p.PodmanBase(args, false, true)
podmanSession := p.PodmanExecBaseWithOptions(args, PodmanExecOptions{
NoCache: true,
})
return &PodmanSessionIntegration{podmanSession}
}
@ -1135,7 +1140,10 @@ func PodmanTestSetup(tempDir string) *PodmanTestIntegration {
// PodmanNoEvents calls the Podman command without an imagecache and without an
// events backend. It is used mostly for caching and uncaching images.
func (p *PodmanTestIntegration) PodmanNoEvents(args []string) *PodmanSessionIntegration {
podmanSession := p.PodmanBase(args, true, true)
podmanSession := p.PodmanExecBaseWithOptions(args, PodmanExecOptions{
NoEvents: true,
NoCache: true,
})
return &PodmanSessionIntegration{podmanSession}
}

View File

@ -25,7 +25,7 @@ func IsRemote() bool {
// Podman is the exec call to podman on the filesystem
func (p *PodmanTestIntegration) Podman(args []string) *PodmanSessionIntegration {
args = p.makeOptions(args, PodmanExecOptions{})
podmanSession := p.PodmanBase(args, false, false)
podmanSession := p.PodmanExecBaseWithOptions(args, PodmanExecOptions{})
return &PodmanSessionIntegration{podmanSession}
}

View File

@ -17,7 +17,7 @@ func IsRemote() bool {
// Podman is the exec call to podman on the filesystem
func (p *PodmanTestIntegration) Podman(args []string) *PodmanSessionIntegration {
podmanSession := p.PodmanBase(args, false, false)
podmanSession := p.PodmanExecBaseWithOptions(args, PodmanExecOptions{})
return &PodmanSessionIntegration{podmanSession}
}

View File

@ -157,14 +157,6 @@ func (p *PodmanTest) PodmanExecBaseWithOptions(args []string, options PodmanExec
return &PodmanSession{session}
}
// PodmanBase exec podman with default env.
func (p *PodmanTest) PodmanBase(args []string, noEvents, noCache bool) *PodmanSession {
return p.PodmanExecBaseWithOptions(args, PodmanExecOptions{
NoEvents: noEvents,
NoCache: noCache,
})
}
// WaitForContainer waits on a started container
func (p *PodmanTest) WaitForContainer() bool {
for i := 0; i < 10; i++ {
@ -181,7 +173,9 @@ func (p *PodmanTest) WaitForContainer() bool {
// containers are currently running.
func (p *PodmanTest) NumberOfContainersRunning() int {
var containers []string
ps := p.PodmanBase([]string{"ps", "-q"}, false, true)
ps := p.PodmanExecBaseWithOptions([]string{"ps", "-q"}, PodmanExecOptions{
NoCache: true,
})
ps.WaitWithDefaultTimeout()
Expect(ps).Should(Exit(0))
for _, i := range ps.OutputToStringArray() {
@ -196,7 +190,9 @@ func (p *PodmanTest) NumberOfContainersRunning() int {
// containers are currently defined.
func (p *PodmanTest) NumberOfContainers() int {
var containers []string
ps := p.PodmanBase([]string{"ps", "-aq"}, false, true)
ps := p.PodmanExecBaseWithOptions([]string{"ps", "-aq"}, PodmanExecOptions{
NoCache: true,
})
ps.WaitWithDefaultTimeout()
Expect(ps.ExitCode()).To(Equal(0))
for _, i := range ps.OutputToStringArray() {
@ -211,7 +207,9 @@ func (p *PodmanTest) NumberOfContainers() int {
// pods are currently defined.
func (p *PodmanTest) NumberOfPods() int {
var pods []string
ps := p.PodmanBase([]string{"pod", "ps", "-q"}, false, true)
ps := p.PodmanExecBaseWithOptions([]string{"pod", "ps", "-q"}, PodmanExecOptions{
NoCache: true,
})
ps.WaitWithDefaultTimeout()
Expect(ps.ExitCode()).To(Equal(0))
for _, i := range ps.OutputToStringArray() {
@ -227,7 +225,9 @@ func (p *PodmanTest) NumberOfPods() int {
func (p *PodmanTest) GetContainerStatus() string {
var podmanArgs = []string{"ps"}
podmanArgs = append(podmanArgs, "--all", "--format={{.Status}}")
session := p.PodmanBase(podmanArgs, false, true)
session := p.PodmanExecBaseWithOptions(podmanArgs, PodmanExecOptions{
NoCache: true,
})
session.WaitWithDefaultTimeout()
return session.OutputToString()
}
@ -235,7 +235,9 @@ func (p *PodmanTest) GetContainerStatus() string {
// WaitContainerReady waits process or service inside container start, and ready to be used.
func (p *PodmanTest) WaitContainerReady(id string, expStr string, timeout int, step int) bool {
startTime := time.Now()
s := p.PodmanBase([]string{"logs", id}, false, true)
s := p.PodmanExecBaseWithOptions([]string{"logs", id}, PodmanExecOptions{
NoCache: true,
})
s.WaitWithDefaultTimeout()
for {
@ -248,7 +250,9 @@ func (p *PodmanTest) WaitContainerReady(id string, expStr string, timeout int, s
return false
}
time.Sleep(time.Duration(step) * time.Second)
s = p.PodmanBase([]string{"logs", id}, false, true)
s = p.PodmanExecBaseWithOptions([]string{"logs", id}, PodmanExecOptions{
NoCache: true,
})
s.WaitWithDefaultTimeout()
}
}