}
type StubPutHandler struct {
- c *C
- expectPath string
- expectAPIToken string
- expectBody string
- expectStorageClass string
- handled chan string
+ c *C
+ expectPath string
+ expectAPIToken string
+ expectBody string
+ expectStorageClass string
+ returnStorageClasses string
+ handled chan string
}
func (sph StubPutHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
body, err := ioutil.ReadAll(req.Body)
sph.c.Check(err, Equals, nil)
sph.c.Check(body, DeepEquals, []byte(sph.expectBody))
+ resp.Header().Set("X-Keep-Replicas-Stored", "1")
+ if sph.returnStorageClasses != "" {
+ resp.Header().Set("X-Keep-Storage-Classes-Confirmed", sph.returnStorageClasses)
+ }
resp.WriteHeader(200)
sph.handled <- fmt.Sprintf("http://%s", req.Host)
}
"acbd18db4cc2f85cedef654fccc4a4d8",
"abc123",
"foo",
- "hot",
+ "", "default=1",
make(chan string)}
UploadToStubHelper(c, st,
func(kc *KeepClient, url string, reader io.ReadCloser, writer io.WriteCloser, uploadStatusChan chan uploadStatus) {
- kc.StorageClasses = []string{"hot"}
- go kc.uploadToKeepServer(url, st.expectPath, reader, uploadStatusChan, int64(len("foo")), kc.getRequestID())
+ go kc.uploadToKeepServer(url, st.expectPath, nil, reader, uploadStatusChan, int64(len("foo")), kc.getRequestID())
writer.Write([]byte("foo"))
writer.Close()
<-st.handled
status := <-uploadStatusChan
- c.Check(status, DeepEquals, uploadStatus{nil, fmt.Sprintf("%s/%s", url, st.expectPath), 200, 1, ""})
+ c.Check(status, DeepEquals, uploadStatus{nil, fmt.Sprintf("%s/%s", url, st.expectPath), 200, 1, map[string]int{"default": 1}, ""})
})
}
"acbd18db4cc2f85cedef654fccc4a4d8",
"abc123",
"foo",
- "",
+ "", "default=1",
make(chan string)}
UploadToStubHelper(c, st,
func(kc *KeepClient, url string, _ io.ReadCloser, _ io.WriteCloser, uploadStatusChan chan uploadStatus) {
- go kc.uploadToKeepServer(url, st.expectPath, bytes.NewBuffer([]byte("foo")), uploadStatusChan, 3, kc.getRequestID())
+ go kc.uploadToKeepServer(url, st.expectPath, nil, bytes.NewBuffer([]byte("foo")), uploadStatusChan, 3, kc.getRequestID())
<-st.handled
status := <-uploadStatusChan
- c.Check(status, DeepEquals, uploadStatus{nil, fmt.Sprintf("%s/%s", url, st.expectPath), 200, 1, ""})
+ c.Check(status, DeepEquals, uploadStatus{nil, fmt.Sprintf("%s/%s", url, st.expectPath), 200, 1, map[string]int{"default": 1}, ""})
})
}
+func (s *StandaloneSuite) TestUploadWithStorageClasses(c *C) {
+ for _, trial := range []struct {
+ respHeader string
+ expectMap map[string]int
+ }{
+ {"", nil},
+ {"foo=1", map[string]int{"foo": 1}},
+ {" foo=1 , bar=2 ", map[string]int{"foo": 1, "bar": 2}},
+ {" =foo=1 ", nil},
+ {"foo", nil},
+ } {
+ st := StubPutHandler{
+ c,
+ "acbd18db4cc2f85cedef654fccc4a4d8",
+ "abc123",
+ "foo",
+ "", trial.respHeader,
+ make(chan string)}
+
+ UploadToStubHelper(c, st,
+ func(kc *KeepClient, url string, reader io.ReadCloser, writer io.WriteCloser, uploadStatusChan chan uploadStatus) {
+ go kc.uploadToKeepServer(url, st.expectPath, nil, reader, uploadStatusChan, int64(len("foo")), kc.getRequestID())
+
+ writer.Write([]byte("foo"))
+ writer.Close()
+
+ <-st.handled
+ status := <-uploadStatusChan
+ c.Check(status, DeepEquals, uploadStatus{nil, fmt.Sprintf("%s/%s", url, st.expectPath), 200, 1, trial.expectMap, ""})
+ })
+ }
+}
+
type FailHandler struct {
handled chan string
}
func(kc *KeepClient, url string, reader io.ReadCloser,
writer io.WriteCloser, uploadStatusChan chan uploadStatus) {
- go kc.uploadToKeepServer(url, hash, reader, uploadStatusChan, 3, kc.getRequestID())
+ go kc.uploadToKeepServer(url, hash, nil, reader, uploadStatusChan, 3, kc.getRequestID())
writer.Write([]byte("foo"))
writer.Close()
"abc123",
"foo",
"",
+ "",
make(chan string, 5)}
arv, _ := arvadosclient.MakeArvadosClient()
"abc123",
"foo",
"",
+ "",
make(chan string, 5)}
arv, _ := arvadosclient.MakeArvadosClient()
"abc123",
"foo",
"",
+ "",
make(chan string, 4)}
fh := FailHandler{
"abc123",
"foo",
"",
+ "",
make(chan string, 1)}
fh := FailHandler{
"abc123",
"foo",
"",
+ "",
make(chan string, 5)}
arv, _ := arvadosclient.MakeArvadosClient()
"abc123",
"foo",
"",
+ "",
make(chan string, 5)}
arv, _ := arvadosclient.MakeArvadosClient()
"abc123",
"foo",
"",
+ "",
make(chan string, 5)}}
arv, _ := arvadosclient.MakeArvadosClient()