From da23f8a58a91f1dfb25beb4de4d636409e616612 Mon Sep 17 00:00:00 2001 From: jiuker <2818723467@qq.com> Date: Fri, 12 Jan 2024 09:51:50 +0800 Subject: [PATCH] change ut --- internal/keystore/azure/key-vault_test.go | 56 ++++++++++++++++++----- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/internal/keystore/azure/key-vault_test.go b/internal/keystore/azure/key-vault_test.go index 037c46ca..839b7572 100644 --- a/internal/keystore/azure/key-vault_test.go +++ b/internal/keystore/azure/key-vault_test.go @@ -13,8 +13,6 @@ func TestConnectWithCredentials(t *testing.T) { ClientID := os.Getenv("ClientID") TenantID := os.Getenv("TenantID") Secret := os.Getenv("Secret") - // managed identity credential - ManagedIdentityClientID := os.Getenv("ManagedIdentityClientID") if ClientID == "" || TenantID == "" || Secret == "" || EndPoint == "" { t.Skip("Skipping test due to missing credentials") } @@ -25,11 +23,7 @@ func TestConnectWithCredentials(t *testing.T) { return } os.Setenv("AZURE_CLIENT_API_VERSION", "7.4") - c2, err := ConnectWithIdentity(ctx, EndPoint, ManagedIdentity{ClientID: ManagedIdentityClientID}) - if err != nil { - return - } - c3, err := ConnectWithCredentials(ctx, EndPoint, Credentials{TenantID: TenantID, ClientID: ClientID, Secret: Secret}) + c2, err := ConnectWithCredentials(ctx, EndPoint, Credentials{TenantID: TenantID, ClientID: ClientID, Secret: Secret}) if err != nil { return } @@ -63,21 +57,59 @@ func TestConnectWithCredentials(t *testing.T) { t.Logf("list:[%s] s:[%s] err:[%v]\n", list, s, err) t.Log("-------------------------------") } + _ = c1 + _ = c2 +} + +func TestConnectWithManagedIdentityCredentials(t *testing.T) { + // endpoint + EndPoint := os.Getenv("EndPoint") + // managed identity credential + ManagedIdentityClientID := os.Getenv("ManagedIdentityClientID") + if ManagedIdentityClientID == "" || EndPoint == "" { + t.Skip("Skipping test due to missing credentials") + } + ctx := context.Background() + os.Setenv("AZURE_CLIENT_API_VERSION", "7.2") + c1, err := ConnectWithIdentity(ctx, EndPoint, ManagedIdentity{ClientID: ManagedIdentityClientID}) + if err != nil { + return + } + os.Setenv("AZURE_CLIENT_API_VERSION", "7.4") + c2, err := ConnectWithIdentity(ctx, EndPoint, ManagedIdentity{ClientID: ManagedIdentityClientID}) + if err != nil { + return + } + { + // delete first + _ = c1.Delete(ctx, "mytestFirst-c1-m") + // create + err = c1.Create(ctx, "mytestFirst-c1-m", []byte("hello")) + if err != nil { + t.Error(err) + } + data, err := c1.Get(ctx, "mytestFirst-c1-m") + t.Logf("data:[%s] err:[%v]\n", data, err) + + list, s, err := c1.List(ctx, "", 25) + t.Logf("list:[%s] s:[%s] err:[%v]\n", list, s, err) + t.Log("-------------------------------") + } { // delete first - _ = c3.Delete(ctx, "mytestFirst-c3") + _ = c2.Delete(ctx, "mytestFirst-c2-m") // create - err = c3.Create(ctx, "mytestFirst-c3", []byte("hello")) + err = c2.Create(ctx, "mytestFirst-c2-m", []byte("hello")) if err != nil { t.Error(err) } - data, err := c3.Get(ctx, "mytestFirst-c3") + data, err := c2.Get(ctx, "mytestFirst-c2-m") t.Logf("data:[%s] err:[%v]\n", data, err) - list, s, err := c3.List(ctx, "", 25) + + list, s, err := c2.List(ctx, "", 25) t.Logf("list:[%s] s:[%s] err:[%v]\n", list, s, err) t.Log("-------------------------------") } _ = c1 _ = c2 - _ = c3 }