Skip to content

Commit

Permalink
feat(service_test.go): add grpc resolver import and set default schem…
Browse files Browse the repository at this point in the history
…e for testing

The import of `google.golang.org/grpc/resolver` and setting the default
scheme to "passthrough" in the test setup function enhances the testing
environment for gRPC services. This change ensures that the gRPC client
in tests resolves to the correct network scheme without requiring
external DNS, which is crucial for consistent and isolated testing
environments.
  • Loading branch information
cybersiddhu authored and kodiakhq[bot] committed May 31, 2024
1 parent adc191d commit c4d56d2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions internal/app/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"testing"
"time"

"google.golang.org/grpc/resolver"

"github.com/dictyBase/aphgrpc"
manager "github.com/dictyBase/arangomanager"
"github.com/dictyBase/arangomanager/testarango"
Expand Down Expand Up @@ -77,13 +79,13 @@ func setup(t *testing.T) (content.ContentServiceClient, *require.Assertions) {
dialer := func(context.Context, string) (net.Conn, error) {
conn, err := listener.Dial()
assert.NoError(err, "expect no error from creating listener")

return conn, nil
}
resolver.SetDefaultScheme("passthrough")
conn, err := grpc.NewClient(
"",
grpc.WithContextDialer(dialer),
"bufnet",
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithContextDialer(dialer),
)
assert.NoError(err, "expect no error in creating grpc client")
t.Cleanup(func() {
Expand Down

0 comments on commit c4d56d2

Please sign in to comment.