github.com/hoffie/larasync@v0.0.0-20151025221940-0384d2bddcef/api/server/authorizationPut_test.go (about) 1 package server 2 3 import ( 4 "bytes" 5 "io" 6 "net/http" 7 8 . "gopkg.in/check.v1" 9 ) 10 11 type AuthorizationPutTests struct { 12 AuthorizationTests 13 } 14 15 var _ = Suite(&AuthorizationPutTests{getAuthorizationTest()}) 16 17 func (t *AuthorizationPutTests) SetUpTest(c *C) { 18 t.AuthorizationTests.SetUpTest(c) 19 t.httpMethod = "PUT" 20 t.req = t.requestEmptyBody(c) 21 } 22 23 func (t *AuthorizationPutTests) TestRepositoryNotExists(c *C) { 24 resp := t.getResponse(t.req) 25 c.Assert(resp.Code, Equals, http.StatusUnauthorized) 26 } 27 28 func (t *AuthorizationPutTests) TestNotSigned(c *C) { 29 t.createRepository(c) 30 resp := t.getResponse(t.req) 31 c.Assert(resp.Code, Equals, http.StatusUnauthorized) 32 } 33 34 func (t *AuthorizationPutTests) setUpWithExist(c *C) { 35 t.createRepository(c) 36 auth := t.testAuthorization(c) 37 t.addAuthorization(c, auth) 38 } 39 40 func (t *AuthorizationPutTests) TestPut(c *C) { 41 t.setUpWithExist(c) 42 repo := t.getRepository(c) 43 reader, err := repo.GetAuthorizationReader(t.authPublicKey) 44 c.Assert(err, IsNil) 45 buff := &bytes.Buffer{} 46 _, err = io.Copy(buff, reader) 47 c.Assert(err, IsNil) 48 reader.Close() 49 50 t.req = t.requestWithReader(c, buff) 51 t.signRequest() 52 53 resp := t.getResponse(t.req) 54 c.Assert(resp.Code, Equals, http.StatusCreated) 55 }