decred.org/dcrdex@v1.0.5/server/cmd/dcrdex/config_test.go (about)

     1  // This code is available on the terms of the project LICENSE.md file,
     2  // also available online at https://blueoakcouncil.org/license/1.0.0.
     3  
     4  package main
     5  
     6  import "testing"
     7  
     8  const (
     9  	defaultHost = "127.0.0.1"
    10  	defaultPort = "17232"
    11  )
    12  
    13  func Test_normalizeNetworkAddress(t *testing.T) {
    14  	tests := []struct {
    15  		listen  string
    16  		want    string
    17  		wantErr bool
    18  	}{
    19  		{
    20  			listen: "[::1]",
    21  			want:   "[::1]:17232",
    22  		},
    23  		{
    24  			listen: "[::]:",
    25  			want:   "[::]:17232",
    26  		},
    27  		{
    28  			listen: "",
    29  			want:   "127.0.0.1:17232",
    30  		},
    31  		{
    32  			listen: "127.0.0.2",
    33  			want:   "127.0.0.2:17232",
    34  		},
    35  		{
    36  			listen: ":7222",
    37  			want:   "127.0.0.1:7222",
    38  		},
    39  	}
    40  	for _, tt := range tests {
    41  		t.Run(tt.listen, func(t *testing.T) {
    42  			got, err := normalizeNetworkAddress(tt.listen, defaultHost, defaultPort)
    43  			if (err != nil) != tt.wantErr {
    44  				t.Errorf("normalizeNetworkAddress() error = %v, wantErr %v", err, tt.wantErr)
    45  				return
    46  			}
    47  			if got != tt.want {
    48  				t.Errorf("normalizeNetworkAddress() = %v, want %v", got, tt.want)
    49  			}
    50  		})
    51  	}
    52  }