Skip to content

Commit e8c4c4d

Browse files
authored
Merge pull request #1836 from pratikjagrut/render.e2e
e2e: add e2e test for render command
2 parents 0594977 + 018c7be commit e8c4c4d

File tree

10 files changed

+285
-1
lines changed

10 files changed

+285
-1
lines changed

e2e/e2e_suite_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
_ "github.com/loft-sh/devspace/e2e/tests/devspacehelper"
1818
_ "github.com/loft-sh/devspace/e2e/tests/hooks"
1919
_ "github.com/loft-sh/devspace/e2e/tests/init"
20+
_ "github.com/loft-sh/devspace/e2e/tests/render"
2021
_ "github.com/loft-sh/devspace/e2e/tests/replacepods"
2122
_ "github.com/loft-sh/devspace/e2e/tests/sync"
2223
_ "github.com/loft-sh/devspace/e2e/tests/terminal"

e2e/tests/deploy/testdata/kubectl/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ spec:
1414
spec:
1515
containers:
1616
- name: webserver-simple-container
17-
image: nginx
17+
image: nginx

e2e/tests/render/framework.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package render
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("[render] "+text, body)
8+
}

e2e/tests/render/render.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package render
2+
3+
import (
4+
"bytes"
5+
"os"
6+
"path/filepath"
7+
"strings"
8+
"sync"
9+
10+
"github.com/loft-sh/devspace/cmd"
11+
"github.com/loft-sh/devspace/cmd/flags"
12+
"github.com/loft-sh/devspace/e2e/framework"
13+
"github.com/loft-sh/devspace/pkg/util/factory"
14+
"github.com/onsi/ginkgo"
15+
)
16+
17+
var _ = DevSpaceDescribe("build", func() {
18+
19+
initialDir, err := os.Getwd()
20+
if err != nil {
21+
panic(err)
22+
}
23+
24+
// create a new factory
25+
var f factory.Factory
26+
27+
ginkgo.BeforeEach(func() {
28+
f = framework.NewDefaultFactory()
29+
})
30+
31+
// Test cases:
32+
33+
ginkgo.It("should render helm charts", func() {
34+
tempDir, err := framework.CopyToTempDir("tests/render/testdata/helm")
35+
framework.ExpectNoError(err)
36+
defer framework.CleanupTempDir(initialDir, tempDir)
37+
38+
stdout := &Buffer{}
39+
// create build command
40+
renderCmd := &cmd.RenderCmd{
41+
GlobalFlags: &flags.GlobalFlags{
42+
NoWarn: true,
43+
},
44+
SkipPush: true,
45+
Writer: stdout,
46+
}
47+
err = renderCmd.Run(f)
48+
framework.ExpectNoError(err)
49+
content := strings.TrimSpace(stdout.String()) + "\n"
50+
framework.ExpectLocalFileContentsImmediately(filepath.Join(tempDir, "rendered.txt"), content)
51+
})
52+
53+
ginkgo.It("should render kubectl deployments", func() {
54+
tempDir, err := framework.CopyToTempDir("tests/render/testdata/kubectl")
55+
framework.ExpectNoError(err)
56+
defer framework.CleanupTempDir(initialDir, tempDir)
57+
58+
stdout := &Buffer{}
59+
// create build command
60+
renderCmd := &cmd.RenderCmd{
61+
GlobalFlags: &flags.GlobalFlags{
62+
NoWarn: true,
63+
},
64+
SkipPush: true,
65+
Writer: stdout,
66+
}
67+
err = renderCmd.Run(f)
68+
framework.ExpectNoError(err)
69+
content := strings.TrimSpace(stdout.String()) + "\n"
70+
framework.ExpectLocalFileContentsImmediately(filepath.Join(tempDir, "rendered.txt"), content)
71+
})
72+
})
73+
74+
// Buffer is a goroutine safe bytes.Buffer
75+
type Buffer struct {
76+
buffer bytes.Buffer
77+
mutex sync.Mutex
78+
}
79+
80+
// Write appends the contents of p to the buffer, growing the buffer as needed. It returns
81+
// the number of bytes written.
82+
func (s *Buffer) Write(p []byte) (n int, err error) {
83+
s.mutex.Lock()
84+
defer s.mutex.Unlock()
85+
return s.buffer.Write(p)
86+
}
87+
88+
// String returns the contents of the unread portion of the buffer
89+
// as a string. If the Buffer is a nil pointer, it returns "<nil>".
90+
func (s *Buffer) String() string {
91+
s.mutex.Lock()
92+
defer s.mutex.Unlock()
93+
return s.buffer.String()
94+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: v1beta11
2+
vars:
3+
- name: IMAGE
4+
value: node:13.14-alpine
5+
deployments:
6+
- name: test
7+
helm:
8+
componentChart: true
9+
values:
10+
containers:
11+
- image: ${IMAGE}
12+
command: ["sleep"]
13+
args: ["999999999999"]
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
# Source: component-chart/templates/deployment.yaml
3+
apiVersion: apps/v1
4+
kind: Deployment
5+
metadata:
6+
name: "test"
7+
labels:
8+
"app.kubernetes.io/name": "devspace-app"
9+
"app.kubernetes.io/component": "test"
10+
"app.kubernetes.io/managed-by": "Helm"
11+
annotations:
12+
"helm.sh/chart": "component-chart-0.8.4"
13+
spec:
14+
replicas: 1
15+
strategy:
16+
type: Recreate
17+
selector:
18+
matchLabels:
19+
"app.kubernetes.io/name": "devspace-app"
20+
"app.kubernetes.io/component": "test"
21+
"app.kubernetes.io/managed-by": "Helm"
22+
template:
23+
metadata:
24+
labels:
25+
"app.kubernetes.io/name": "devspace-app"
26+
"app.kubernetes.io/component": "test"
27+
"app.kubernetes.io/managed-by": "Helm"
28+
annotations:
29+
"helm.sh/chart": "component-chart-0.8.4"
30+
spec:
31+
imagePullSecrets:
32+
nodeSelector:
33+
null
34+
nodeName:
35+
null
36+
affinity:
37+
null
38+
tolerations:
39+
null
40+
dnsConfig:
41+
null
42+
hostAliases:
43+
null
44+
overhead:
45+
null
46+
readinessGates:
47+
null
48+
securityContext:
49+
null
50+
topologySpreadConstraints:
51+
null
52+
terminationGracePeriodSeconds: 5
53+
ephemeralContainers:
54+
null
55+
containers:
56+
- image: "node:13.14-alpine"
57+
name: "container-0"
58+
command:
59+
- "sleep"
60+
args:
61+
- "999999999999"
62+
env:
63+
null
64+
envFrom:
65+
null
66+
securityContext:
67+
null
68+
lifecycle:
69+
null
70+
livenessProbe:
71+
null
72+
readinessProbe:
73+
null
74+
startupProbe:
75+
null
76+
volumeDevices:
77+
null
78+
volumeMounts:
79+
initContainers:
80+
volumes:
81+
volumeClaimTemplates:
82+
---
83+
# Source: component-chart/templates/deployment.yaml
84+
# Create headless service for StatefulSet
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: webserver-simple-deployment
5+
spec:
6+
replicas: 2
7+
selector:
8+
matchLabels:
9+
app: webserver-simple-app
10+
template:
11+
metadata:
12+
labels:
13+
app: webserver-simple-app
14+
spec:
15+
containers:
16+
- name: webserver-simple-container
17+
image: nginx
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: v1beta11
2+
deployments:
3+
- name: test
4+
kubectl:
5+
manifests:
6+
- deployment.yaml
7+
- service.yaml
8+
- https://raw.githubusercontent.com/ContainerSolutions/kubernetes-examples/cdf024abb19fa005ad8bccb762e238f10ba0511e/Pod/simple.yaml
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: webserver-simple-deployment
5+
namespace: default
6+
spec:
7+
replicas: 2
8+
selector:
9+
matchLabels:
10+
app: webserver-simple-app
11+
template:
12+
metadata:
13+
labels:
14+
app: webserver-simple-app
15+
spec:
16+
containers:
17+
- image: nginx
18+
name: webserver-simple-container
19+
20+
---
21+
apiVersion: v1
22+
kind: Service
23+
metadata:
24+
name: webserver-simple-service
25+
namespace: default
26+
spec:
27+
ports:
28+
- port: 80
29+
protocol: TCP
30+
targetPort: 8000
31+
selector:
32+
app: webserver-simple-app
33+
34+
---
35+
apiVersion: v1
36+
kind: Pod
37+
metadata:
38+
name: pods-simple-pod
39+
namespace: default
40+
spec:
41+
containers:
42+
- command:
43+
- sleep
44+
- "3600"
45+
image: busybox
46+
name: pods-simple-container
47+
48+
---
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: webserver-simple-service
5+
spec:
6+
selector:
7+
app: webserver-simple-app
8+
ports:
9+
- protocol: TCP
10+
port: 80
11+
targetPort: 8000

0 commit comments

Comments
 (0)