Skip to content

Commit

Permalink
Merge pull request #2790 from lizardruss/ENG-2328
Browse files Browse the repository at this point in the history
SSH test improvements
  • Loading branch information
lizardruss committed Jan 16, 2024
2 parents 26edf30 + 544036b commit b21c769
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
44 changes: 34 additions & 10 deletions e2e/tests/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var _ = DevSpaceDescribe("ssh", func() {

// create a new dev command and start it
done := make(chan error)
cancelCtx, cancel := context.WithCancel(context.Background())
cancelCtx, cancel := context.WithCancel(ctx)
ginkgo.DeferCleanup(cancel)

go func() {
Expand All @@ -63,23 +63,31 @@ var _ = DevSpaceDescribe("ssh", func() {
done <- devCmd.RunDefault(f)
}()

// Wait for the dev session to start
gomega.Eventually(func(g gomega.Gomega) {
_, err := os.ReadFile("started")
g.Expect(err).NotTo(gomega.HaveOccurred())
}).
WithPolling(time.Second).
WithTimeout(time.Second * 60).
Should(gomega.Succeed())

// connect to the SSH server
gomega.Eventually(func(g gomega.Gomega) {
cmd := exec.Command("ssh", "test.ssh-simple.devspace", "ls")
err := cmd.Run()
g.Expect(err).NotTo(gomega.HaveOccurred())

cancel()
}).
WithPolling(time.Second).
WithTimeout(time.Second * 60).
Should(gomega.Succeed())

cancel()
err = <-done
framework.ExpectNoError(err)
})

ginkgo.It("devspace dev should NOT start an SSH service when disabled with a variable", ginkgo.FlakeAttempts(3), func(ctx context.Context) {
ginkgo.It("devspace dev should NOT start an SSH service when disabled with a variable", func(ctx context.Context) {
tempDir, err := framework.CopyToTempDir("tests/ssh/testdata/ssh-variable")
framework.ExpectNoError(err)
ginkgo.DeferCleanup(framework.CleanupTempDir, initialDir, tempDir)
Expand All @@ -90,7 +98,7 @@ var _ = DevSpaceDescribe("ssh", func() {

// create a new dev command and start it
done := make(chan error)
cancelCtx, cancel := context.WithCancel(context.Background())
cancelCtx, cancel := context.WithCancel(ctx)
ginkgo.DeferCleanup(cancel)

go func() {
Expand All @@ -110,6 +118,15 @@ var _ = DevSpaceDescribe("ssh", func() {
done <- devCmd.RunDefault(f)
}()

// Wait for the dev session to start
gomega.Eventually(func(g gomega.Gomega) {
_, err := os.ReadFile("started")
g.Expect(err).NotTo(gomega.HaveOccurred())
}).
WithPolling(time.Second).
WithTimeout(time.Second * 60).
Should(gomega.Succeed())

gomega.Eventually(func(g gomega.Gomega) {
cmd := exec.Command("ssh", "test.ssh-variable.devspace", "ls")
out, err := cmd.CombinedOutput()
Expand All @@ -121,13 +138,12 @@ var _ = DevSpaceDescribe("ssh", func() {
gomega.ContainSubstring("ssh: connect to host localhost port 10023"),
),
)

cancel()
}).
WithPolling(time.Second).
WithTimeout(time.Second * 60).
Should(gomega.Succeed())

cancel()
cmdErr := <-done
framework.ExpectNoError(cmdErr)
})
Expand All @@ -143,7 +159,7 @@ var _ = DevSpaceDescribe("ssh", func() {

// create a new dev command and start it
done := make(chan error)
cancelCtx, cancel := context.WithCancel(context.Background())
cancelCtx, cancel := context.WithCancel(ctx)
ginkgo.DeferCleanup(cancel)

go func() {
Expand All @@ -163,18 +179,26 @@ var _ = DevSpaceDescribe("ssh", func() {
done <- devCmd.RunDefault(f)
}()

// Wait for the dev session to start
gomega.Eventually(func(g gomega.Gomega) {
_, err := os.ReadFile("started")
g.Expect(err).NotTo(gomega.HaveOccurred())
}).
WithPolling(time.Second).
WithTimeout(time.Second * 60).
Should(gomega.Succeed())

// connect to the SSH server
gomega.Eventually(func(g gomega.Gomega) {
cmd := exec.Command("ssh", "test.ssh-variable.devspace", "ls")
err := cmd.Run()
g.Expect(err).NotTo(gomega.HaveOccurred())

cancel()
}).
WithPolling(time.Second).
WithTimeout(time.Second * 60).
Should(gomega.Succeed())

cancel()
cmdErr := <-done
framework.ExpectNoError(cmdErr)
})
Expand Down
4 changes: 4 additions & 0 deletions e2e/tests/ssh/testdata/ssh-simple/devspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ deployments:
- image: ${IMAGE}
command: ["sleep"]
args: ["999999999999"]
pipelines:
dev: |
run_default_pipeline dev
echo "started" > started
dev:
test:
imageSelector: ${IMAGE}
Expand Down
4 changes: 4 additions & 0 deletions e2e/tests/ssh/testdata/ssh-variable/devspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ deployments:
- image: ${IMAGE}
command: ["sleep"]
args: ["999999999999"]
pipelines:
dev: |
run_default_pipeline dev
echo "started" > started
dev:
test:
imageSelector: ${IMAGE}
Expand Down

0 comments on commit b21c769

Please sign in to comment.