-
-
Notifications
You must be signed in to change notification settings - Fork 450
/
source_fs_test.go
38 lines (32 loc) · 837 Bytes
/
source_fs_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
package main
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"testing"
)
func TestFileSystemImageSource(t *testing.T) {
var body []byte
var err error
const fixtureFile = "testdata/large image.jpg"
source := NewFileSystemImageSource(&SourceConfig{MountPath: "testdata"})
fakeHandler := func(w http.ResponseWriter, r *http.Request) {
if !source.Matches(r) {
t.Fatal("Cannot match the request")
}
body, err = source.GetImage(r)
if err != nil {
t.Fatalf("Error while reading the body: %s", err)
}
_, _ = w.Write(body)
}
file, _ := os.Open(fixtureFile)
r, _ := http.NewRequest(http.MethodGet, "http://foo/bar?file=large%20image.jpg", file)
w := httptest.NewRecorder()
fakeHandler(w, r)
buf, _ := ioutil.ReadFile(fixtureFile)
if len(body) != len(buf) {
t.Error("Invalid response body")
}
}