@@ -18,25 +18,33 @@ package azclient
1818
1919import (
2020 "context"
21+ "fmt"
22+ "sync/atomic"
2123 "testing"
24+ "time"
2225
2326 "github.com/Azure/azure-sdk-for-go/sdk/azcore"
2427 "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
2528 "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
2629 "github.com/stretchr/testify/assert"
2730)
2831
32+ var (
33+ incCounter = atomic.Int64 {}
34+ )
35+
2936type fakeTokenCredential struct {
3037 ID string
3138}
3239
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 ())
3442 return & fakeTokenCredential {ID : id }
3543}
3644
3745func (f * fakeTokenCredential ) GetToken (
38- ctx context.Context ,
39- options policy.TokenRequestOptions ,
46+ _ context.Context ,
47+ _ policy.TokenRequestOptions ,
4048) (azcore.AccessToken , error ) {
4149 panic ("not implemented" )
4250}
@@ -51,27 +59,27 @@ func ApplyAssertions(t testing.TB, authProvider *AuthProvider, assertions []Auth
5159 }
5260}
5361
54- func AssertComputeTokenCredential (expectedID string ) AuthProviderAssertions {
62+ func AssertComputeTokenCredential (tokenCredential * fakeTokenCredential ) AuthProviderAssertions {
5563 return func (t testing.TB , authProvider * AuthProvider ) {
5664 t .Helper ()
5765
5866 assert .NotNil (t , authProvider .ComputeCredential )
5967
6068 cred , ok := authProvider .ComputeCredential .(* fakeTokenCredential )
6169 assert .True (t , ok , "expected a fake token credential" )
62- assert .Equal (t , expectedID , cred .ID )
70+ assert .Equal (t , tokenCredential . ID , cred .ID )
6371 }
6472}
6573
66- func AssertNetworkTokenCredential (expectedID string ) AuthProviderAssertions {
74+ func AssertNetworkTokenCredential (tokenCredential * fakeTokenCredential ) AuthProviderAssertions {
6775 return func (t testing.TB , authProvider * AuthProvider ) {
6876 t .Helper ()
6977
7078 assert .NotNil (t , authProvider .NetworkCredential )
7179
7280 cred , ok := authProvider .NetworkCredential .(* fakeTokenCredential )
7381 assert .True (t , ok , "expected a fake token credential" )
74- assert .Equal (t , expectedID , cred .ID )
82+ assert .Equal (t , tokenCredential . ID , cred .ID )
7583 }
7684}
7785
0 commit comments