forked from loft-sh/devpod
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathintegration.go
More file actions
116 lines (99 loc) · 3.26 KB
/
integration.go
File metadata and controls
116 lines (99 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package integration
import (
"context"
"os"
"os/exec"
"path/filepath"
"github.com/onsi/ginkgo/v2"
"github.com/skevetter/devpod/e2e/framework"
)
var _ = ginkgo.Describe(
"devpod provider ssh test suite",
ginkgo.Label("integration"),
ginkgo.Ordered,
func() {
var initialDir string
ginkgo.BeforeEach(func() {
var err error
initialDir, err = os.Getwd()
framework.ExpectNoError(err)
})
ginkgo.It("should generate ssh keypairs", func(ctx context.Context) {
sshDir := os.Getenv("HOME") + "/.ssh"
if _, err := os.Stat(sshDir); os.IsNotExist(err) {
err = os.MkdirAll(sshDir, 0o700)
framework.ExpectNoError(err)
}
homeDir := os.Getenv("HOME")
sshKeyPath := filepath.Join(homeDir, ".ssh", "id_rsa")
sshPubKeyPath := filepath.Join(homeDir, ".ssh", "id_rsa.pub")
_, err := os.Stat(sshKeyPath)
if err != nil {
ginkgo.GinkgoWriter.Println("generating ssh keys")
// #nosec G204 -- ssh-keygen with fixed arguments for test setup
cmd := exec.CommandContext(
ctx,
"ssh-keygen",
"-q",
"-t",
"rsa",
"-N",
"",
"-f",
sshKeyPath,
)
err = cmd.Run()
framework.ExpectNoError(err)
// #nosec G204 -- ssh-keygen with fixed arguments for test setup
cmd = exec.CommandContext(ctx, "ssh-keygen", "-y", "-f", sshKeyPath)
output, err := cmd.Output()
framework.ExpectNoError(err)
err = os.WriteFile(sshPubKeyPath, output, 0o600)
framework.ExpectNoError(err)
}
// #nosec G204 -- ssh-keygen with fixed arguments for test setup
cmd := exec.CommandContext(ctx, "ssh-keygen", "-y", "-f", sshKeyPath)
publicKey, err := cmd.Output()
framework.ExpectNoError(err)
authorizedKeysPath := filepath.Join(homeDir, ".ssh", "authorized_keys")
_, err = os.Stat(authorizedKeysPath)
if err != nil {
err = os.WriteFile(authorizedKeysPath, publicKey, 0o600)
framework.ExpectNoError(err)
} else {
f, err := os.OpenFile(os.Getenv("HOME")+"/.ssh/authorized_keys",
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o600)
framework.ExpectNoError(err)
defer func() { _ = f.Close() }()
_, err = f.Write(publicKey)
framework.ExpectNoError(err)
}
})
ginkgo.It("should add provider to devpod", func(ctx context.Context) {
f := framework.NewDefaultFramework(initialDir + "/bin")
// ensure we don't have the ssh provider present
err := f.DevPodProviderDelete(ctx, "ssh")
if err != nil {
ginkgo.GinkgoWriter.Println("warning: " + err.Error())
}
err = f.DevPodProviderAdd(ctx, "ssh", "-o", "HOST=localhost")
framework.ExpectNoError(err)
})
ginkgo.It("should run devpod up", func(ctx context.Context) {
f := framework.NewDefaultFramework(initialDir + "/bin")
err := f.DevPodUp(ctx, "tests/integration/testdata/")
framework.ExpectNoError(err)
})
ginkgo.It("should run commands to workspace via ssh", func(ctx context.Context) {
f := framework.NewDefaultFramework(initialDir + "/bin")
out, err := f.DevPodSSH(ctx, "testdata", "echo test")
framework.ExpectNoError(err)
framework.ExpectEqual(out, "test\n")
})
ginkgo.It("should cleanup devpod workspace", func(ctx context.Context) {
f := framework.NewDefaultFramework(initialDir + "/bin")
err := f.DevPodWorkspaceDelete(ctx, "testdata")
framework.ExpectNoError(err)
})
},
)