Skip to content

Commit 77f02e0

Browse files
committed
test: add e2e test for ssh
1 parent cf1cb71 commit 77f02e0

4 files changed

Lines changed: 112 additions & 0 deletions

File tree

e2e/e2e_suite_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
_ "github.com/loft-sh/devspace/e2e/tests/pullsecret"
2323
_ "github.com/loft-sh/devspace/e2e/tests/render"
2424
_ "github.com/loft-sh/devspace/e2e/tests/replacepods"
25+
_ "github.com/loft-sh/devspace/e2e/tests/ssh"
2526
_ "github.com/loft-sh/devspace/e2e/tests/sync"
2627
_ "github.com/loft-sh/devspace/e2e/tests/terminal"
2728
)

e2e/tests/ssh/framework.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package ssh
2+
3+
import "github.com/onsi/ginkgo"
4+
5+
// DevSpaceDescribe annotates the test with the label.
6+
func DevSpaceDescribe(text string, body func()) bool {
7+
return ginkgo.Describe("[ssh] "+text, body)
8+
}

e2e/tests/ssh/ssh.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package ssh
2+
3+
import (
4+
"context"
5+
"os"
6+
"os/exec"
7+
"time"
8+
9+
"github.com/loft-sh/devspace/cmd"
10+
"github.com/loft-sh/devspace/cmd/flags"
11+
"github.com/loft-sh/devspace/e2e/framework"
12+
"github.com/loft-sh/devspace/e2e/kube"
13+
"github.com/loft-sh/devspace/pkg/util/factory"
14+
"github.com/onsi/ginkgo"
15+
"k8s.io/apimachinery/pkg/util/wait"
16+
)
17+
18+
var _ = DevSpaceDescribe("ssh", func() {
19+
initialDir, err := os.Getwd()
20+
if err != nil {
21+
panic(err)
22+
}
23+
24+
// create a new factory
25+
var (
26+
f factory.Factory
27+
kubeClient *kube.KubeHelper
28+
)
29+
30+
ginkgo.BeforeEach(func() {
31+
f = framework.NewDefaultFactory()
32+
33+
kubeClient, err = kube.NewKubeHelper()
34+
framework.ExpectNoError(err)
35+
})
36+
37+
ginkgo.It("devspace dev should start an SSH service", func() {
38+
tempDir, err := framework.CopyToTempDir("tests/ssh/testdata/ssh-simple")
39+
framework.ExpectNoError(err)
40+
defer framework.CleanupTempDir(initialDir, tempDir)
41+
42+
ns, err := kubeClient.CreateNamespace("ssh")
43+
framework.ExpectNoError(err)
44+
defer framework.ExpectDeleteNamespace(kubeClient, ns)
45+
46+
// create a new dev command and start it
47+
done := make(chan error)
48+
cancelCtx, cancel := context.WithCancel(context.Background())
49+
defer cancel()
50+
51+
go func() {
52+
defer ginkgo.GinkgoRecover()
53+
54+
devCmd := &cmd.DevCmd{
55+
GlobalFlags: &flags.GlobalFlags{
56+
NoWarn: true,
57+
Namespace: ns,
58+
},
59+
Ctx: cancelCtx,
60+
}
61+
62+
done <- devCmd.Run(f)
63+
}()
64+
65+
// connect to the SSH server
66+
err = wait.PollImmediate(time.Second, time.Minute*2, func() (bool, error) {
67+
cmd := exec.Command("ssh", "test.ssh-simple.devspace", "ls")
68+
err := cmd.Run()
69+
if err != nil {
70+
return false, nil
71+
}
72+
73+
return true, nil
74+
})
75+
framework.ExpectNoError(err)
76+
77+
cancel()
78+
79+
err = <-done
80+
framework.ExpectNoError(err)
81+
})
82+
})
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: v2beta1
2+
vars:
3+
IMAGE: alpine
4+
deployments:
5+
test:
6+
helm:
7+
chart:
8+
name: component-chart
9+
repo: https://charts.devspace.sh
10+
values:
11+
containers:
12+
- image: ${IMAGE}
13+
command: ["sleep"]
14+
args: ["999999999999"]
15+
dev:
16+
test:
17+
imageSelector: ${IMAGE}
18+
ssh:
19+
enabled: true
20+
localHostname: test.ssh-simple.devspace
21+
localPort: 10022

0 commit comments

Comments
 (0)