-
Notifications
You must be signed in to change notification settings - Fork 55
/
application_export_test.go
146 lines (123 loc) · 4.53 KB
/
application_export_test.go
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright © 2021 - 2023 SUSE LLC
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package v1_test
import (
"fmt"
"io"
"net/http"
"strings"
"github.com/epinio/epinio/acceptance/helpers/catalog"
v1 "github.com/epinio/epinio/internal/api/v1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("AppPart Endpoint", LApplication, func() {
var (
namespace string
app string
domain string
)
containerImageURL := "splatform/sample-app"
// The testsuite checks using only part `values` and part `manifest`, as the smallest
// possible parts, and also (YAML-formatted) text. The data returned for parts `chart` and
// `image` will be much much larger, and binary.
BeforeEach(func() {
domain = catalog.NewTmpName("exportdomain-") + ".org"
namespace = catalog.NewNamespaceName()
env.SetupAndTargetNamespace(namespace)
app = catalog.NewAppName()
env.MakeRoutedContainerImageApp(app, 1, containerImageURL, domain)
})
AfterEach(func() {
env.DeleteApp(app)
env.DeleteNamespace(namespace)
})
It("retrieves the named application part, values", func() {
response, err := env.Curl("GET", fmt.Sprintf("%s%s/namespaces/%s/applications/%s/part/values",
serverURL, v1.Root, namespace, app), strings.NewReader(""))
Expect(err).ToNot(HaveOccurred())
Expect(response).ToNot(BeNil())
defer response.Body.Close()
bodyBytes, err := io.ReadAll(response.Body)
Expect(err).ToNot(HaveOccurred())
Expect(response.StatusCode).To(Equal(http.StatusOK), string(bodyBytes))
Expect(string(bodyBytes)).To(Equal(fmt.Sprintf(`epinio:
appName: %s
configpaths: []
configurations: []
env: []
imageURL: splatform/sample-app
ingress: null
replicaCount: 1
routes:
- domain: %s
id: %s
path: /
stageID: ""
start: null
tlsIssuer: epinio-ca
username: admin
`, app, domain, domain)))
})
It("retrieves the named application part, manifest", func() {
response, err := env.Curl("GET", fmt.Sprintf("%s%s/namespaces/%s/applications/%s/part/manifest",
serverURL, v1.Root, namespace, app), strings.NewReader(""))
Expect(err).ToNot(HaveOccurred())
Expect(response).ToNot(BeNil())
defer response.Body.Close()
bodyBytes, err := io.ReadAll(response.Body)
Expect(err).ToNot(HaveOccurred())
Expect(response.StatusCode).To(Equal(http.StatusOK), string(bodyBytes))
expecting := fmt.Sprintf(`name: %s
configuration:
instances: 1
routes:
- %s
appchart: standard
origin:
container: splatform/sample-app
namespace: %s
`, app, domain, namespace)
By(string(bodyBytes))
By(expecting)
Expect(string(bodyBytes)).To(Equal(expecting), string(bodyBytes))
})
It("returns a 404 when the namespace does not exist", func() {
response, err := env.Curl("GET", fmt.Sprintf("%s%s/namespaces/idontexist/applications/%s/part/values",
serverURL, v1.Root, app), strings.NewReader(""))
Expect(err).ToNot(HaveOccurred())
Expect(response).ToNot(BeNil())
defer response.Body.Close()
bodyBytes, err := io.ReadAll(response.Body)
Expect(err).ToNot(HaveOccurred())
Expect(response.StatusCode).To(Equal(http.StatusNotFound), string(bodyBytes))
})
It("returns a 404 when the app does not exist", func() {
response, err := env.Curl("GET", fmt.Sprintf("%s%s/namespaces/%s/applications/bogus/part/values",
serverURL, v1.Root, namespace), strings.NewReader(""))
Expect(err).ToNot(HaveOccurred())
Expect(response).ToNot(BeNil())
defer response.Body.Close()
bodyBytes, err := io.ReadAll(response.Body)
Expect(err).ToNot(HaveOccurred())
Expect(response.StatusCode).To(Equal(http.StatusNotFound), string(bodyBytes))
})
It("returns a 400 when the part does not exist", func() {
response, err := env.Curl("GET", fmt.Sprintf("%s%s/namespaces/%s/applications/%s/part/bogus",
serverURL, v1.Root, namespace, app), strings.NewReader(""))
Expect(err).ToNot(HaveOccurred())
Expect(response).ToNot(BeNil())
defer response.Body.Close()
bodyBytes, err := io.ReadAll(response.Body)
Expect(err).ToNot(HaveOccurred())
Expect(response.StatusCode).To(Equal(http.StatusBadRequest), string(bodyBytes))
})
})