-
Notifications
You must be signed in to change notification settings - Fork 3
/
token_test.go
47 lines (45 loc) · 1.22 KB
/
token_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
46
47
package vertexai
import "testing"
func Test_getToken(t *testing.T) {
tests := []struct {
name string
key string
want string
wantErr bool
}{
{
name: "unable to retrieve credentials",
key: ``,
wantErr: true,
},
{
name: "unable to retreive token",
key: `{
"type": "service_account",
"project_id": "project_id",
"private_key_id": "1234567",
"private_key": "-----BEGIN PRIVATE KEY-----\n456789\n-----END PRIVATE KEY-----\n",
"client_email": "[email protected]",
"client_id": "12345",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/dev%40project.iam.gserviceaccount.com"
}`,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tokenizer := &defaultTokenizer{}
got, err := tokenizer.getToken(tt.key)
if (err != nil) != tt.wantErr {
t.Errorf("getToken() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("getToken() = %v, want %v", got, tt.want)
}
})
}
}