This repository was archived by the owner on Dec 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmiddleware_static_file_test.go
More file actions
67 lines (57 loc) · 1.59 KB
/
middleware_static_file_test.go
File metadata and controls
67 lines (57 loc) · 1.59 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
package rye
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"os"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Static File Middleware", func() {
var (
request *http.Request
response *httptest.ResponseRecorder
path string
testPath string
)
BeforeEach(func() {
response = httptest.NewRecorder()
request = &http.Request{}
testPath, _ = os.Getwd()
})
Describe("handle", func() {
Context("when a valid file is referenced", func() {
It("should return a response", func() {
path = "/static-examples/dist/index.html"
url, _ := url.Parse("/thisstuff")
request.URL = url
resp := NewStaticFile(testPath+path)(response, request)
Expect(resp).To(BeNil())
Expect(response).ToNot(BeNil())
Expect(response.Code).To(Equal(200))
body, err := ioutil.ReadAll(response.Body)
Expect(err).To(BeNil())
Expect(body).To(ContainSubstring("Index.html"))
})
It("should return a Moved Permanently response", func() {
path = "/static-examples/dist/index.html"
url, _ := url.Parse("/thisstuff")
request.URL = url
resp := NewStaticFile("")(response, request)
Expect(resp).To(BeNil())
Expect(response).ToNot(BeNil())
Expect(response.Code).To(Equal(301))
})
It("should return a File Not Found response", func() {
path = "/static-examples/dist/index.html"
url, _ := url.Parse("/thisstuff")
request.URL = url
resp := NewStaticFile(path)(response, request)
Expect(resp).To(BeNil())
Expect(response).ToNot(BeNil())
Expect(response.Code).To(Equal(404))
})
})
})
})