evcc-io/vehicle/vw/token_test.go
andig 57495de286
Some checks failed
Build / Build (push) Failing after 2m9s
Build / Build UI (push) Failing after 1m46s
Build / Publish :latest (push) Has been skipped
Build / Publish :release (push) Has been skipped
Build / Release (push) Has been skipped
Fix token refresh (#764)
2021-03-15 15:29:14 +01:00

56 lines
878 B
Go

package vw
import (
"encoding/json"
"testing"
)
func TestUnmarshalJSON(t *testing.T) {
var tok Token
str := `{"access_token":"access","refresh_token":"refresh","token_type":"bearer","expires_in":3600}`
if err := json.Unmarshal([]byte(str), &tok); err != nil {
t.Error(err)
}
if tok.AccessToken != "access" {
t.Error("AccessToken")
}
if tok.RefreshToken != "refresh" {
t.Error("RefreshToken")
}
if tok.TokenType != "bearer" {
t.Error("TokenType")
}
if tok.Expiry.IsZero() {
t.Error("Expiry")
}
}
func TestMerge(t *testing.T) {
ts := &TokenSource{
token: &Token{
AccessToken: "access1",
RefreshToken: "refresh1",
},
}
new := Token{
AccessToken: "access2",
}
ts.mergeToken(new)
tok := ts.token
if tok.AccessToken != "access2" {
t.Error("AccessToken")
}
if tok.RefreshToken != "refresh1" {
t.Error("RefreshToken")
}
}