Skip to content

Commit

Permalink
Add integration test
Browse files Browse the repository at this point in the history
Signed-off-by: Parthvi Vala <pvala@redhat.com>
  • Loading branch information
valaparthvi committed Jun 19, 2023
1 parent 210c7f9 commit 0d5932d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 35 deletions.
15 changes: 15 additions & 0 deletions tests/helper/helper_podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,18 @@ func GetPodmanVersion() string {
Expect(err).ToNot(HaveOccurred())
return result.Client.Version
}

// GenerateDelayedPodman returns a podman cmd that sleeps for delaySecond before responding;
// this function is usually used in combination with PODMAN_CMD_INIT_TIMEOUT odo preference
func GenerateDelayedPodman(commonVarContext string, delaySecond int) string {
delayer := filepath.Join(commonVarContext, "podman-cmd-delayer")
fileContent := fmt.Sprintf(`#!/bin/bash
echo Delaying command execution... >&2
sleep %d
echo "$@"
`, delaySecond)
err := CreateFileWithContentAndPerm(delayer, fileContent, 0755)
Expect(err).ToNot(HaveOccurred())
return delayer
}
9 changes: 1 addition & 8 deletions tests/integration/cmd_dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,7 @@ var _ = Describe("odo dev command tests", func() {
// odo dev on cluster should not wait for the Podman client to initialize properly, if this client takes very long.
// See https://github.com/redhat-developer/odo/issues/6575.
// StartDevMode will time out if Podman client takes too long to initialize.
delayer := filepath.Join(commonVar.Context, "podman-cmd-delayer")
err = helper.CreateFileWithContentAndPerm(delayer, `#!/bin/bash
echo Delaying command execution... >&2
sleep 10
echo "$@"
`, 0755)
Expect(err).ShouldNot(HaveOccurred())
delayer := helper.GenerateDelayedPodman(commonVar.Context, 10)

var devSession helper.DevSession
devSession, err = helper.StartDevMode(helper.DevSessionOpts{
Expand Down
78 changes: 51 additions & 27 deletions tests/integration/generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package integration
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/redhat-developer/odo/tests/helper"
)

Expand Down Expand Up @@ -112,33 +111,58 @@ var _ = Describe("odo generic", func() {
})
})

When("executing odo version command", func() {
var odoVersion string
BeforeEach(func() {
odoVersion = helper.Cmd("odo", "version").ShouldPass().Out()
})
for _, podman := range []bool{true, false} {
podman := podman
FIt("should show the version of odo major components including server login URL", helper.LabelPodmanIf(podman, func() {
reOdoVersion := `^odo\s*v[0-9]+.[0-9]+.[0-9]+(?:-\w+)?\s*\(\w+\)`
rekubernetesVersion := `Kubernetes:\s*v[0-9]+.[0-9]+.[0-9]+((-\w+\.[0-9]+)?\+\w+)?`
Expect(odoVersion).Should(SatisfyAll(MatchRegexp(reOdoVersion), MatchRegexp(rekubernetesVersion)))
if podman {
podmanVersion := `^Podman \(Client\):\s*[0-9]+.[0-9]+.[0-9]+(?:-\w+)?\s*\(\w+\)`
Expect(odoVersion).Should(Satisfy(MatchRegexp(podmanVersion)))
}
serverURL := oc.GetCurrentServerURL()
Expect(odoVersion).Should(ContainSubstring("Server: " + serverURL))
}))
}

It("should show the version of odo major components", Label(helper.LabelNoCluster), func() {
reOdoVersion := `^odo\s*v[0-9]+.[0-9]+.[0-9]+(?:-\w+)?\s*\(\w+\)`
Expect(odoVersion).Should(MatchRegexp(reOdoVersion))
Context("executing odo version command", func() {
const (
reOdoVersion = `^odo\s*v[0-9]+.[0-9]+.[0-9]+(?:-\w+)?\s*\(\w+\)`
rekubernetesVersion = `Kubernetes:\s*v[0-9]+.[0-9]+.[0-9]+((-\w+\.[0-9]+)?\+\w+)?`
rePodmanVersion = `Podman \(Client\):\s*[0-9]+.[0-9]+.[0-9]+((-\w+\.[0-9]+)?\+\w+)?`
)
When("executing the complete command with server info", func() {
var odoVersion, errVersion string
BeforeEach(func() {
odoVersion, errVersion = helper.Cmd("odo", "version", "-v", "4").ShouldPass().OutAndErr()
Expect(errVersion).ToNot(BeTrue())
})
for _, podman := range []bool{true, false} {
podman := podman
It("should show the version of odo major components including server login URL", helper.LabelPodmanIf(podman, func() {
Expect(odoVersion).Should(MatchRegexp(reOdoVersion))

// odo tests setup (CommonBeforeEach) is designed in a way that if a test is labelled with 'podman', it will not have cluster configuration
// so we only test podman info on podman labelled test, and clsuter info otherwise
// TODO (pvala): Change this behavior when we write tests that should be tested on both podman and cluster simultaneously
// Ref: https://github.com/redhat-developer/odo/issues/6719
if podman {
Expect(odoVersion).Should(MatchRegexp(rePodmanVersion))
Expect(odoVersion).To(ContainSubstring(helper.GetPodmanVersion()))
} else {
Expect(odoVersion).Should(MatchRegexp(rekubernetesVersion))
if !helper.IsKubernetesCluster() {
serverURL := oc.GetCurrentServerURL()
Expect(odoVersion).Should(ContainSubstring("Server: " + serverURL))
}
}
}))
}

for _, label := range []string{helper.LabelNoCluster, helper.LabelUnauth} {
label := label
It("should show the version of odo major components", Label(label), func() {
Expect(odoVersion).Should(MatchRegexp(reOdoVersion))
})
}
})
It("should show the version of odo major components", Label(helper.LabelUnauth), func() {
reOdoVersion := `^odo\s*v[0-9]+.[0-9]+.[0-9]+(?:-\w+)?\s*\(\w+\)`
Expect(odoVersion).Should(MatchRegexp(reOdoVersion))

When("podman client is bound to delay and odo version is run", Label(helper.LabelPodman), func() {
var odoVersion string
BeforeEach(func() {
delayer := helper.GenerateDelayedPodman(commonVar.Context, 2)
odoVersion = helper.Cmd("odo", "version").WithEnv("PODMAN_CMD="+delayer, "PODMAN_CMD_INIT_TIMEOUT=1s").ShouldPass().Out()
})
It("should not print podman version if podman cmd timeout has been reached", func() {
Expect(odoVersion).Should(Satisfy(MatchRegexp(reOdoVersion)))
Expect(odoVersion).ToNot(ContainSubstring("Podman (Client):"))
})
})
})

Expand Down

0 comments on commit 0d5932d

Please sign in to comment.