mirror of
https://github.com/containers/podman.git
synced 2025-06-28 06:18:57 +08:00
Add a function for check if command exist
Use this function to check if command exist before execute it in our test. Signed-off-by: Yiqiao Pu <ypu@redhat.com>
This commit is contained in:
@ -612,3 +612,13 @@ func WaitContainerReady(p *PodmanTest, id string, expStr string, timeout int, st
|
|||||||
s.WaitWithDefaultTimeout()
|
s.WaitWithDefaultTimeout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//IsCommandAvaible check if command exist
|
||||||
|
func IsCommandAvailable(command string) bool {
|
||||||
|
check := exec.Command("bash", "-c", strings.Join([]string{"command -v", command}, " "))
|
||||||
|
err := check.Run()
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
@ -78,15 +78,16 @@ var _ = Describe("Podman push", func() {
|
|||||||
cwd, _ := os.Getwd()
|
cwd, _ := os.Getwd()
|
||||||
certPath := filepath.Join(cwd, "../", "certs")
|
certPath := filepath.Join(cwd, "../", "certs")
|
||||||
|
|
||||||
setup := podmanTest.SystemExec("getenforce", []string{})
|
if IsCommandAvailable("getenforce") {
|
||||||
setup.WaitWithDefaultTimeout()
|
ge := podmanTest.SystemExec("getenforce", []string{})
|
||||||
if setup.OutputToString() == "Enforcing" {
|
ge.WaitWithDefaultTimeout()
|
||||||
|
if ge.OutputToString() == "Enforcing" {
|
||||||
setup = podmanTest.SystemExec("setenforce", []string{"0"})
|
se := podmanTest.SystemExec("setenforce", []string{"0"})
|
||||||
setup.WaitWithDefaultTimeout()
|
se.WaitWithDefaultTimeout()
|
||||||
|
|
||||||
defer podmanTest.SystemExec("setenforce", []string{"1"})
|
defer podmanTest.SystemExec("setenforce", []string{"1"})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
session := podmanTest.Podman([]string{"run", "--entrypoint", "htpasswd", "registry:2", "-Bbn", "podmantest", "test"})
|
session := podmanTest.Podman([]string{"run", "--entrypoint", "htpasswd", "registry:2", "-Bbn", "podmantest", "test"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
@ -123,7 +124,7 @@ var _ = Describe("Podman push", func() {
|
|||||||
push.WaitWithDefaultTimeout()
|
push.WaitWithDefaultTimeout()
|
||||||
Expect(push.ExitCode()).To(Equal(0))
|
Expect(push.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
setup = podmanTest.SystemExec("cp", []string{filepath.Join(certPath, "domain.crt"), "/etc/containers/certs.d/localhost:5000/ca.crt"})
|
setup := podmanTest.SystemExec("cp", []string{filepath.Join(certPath, "domain.crt"), "/etc/containers/certs.d/localhost:5000/ca.crt"})
|
||||||
setup.WaitWithDefaultTimeout()
|
setup.WaitWithDefaultTimeout()
|
||||||
defer os.RemoveAll("/etc/containers/certs.d/localhost:5000")
|
defer os.RemoveAll("/etc/containers/certs.d/localhost:5000")
|
||||||
|
|
||||||
@ -186,17 +187,14 @@ var _ = Describe("Podman push", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("podman push to local ostree", func() {
|
It("podman push to local ostree", func() {
|
||||||
setup := podmanTest.SystemExec("which", []string{"ostree"})
|
if !IsCommandAvailable("ostree") {
|
||||||
setup.WaitWithDefaultTimeout()
|
|
||||||
|
|
||||||
if setup.ExitCode() != 0 {
|
|
||||||
Skip("ostree is not installed")
|
Skip("ostree is not installed")
|
||||||
}
|
}
|
||||||
|
|
||||||
ostreePath := filepath.Join(podmanTest.TempDir, "ostree/repo")
|
ostreePath := filepath.Join(podmanTest.TempDir, "ostree/repo")
|
||||||
os.MkdirAll(ostreePath, os.ModePerm)
|
os.MkdirAll(ostreePath, os.ModePerm)
|
||||||
|
|
||||||
setup = podmanTest.SystemExec("ostree", []string{strings.Join([]string{"--repo=", ostreePath}, ""), "init"})
|
setup := podmanTest.SystemExec("ostree", []string{strings.Join([]string{"--repo=", ostreePath}, ""), "init"})
|
||||||
setup.WaitWithDefaultTimeout()
|
setup.WaitWithDefaultTimeout()
|
||||||
|
|
||||||
session := podmanTest.Podman([]string{"push", ALPINE, strings.Join([]string{"ostree:alp@", ostreePath}, "")})
|
session := podmanTest.Podman([]string{"push", ALPINE, strings.Join([]string{"ostree:alp@", ostreePath}, "")})
|
||||||
|
Reference in New Issue
Block a user