This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package googleapi
|
||||
|
||||
import (
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/tst"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestNewGoogleOAuthReturnsNonNil(t *testing.T) {
|
||||
auth := NewGoogleOAuth("cid", "csecret", "rtok")
|
||||
tst.AssertTrue(t, auth != nil)
|
||||
}
|
||||
|
||||
func TestNewGoogleOAuthFieldsSet(t *testing.T) {
|
||||
auth := NewGoogleOAuth("cid", "csecret", "rtok")
|
||||
c, ok := auth.(*oauth)
|
||||
tst.AssertTrue(t, ok)
|
||||
tst.AssertEqual(t, c.clientID, "cid")
|
||||
tst.AssertEqual(t, c.clientSecret, "csecret")
|
||||
tst.AssertEqual(t, c.refreshToken, "rtok")
|
||||
tst.AssertTrue(t, c.accessToken == nil)
|
||||
tst.AssertTrue(t, c.expiryDate == nil)
|
||||
}
|
||||
|
||||
func TestOAuthAccessTokenCachedReturnsStored(t *testing.T) {
|
||||
c := &oauth{
|
||||
clientID: "cid",
|
||||
clientSecret: "csecret",
|
||||
refreshToken: "rtok",
|
||||
}
|
||||
|
||||
tok := "cached-token-value"
|
||||
expiry := time.Now().Add(1 * time.Hour)
|
||||
c.accessToken = &tok
|
||||
c.expiryDate = &expiry
|
||||
|
||||
got, err := c.AccessToken()
|
||||
tst.AssertNoErr(t, err)
|
||||
tst.AssertEqual(t, got, "cached-token-value")
|
||||
}
|
||||
|
||||
func TestOAuthAccessTokenCachedMultipleCalls(t *testing.T) {
|
||||
c := &oauth{
|
||||
clientID: "cid",
|
||||
clientSecret: "csecret",
|
||||
refreshToken: "rtok",
|
||||
}
|
||||
|
||||
tok := "another-token"
|
||||
expiry := time.Now().Add(30 * time.Minute)
|
||||
c.accessToken = &tok
|
||||
c.expiryDate = &expiry
|
||||
|
||||
for range 5 {
|
||||
got, err := c.AccessToken()
|
||||
tst.AssertNoErr(t, err)
|
||||
tst.AssertEqual(t, got, "another-token")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user