10
type tokenSource struct{ token *Token }
12
func (t *tokenSource) Token() (*Token, error) {
16
func TestTransportTokenSource(t *testing.T) {
25
server := newMockServer(func(w http.ResponseWriter, r *http.Request) {
26
if r.Header.Get("Authorization") != "Bearer abc" {
27
t.Errorf("Transport doesn't set the Authorization header from the fetched token")
31
client := http.Client{Transport: tr}
32
client.Get(server.URL)
35
func TestTokenValidNoAccessToken(t *testing.T) {
38
t.Errorf("Token should not be valid with no access token")
42
func TestExpiredWithExpiry(t *testing.T) {
44
Expiry: time.Now().Add(-5 * time.Hour),
47
t.Errorf("Token should not be valid if it expired in the past")
51
func newMockServer(handler func(w http.ResponseWriter, r *http.Request)) *httptest.Server {
52
return httptest.NewServer(http.HandlerFunc(handler))