Skip to content

Commit

Permalink
- Add more tests, and error checks
Browse files Browse the repository at this point in the history
- typo in error code naming
  • Loading branch information
primalmotion committed Mar 16, 2016
1 parent d0d58bc commit c2270ad
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 63 deletions.
2 changes: 1 addition & 1 deletion bambou/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const (

// ErrorCodeSessionCannotForgetAuthToken is the code that means no password
// or token has been given to the session.
ErrorCodeSessionCannotForgetAuthToken = 11002
ErrorCodeSessionCannotForgeAuthToken = 11002

// ErrorCodeSessionCannotProcessRequest is the code that means that it was
// impossible to process a request.
Expand Down
19 changes: 14 additions & 5 deletions bambou/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@ func (s *Session) makeAuthorizationHeaders() (string, *Error) {
return "", NewError(ErrorCodeSessionUsernameNotSet, "Error while creating headers: User must be set")
}

if s.root == nil {
return "", NewError(ErrorCodeSessionCannotForgeAuthToken, "Error while creating headers: no root user set")
}

key := s.root.APIKey()
if s.Password == "" && key == "" {
return "", NewError(ErrorCodeSessionCannotForgetAuthToken, "Error while creating headers: Password or APIKey must be set")
return "", NewError(ErrorCodeSessionCannotForgeAuthToken, "Error while creating headers: Password or APIKey must be set")
}

if key == "" {
Expand All @@ -117,9 +121,9 @@ func (s *Session) makeAuthorizationHeaders() (string, *Error) {

func (s *Session) prepareHeaders(request *http.Request, info *FetchingInfo) *Error {

authString, err := s.makeAuthorizationHeaders()
if err != nil {
return err
authString, berr := s.makeAuthorizationHeaders()
if berr != nil {
return berr
}

request.Header.Set("Authorization", authString)
Expand Down Expand Up @@ -421,7 +425,12 @@ func (s *Session) AssignChildren(parent Identifiable, children []Identifiable, i

var ids []string
for _, c := range children {
ids = append(ids, c.Identifier())

if i := c.Identifier(); i != "" {
ids = append(ids, c.Identifier())
} else {
return NewError(ErrorCodeSessionIDNotSet, "One of the object to assign has no ID")
}
}

buffer := &bytes.Buffer{}
Expand Down
Loading

0 comments on commit c2270ad

Please sign in to comment.