Skip to content

Commit

Permalink
coverage test
Browse files Browse the repository at this point in the history
  • Loading branch information
Lifosmin Simon committed Oct 23, 2024
1 parent 45f0940 commit 5b22978
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
7 changes: 5 additions & 2 deletions plugins/providers/dataplex/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ type policyTagClient struct {
taxonomyLocation string
}

func newPolicyTagClient(projectID, location string, credentialsJSON []byte) (*policyTagClient, error) {
func NewPolicyTagClient(projectID, location string, credentialsJSON []byte) (*policyTagClient, error) {
ctx := context.Background()

clientOptions := []option.ClientOption{
option.WithCredentialsJSON(credentialsJSON),
option.WithGRPCDialOption(grpc.WithChainUnaryInterceptor(otelgrpc.UnaryClientInterceptor())),
option.WithGRPCDialOption(grpc.WithChainStreamInterceptor(otelgrpc.StreamClientInterceptor())),
}
if credentialsJSON != nil {
clientOptions = append(clientOptions, option.WithCredentialsJSON(credentialsJSON))
}

policyManager, err := datacatalog.NewPolicyTagManagerClient(ctx, clientOptions...)
if err != nil {
return nil, err
Expand Down
26 changes: 26 additions & 0 deletions plugins/providers/dataplex/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package dataplex_test

import (
"testing"

"github.com/goto/guardian/plugins/providers/dataplex"
"github.com/stretchr/testify/assert"
)

func TestNewPolicyTagClient(t *testing.T) {
t.Run("should return error if credentials are invalid", func(t *testing.T) {
invalidCredentials := []byte("invalid-credentials")

actualClient, actualError := dataplex.NewPolicyTagClient("test-project", "test-location", invalidCredentials)

assert.Nil(t, actualClient)
assert.Error(t, actualError)
})

t.Run("should return client and nil error on success", func(t *testing.T) {
actualClient, actualError := dataplex.NewPolicyTagClient("test-project", "test-location", nil)

assert.NotNil(t, actualClient)
assert.Nil(t, actualError)
})
}
2 changes: 1 addition & 1 deletion plugins/providers/dataplex/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (p *Provider) getPolicyTagClient(credentials Credentials) (PolicyTagClient,
if err != nil {
return nil, ErrUnableToDecryptCredentials
}
client, err := newPolicyTagClient(projectID, taxonomyLocation, []byte(credentials.ServiceAccountKey))
client, err := NewPolicyTagClient(projectID, taxonomyLocation, []byte(credentials.ServiceAccountKey))
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 5b22978

Please sign in to comment.