@@ -18,25 +18,33 @@ package azclient
18
18
19
19
import (
20
20
"context"
21
+ "fmt"
22
+ "sync/atomic"
21
23
"testing"
24
+ "time"
22
25
23
26
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
24
27
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
25
28
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
26
29
"github.com/stretchr/testify/assert"
27
30
)
28
31
32
+ var (
33
+ incCounter = atomic.Int64 {}
34
+ )
35
+
29
36
type fakeTokenCredential struct {
30
37
ID string
31
38
}
32
39
33
- func NewFakeTokenCredential (id string ) * fakeTokenCredential {
40
+ func newFakeTokenCredential () * fakeTokenCredential {
41
+ id := fmt .Sprintf ("fake-token-credential-%d-%d" , incCounter .Add (1 ), time .Now ().UnixNano ())
34
42
return & fakeTokenCredential {ID : id }
35
43
}
36
44
37
45
func (f * fakeTokenCredential ) GetToken (
38
- ctx context.Context ,
39
- options policy.TokenRequestOptions ,
46
+ _ context.Context ,
47
+ _ policy.TokenRequestOptions ,
40
48
) (azcore.AccessToken , error ) {
41
49
panic ("not implemented" )
42
50
}
@@ -51,27 +59,27 @@ func ApplyAssertions(t testing.TB, authProvider *AuthProvider, assertions []Auth
51
59
}
52
60
}
53
61
54
- func AssertComputeTokenCredential (expectedID string ) AuthProviderAssertions {
62
+ func AssertComputeTokenCredential (tokenCredential * fakeTokenCredential ) AuthProviderAssertions {
55
63
return func (t testing.TB , authProvider * AuthProvider ) {
56
64
t .Helper ()
57
65
58
66
assert .NotNil (t , authProvider .ComputeCredential )
59
67
60
68
cred , ok := authProvider .ComputeCredential .(* fakeTokenCredential )
61
69
assert .True (t , ok , "expected a fake token credential" )
62
- assert .Equal (t , expectedID , cred .ID )
70
+ assert .Equal (t , tokenCredential . ID , cred .ID )
63
71
}
64
72
}
65
73
66
- func AssertNetworkTokenCredential (expectedID string ) AuthProviderAssertions {
74
+ func AssertNetworkTokenCredential (tokenCredential * fakeTokenCredential ) AuthProviderAssertions {
67
75
return func (t testing.TB , authProvider * AuthProvider ) {
68
76
t .Helper ()
69
77
70
78
assert .NotNil (t , authProvider .NetworkCredential )
71
79
72
80
cred , ok := authProvider .NetworkCredential .(* fakeTokenCredential )
73
81
assert .True (t , ok , "expected a fake token credential" )
74
- assert .Equal (t , expectedID , cred .ID )
82
+ assert .Equal (t , tokenCredential . ID , cred .ID )
75
83
}
76
84
}
77
85
0 commit comments