@@ -10,17 +10,21 @@ import (
10
10
"context"
11
11
"errors"
12
12
"testing"
13
+ "time"
13
14
14
15
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
15
16
)
16
17
17
18
var (
18
19
mockCLITokenProviderSuccess = func (ctx context.Context , resource string , tenantID string ) ([]byte , error ) {
19
- return []byte (" {\" accessToken\" :\" mocktoken\" , " +
20
- "\" expiresOn\" : \" 2007-01-01 01:01:01.079627\" ," +
21
- "\" subscription\" : \" mocksub\" ," +
22
- "\" tenant\" : \" mocktenant\" ," +
23
- "\" tokenType\" : \" mocktype\" }" ), nil
20
+ return []byte (`{
21
+ "accessToken": "mocktoken",
22
+ "expiresOn": "2001-02-03 04:05:06.000007",
23
+ "subscription": "mocksub",
24
+ "tenant": "mocktenant",
25
+ "tokenType": "Bearer"
26
+ }
27
+ ` ), nil
24
28
}
25
29
mockCLITokenProviderFailure = func (ctx context.Context , resource string , tenantID string ) ([]byte , error ) {
26
30
return nil , errors .New ("provider failure message" )
@@ -32,17 +36,18 @@ func TestAzureCLICredential_GetTokenSuccess(t *testing.T) {
32
36
options .tokenProvider = mockCLITokenProviderSuccess
33
37
cred , err := NewAzureCLICredential (& options )
34
38
if err != nil {
35
- t .Fatalf ( "Unable to create credential. Received: %v" , err )
39
+ t .Fatal ( err )
36
40
}
37
41
at , err := cred .GetToken (context .Background (), policy.TokenRequestOptions {Scopes : []string {liveTestScope }})
38
42
if err != nil {
39
- t .Fatalf ("Expected an empty error but received: %v" , err )
40
- }
41
- if len (at .Token ) == 0 {
42
- t .Fatalf (("Did not receive a token" ))
43
+ t .Fatal (err )
43
44
}
44
45
if at .Token != "mocktoken" {
45
- t .Fatalf (("Did not receive the correct access token" ))
46
+ t .Fatalf ("unexpected access token %q" , at .Token )
47
+ }
48
+ expected := time .Date (2001 , 2 , 3 , 4 , 5 , 6 , 7000 , time .Local ).UTC ()
49
+ if actual := at .ExpiresOn ; ! actual .Equal (expected ) || actual .Location () != time .UTC {
50
+ t .Fatalf ("expected %q, got %q" , expected , actual )
46
51
}
47
52
}
48
53
0 commit comments