1 package grpc
2
3 import (
4 "crypto/tls"
5 "testing"
6
7 "github.com/jmhodges/clock"
8 "github.com/letsencrypt/boulder/cmd"
9 "github.com/letsencrypt/boulder/metrics"
10 "github.com/letsencrypt/boulder/test"
11 _ "google.golang.org/grpc/health"
12 )
13
14 func TestClientSetup(t *testing.T) {
15 tests := []struct {
16 name string
17 cfg *cmd.GRPCClientConfig
18 expectTarget string
19 wantErr bool
20 }{
21 {"valid, address provided", &cmd.GRPCClientConfig{ServerAddress: "localhost:8080"}, "dns:///localhost:8080", false},
22 {"valid, implicit localhost with port provided", &cmd.GRPCClientConfig{ServerAddress: ":8080"}, "dns:///:8080", false},
23 {"valid, IPv6 address provided", &cmd.GRPCClientConfig{ServerAddress: "[::1]:8080"}, "dns:///[::1]:8080", false},
24 {"valid, two addresses provided", &cmd.GRPCClientConfig{ServerIPAddresses: []string{"127.0.0.1:8080", "127.0.0.2:8080"}}, "static:///127.0.0.1:8080,127.0.0.2:8080", false},
25 {"valid, two addresses provided, one has an implicit localhost, ", &cmd.GRPCClientConfig{ServerIPAddresses: []string{":8080", "127.0.0.2:8080"}}, "static:///:8080,127.0.0.2:8080", false},
26 {"valid, two addresses provided, one is IPv6, ", &cmd.GRPCClientConfig{ServerIPAddresses: []string{"[::1]:8080", "127.0.0.2:8080"}}, "static:///[::1]:8080,127.0.0.2:8080", false},
27 {"invalid, both address and addresses provided", &cmd.GRPCClientConfig{ServerAddress: "localhost:8080", ServerIPAddresses: []string{"127.0.0.1:8080"}}, "", true},
28 {"invalid, no address or addresses provided", &cmd.GRPCClientConfig{}, "", true},
29 }
30 for _, tt := range tests {
31 t.Run(tt.name, func(t *testing.T) {
32 client, err := ClientSetup(tt.cfg, &tls.Config{}, metrics.NoopRegisterer, clock.NewFake())
33 if tt.wantErr {
34 test.AssertError(t, err, "expected error, got nil")
35 } else {
36 test.AssertNotError(t, err, "unexpected error")
37 }
38 if tt.expectTarget != "" {
39 test.AssertEquals(t, client.Target(), tt.expectTarget)
40 }
41 })
42 }
43 }
44
View as plain text