Files
goext/googleapi/oAuth_test.go
T
Mikescher 02d6894ec6
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m34s
[🤖] Add Unit-Tests
2026-04-27 16:31:29 +02:00

60 lines
1.3 KiB
Go

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")
}
}