github.com/hoffie/larasync@v0.0.0-20151025221940-0384d2bddcef/api/server/blobPut_test.go (about) 1 package server 2 3 import ( 4 "net/http" 5 6 . "gopkg.in/check.v1" 7 ) 8 9 type BlobPutTests struct { 10 BlobTests 11 } 12 13 var _ = Suite(&BlobPutTests{BlobTests{}}) 14 15 func (t *BlobPutTests) SetUpTest(c *C) { 16 t.BlobTests.SetUpTest(c) 17 t.httpMethod = "PUT" 18 t.req = t.requestWithBytes(c, t.blobData) 19 } 20 21 func (t *BlobPutTests) TestRepoAccessUnauthorized(c *C) { 22 t.createRepository(c) 23 resp := t.getResponse(t.req) 24 c.Assert(resp.Code, Equals, http.StatusUnauthorized) 25 } 26 27 // Should return ok if the blob does not exist yet. 28 func (t *BlobPutTests) TestBlobCreateStatus(c *C) { 29 t.createRepository(c) 30 t.signRequest() 31 resp := t.getResponse(t.req) 32 c.Assert(resp.Code, Equals, http.StatusOK) 33 } 34 35 // Should create a blob with the given content if the blob does not 36 // exist yet. 37 func (t *BlobPutTests) TestBlobCreateData(c *C) { 38 t.createRepository(c) 39 t.signRequest() 40 t.getResponse(t.req) 41 t.expectStoredBlobData(c) 42 } 43 44 func (t *BlobPutTests) TestBlobOverwrite(c *C) { 45 t.createRepository(c) 46 t.createBlobWithData(c, []byte("Other test data")) 47 t.signRequest() 48 resp := t.getResponse(t.req) 49 c.Assert(resp.Code, Equals, http.StatusOK) 50 t.expectStoredBlobData(c) 51 } 52 53 func (t *BlobPutTests) TestBlobPutLocationHeader(c *C) { 54 t.createRepository(c) 55 t.createBlob(c) 56 t.signRequest() 57 resp := t.getResponse(t.req) 58 location := resp.Header().Get("Location") 59 c.Assert(location, Equals, t.req.URL.String()) 60 }