Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Commit

Permalink
Increase coverage of the api package
Browse files Browse the repository at this point in the history
  • Loading branch information
scorphus committed Aug 26, 2014
1 parent 2f9c0bd commit 556cd7c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions api/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,36 @@ func (s *S) TestMaxMemoryValueDontResetMaxMemory(c *gocheck.C) {
c.Assert(maxMemoryValue(), gocheck.Equals, uint(359))
}

func (s *S) TestAccessParametersShouldReturnErrorWhenInvalidJSONInput(c *gocheck.C) {
b := bufferCloser{bytes.NewBufferString(``)}
_, _, err := accessParameters(b)
c.Assert(err, gocheck.ErrorMatches, `^Could not parse json: .+$`)
b = bufferCloser{bytes.NewBufferString(`{`)}
_, _, err = accessParameters(b)
c.Assert(err, gocheck.ErrorMatches, `^Could not parse json: .+$`)
b = bufferCloser{bytes.NewBufferString(`bang`)}
_, _, err = accessParameters(b)
c.Assert(err, gocheck.ErrorMatches, `^Could not parse json: .+$`)
b = bufferCloser{bytes.NewBufferString(` `)}
_, _, err = accessParameters(b)
c.Assert(err, gocheck.ErrorMatches, `^Could not parse json: .+$`)
}

func (s *S) TestAccessParametersShouldReturnErrorWhenNoUserListProvided(c *gocheck.C) {
b := bufferCloser{bytes.NewBufferString(`{"users": "oneuser"}`)}
_, _, err := accessParameters(b)
c.Assert(err, gocheck.ErrorMatches, `^Could not parse json: json: cannot unmarshal string into Go value of type \[\]string$`)
b = bufferCloser{bytes.NewBufferString(`{"repositories": ["barad-dur"]}`)}
_, _, err = accessParameters(b)
c.Assert(err, gocheck.ErrorMatches, `^It is need a user list$`)
}

func (s *S) TestAccessParametersShouldReturnErrorWhenNoRepositoryListProvided(c *gocheck.C) {
b := bufferCloser{bytes.NewBufferString(`{"users": ["nazgul"]}`)}
_, _, err := accessParameters(b)
c.Assert(err, gocheck.ErrorMatches, `^It is need a repository list$`)
}

func (s *S) TestNewUser(c *gocheck.C) {
b := strings.NewReader(fmt.Sprintf(`{"name": "brain", "keys": {"keyname": %q}}`, rawKey))
recorder, request := post("/user", b, c)
Expand Down

0 comments on commit 556cd7c

Please sign in to comment.