Skip to content

Commit

Permalink
add ut
Browse files Browse the repository at this point in the history
  • Loading branch information
cvvz committed Mar 20, 2024
1 parent 68c19d6 commit db238de
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions pkg/azuredisk/azuredisk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,42 @@ func TestRun(t *testing.T) {
assert.Nil(t, err)
},
},
{
name: "Successful run with federated workload identity azure client",
testFunc: func(t *testing.T) {
if err := os.WriteFile(fakeCredFile, []byte(fakeCredContent), 0666); err != nil {
t.Error(err)
}

defer func() {
if err := os.Remove(fakeCredFile); err != nil {
t.Error(err)
}
}()

t.Setenv(consts.DefaultAzureCredentialFileEnv, fakeCredFile)
t.Setenv("AZURE_TENANT_ID", "1234")
t.Setenv("AZURE_CLIENT_ID", "123456")
t.Setenv("AZURE_FEDERATED_TOKEN_FILE", "fake-token-file")

d := newDriverV1(&DriverOptions{
Endpoint: "tcp://127.0.0.1:0",
})

ctx, cancel := context.WithCancel(context.Background())
ch := make(chan error)
go func() {
err := d.Run(ctx)
ch <- err
}()
cancel()
assert.Nil(t, <-ch)
assert.Equal(t, d.cloud.UseFederatedWorkloadIdentityExtension, true)
assert.Equal(t, d.cloud.AADFederatedTokenFile, "fake-token-file")
assert.Equal(t, d.cloud.AADClientID, "123456")
assert.Equal(t, d.cloud.TenantID, "1234")
},
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit db238de

Please sign in to comment.