...

Source file src/github.com/letsencrypt/boulder/grpc/resolver_test.go

Documentation: github.com/letsencrypt/boulder/grpc

     1  package grpc
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/letsencrypt/boulder/test"
     7  	"google.golang.org/grpc/resolver"
     8  )
     9  
    10  func Test_parseResolverIPAddress(t *testing.T) {
    11  	tests := []struct {
    12  		name         string
    13  		addr         string
    14  		expectTarget *resolver.Address
    15  		wantErr      bool
    16  	}{
    17  		{"valid, IPv4 address", "127.0.0.1:1337", &resolver.Address{Addr: "127.0.0.1:1337", ServerName: "127.0.0.1:1337"}, false},
    18  		{"valid, IPv6 address", "[::1]:1337", &resolver.Address{Addr: "[::1]:1337", ServerName: "[::1]:1337"}, false},
    19  		{"valid, port only", ":1337", &resolver.Address{Addr: "127.0.0.1:1337", ServerName: "127.0.0.1:1337"}, false},
    20  		{"invalid, hostname address", "localhost:1337", nil, true},
    21  		{"invalid, IPv6 address, no brackets", "::1:1337", nil, true},
    22  	}
    23  	for _, tt := range tests {
    24  		t.Run(tt.name, func(t *testing.T) {
    25  			got, err := parseResolverIPAddress(tt.addr)
    26  			if tt.wantErr {
    27  				test.AssertError(t, err, "expected error, got nil")
    28  			} else {
    29  				test.AssertNotError(t, err, "unexpected error")
    30  			}
    31  			test.AssertDeepEquals(t, got, tt.expectTarget)
    32  		})
    33  	}
    34  }
    35  

View as plain text