generated from oklookat/gostarter
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
45 lines (36 loc) · 883 Bytes
/
main_test.go
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
package ytmauth
import (
"context"
"fmt"
"os"
"testing"
"github.com/joho/godotenv"
)
func TestNew(t *testing.T) {
if err := godotenv.Load(); err != nil {
t.Fatalf("load env: %s", err.Error())
}
token, err := New(context.Background(), func(url, code string) {
fmt.Printf("go to %s and type %s", url, code)
})
if err != nil {
t.Fatalf("new: %s", err.Error())
}
if len(token.AccessToken) == 0 ||
len(token.TokenType) == 0 ||
len(token.RefreshToken) == 0 || token.Expiry.Unix() == 0 {
t.Fatalf("invalid token")
}
}
func TestRefresh(t *testing.T) {
if err := godotenv.Load(); err != nil {
t.Fatalf("load env: %s", err.Error())
}
//access := os.Getenv("ACCESS_TOKEN")
refresh := os.Getenv("REFRESH_TOKEN")
refreshed, err := Refresh(context.Background(), refresh)
if err != nil {
t.Fatalf(err.Error())
}
fmt.Printf("%s", refreshed.TokenType)
}