Revanth14 commented on code in PR #2018:
URL: https://github.com/apache/iceberg-go/pull/2018#discussion_r4047312428
##########
io/gocloud/azure/azure_test.go:
##########
@@ -23,39 +23,61 @@ import (
"net/url"
"testing"
+ "github.com/Azure/azure-sdk-for-go/sdk/azcore"
+ "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake"
+ "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
+ icebergio "github.com/apache/iceberg-go/io"
"github.com/apache/iceberg-go/io/gocloud/blobfs"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gocloud.dev/blob"
"gocloud.dev/blob/memblob"
)
+func TestProductionAzureCredentialFactories(t *testing.T) {
+ factories := productionAzureCredentialFactories()
+
+ t.Run("default credential", func(t *testing.T) {
+ // Avoid inheriting credential selection or loading credentials
from the environment.
+ t.Setenv("AZURE_TOKEN_CREDENTIALS", "dev")
+
+ credential, err := factories.newDefaultCredential(nil)
+ require.NoError(t, err)
+ assert.IsType(t, &azidentity.DefaultAzureCredential{},
credential)
+ })
+
+ t.Run("managed identity credential", func(t *testing.T) {
+ credential, err := factories.newManagedIdentity(nil)
+ require.NoError(t, err)
+ assert.IsType(t, &azidentity.ManagedIdentityCredential{},
credential)
+ })
+}
+
func TestCreateAzureBucketDefaultCredentialCalled(t *testing.T) {
ctx := context.Background()
parsedURL, err :=
url.Parse("abfs://[email protected]/path")
assert.NoError(t, err)
- props := map[string]string{}
+ defaultCredentialCalled := false
+ credentialFactories := azureCredentialFactories{
+ newDefaultCredential:
func(*azidentity.DefaultAzureCredentialOptions) (azcore.TokenCredential, error)
{
+ defaultCredentialCalled = true
- bucket, err := createAzureBucket(ctx, parsedURL, props)
- if err != nil {
- // If bucket creation fails, it should be with a
DefaultAzureCredential error
- assert.Contains(t, err.Error(), "DefaultAzureCredential",
- "Expected DefaultAzureCredential error but got: %v",
err)
- t.Logf("DefaultAzureCredential path was taken and failed at
creation: %v", err)
+ return &fake.TokenCredential{}, nil
+ },
+ newManagedIdentity:
func(*azidentity.ManagedIdentityCredentialOptions) (azcore.TokenCredential,
error) {
+ t.Fatal("managed identity credential factory should not
be called")
- return
+ return nil, nil
Review Comment:
Updated both closures to use `t.Errorf` and return a non-nil error via
`errors.New`.
One small clarification: `Goexit` terminates the calling goroutine, so the
return after `t.Fatal` wouldn’t execute. Still, this makes the failure handling
explicit and avoids relying on a fatal assertion inside the callback.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]