-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestutils.go
46 lines (39 loc) · 1.03 KB
/
testutils.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
46
package drive
import (
"context"
"time"
"github.com/bakurits/fshare-common/auth"
"github.com/sethvargo/go-envconfig"
"golang.org/x/oauth2"
)
type config struct {
ClientID string `env:"TEST_CLIENT_ID"`
ClientSecret string `env:"TEST_CLIENT_SECRET"`
ProjectID string `env:"TEST_PROJECT_ID"`
AccessToken string `env:"TEST_ACCESS_TOKEN"`
TokenType string `env:"TEST_TOKEN_TYPE"`
RefreshToken string `env:"TEST_REFRESH_TOKEN"`
Expiry string `env:"TEST_EXPIRY"`
}
func getTestClient() (*auth.Client, error) {
var conf config
if err := envconfig.Process(context.Background(), &conf); err != nil {
return nil, err
}
t, err := time.Parse(time.RFC3339, conf.Expiry)
if err != nil {
return nil, err
}
authClient, err := auth.
GetConfig(conf.ClientID, conf.ClientSecret, "http://localhost").
ClientFromToken(&oauth2.Token{
AccessToken: conf.AccessToken,
TokenType: conf.TokenType,
RefreshToken: conf.RefreshToken,
Expiry: t,
})
if err != nil {
return nil, err
}
return authClient, nil
}