1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
package github
import (
"fmt"
"net/http"
"regexp"
"testing"
"github.com/bmizerany/assert"
)
func TestClient_FormatError(t *testing.T) {
e := &errorInfo{
Response: &http.Response{
StatusCode: 401,
Status: "401 Not Found",
},
}
err := FormatError("action", e)
assert.Equal(t, "Error action: Not Found (HTTP 401)", fmt.Sprintf("%s", err))
e = &errorInfo{
Response: &http.Response{
StatusCode: 422,
Status: "422 Unprocessable Entity",
},
Message: "error message",
}
err = FormatError("action", e)
assert.Equal(t, "Error action: Unprocessable Entity (HTTP 422)\nerror message", fmt.Sprintf("%s", err))
}
func TestAuthTokenNote(t *testing.T) {
note, err := authTokenNote(1)
assert.Equal(t, nil, err)
reg := regexp.MustCompile("hub for (.+)@(.+)")
assert.T(t, reg.MatchString(note))
note, err = authTokenNote(2)
assert.Equal(t, nil, err)
reg = regexp.MustCompile("hub for (.+)@(.+) 2")
assert.T(t, reg.MatchString(note))
}
|