forked from kubeflow/hub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_test.go
More file actions
79 lines (62 loc) · 2.09 KB
/
app_test.go
File metadata and controls
79 lines (62 loc) · 2.09 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
package api
import (
"io"
"net/http"
httptest "net/http/httptest"
"github.com/kubeflow/model-registry/ui/bff/internal/config"
"github.com/kubeflow/model-registry/ui/bff/internal/repositories"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Static File serving Test", func() {
var (
server *httptest.Server
client *http.Client
)
Context("serving static files at /", Ordered, func() {
BeforeAll(func() {
envConfig := config.EnvConfig{
StaticAssetsDir: resolveStaticAssetsDirOnTests(),
}
app := &App{
kubernetesClientFactory: kubernetesMockedStaticClientFactory,
repositories: repositories.NewRepositories(mockMRClient, mockModelCatalogClient),
logger: logger,
config: envConfig,
}
server = httptest.NewServer(app.Routes())
client = server.Client()
})
AfterAll(func() {
server.Close()
})
It("should serve index.html from the root path", func() {
resp, err := client.Get(server.URL + "/")
Expect(err).NotTo(HaveOccurred())
defer resp.Body.Close()
Expect(resp.StatusCode).To(Equal(http.StatusOK))
body, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
Expect(string(body)).To(ContainSubstring("BFF Stub Page"))
})
It("should serve subfolders from the root path", func() {
resp, err := client.Get(server.URL + "/sub/test.html")
Expect(err).NotTo(HaveOccurred())
defer resp.Body.Close()
Expect(resp.StatusCode).To(Equal(http.StatusOK))
body, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
Expect(string(body)).To(ContainSubstring("BFF Stub Subfolder Page"))
})
It("should return index.html for a non-existent static file", func() {
resp, err := client.Get(server.URL + "/non-existent.html")
Expect(err).NotTo(HaveOccurred())
defer resp.Body.Close()
Expect(resp.StatusCode).To(Equal(http.StatusOK))
body, err := io.ReadAll(resp.Body)
Expect(err).NotTo(HaveOccurred())
//BFF Stub page is the context of index.html
Expect(string(body)).To(ContainSubstring("BFF Stub Page"))
})
})
})