Skip to content

Commit

Permalink
change ut
Browse files Browse the repository at this point in the history
  • Loading branch information
jiuker committed Jan 12, 2024
1 parent 95f9061 commit da23f8a
Showing 1 changed file with 44 additions and 12 deletions.
56 changes: 44 additions & 12 deletions internal/keystore/azure/key-vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}

0 comments on commit da23f8a

Please sign in to comment.