Skip to content

Commit 3d65a69

Browse files
committed
fix: Add grpc tester receiver to TestDial
1 parent d8a2ca2 commit 3d65a69

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

credentials/alts/internal/handshaker/service/service_test.go

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,35 @@ package service
2020

2121
import (
2222
"testing"
23+
24+
"google.golang.org/grpc"
25+
"google.golang.org/grpc/internal/grpctest"
2326
)
2427

28+
type s struct {
29+
grpctest.Tester
30+
}
31+
32+
func Test(t *testing.T) {
33+
grpctest.RunSubTests(t, s{})
34+
}
35+
2536
const (
2637
testAddress1 = "some_address_1"
2738
testAddress2 = "some_address_2"
2839
)
2940

30-
// TestDial verifies the behavior of the Dial function in managing gRPC connections
31-
// and checks the below scenarios:
32-
// - First call to Dial with an address creates a new connection and stores it.
33-
// - Second call to Dial with the same address returns the existing connection
34-
// and expects the returned connection matching with ƒirst connection.
35-
// - Third call to Dial with a different address creates a separate new connection
36-
// and expects a different connection from connnection1 and connection2.
37-
func TestDial(t *testing.T) {
41+
// TestDial verifies the behaviour of alts handshake when there are multiple Dials.
42+
// If a connection has already been established, this function returns it.
43+
// Otherwise, a new connection is created.
44+
func (s) TestDial(t *testing.T) {
45+
temp := hsDialer
46+
hsDialer = func(target string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
47+
return &grpc.ClientConn{}, nil
48+
}
49+
defer func() {
50+
hsDialer = temp
51+
}()
3852
// First call to Dial, it should create a connection to the server running
3953
// at the given address.
4054
conn1, err := Dial(testAddress1)
@@ -60,8 +74,7 @@ func TestDial(t *testing.T) {
6074
t.Fatalf("hsConnMap[%v]=%v, want %v", testAddress1, got, want)
6175
}
6276

63-
// Third call to Dial using a different address should create a new
64-
// connection.
77+
// Third call to Dial using a different address should create a new connection.
6578
conn3, err := Dial(testAddress2)
6679
if err != nil {
6780
t.Fatalf("third call to Dial(%v) failed: %v", testAddress2, err)

0 commit comments

Comments
 (0)