| 6 | ) |
| 7 | |
| 8 | func TestNetworkAddress(t *testing.T) { |
| 9 | tests := []struct { |
| 10 | addr net.Addr |
| 11 | network string |
| 12 | address string |
| 13 | }{ |
| 14 | { |
| 15 | addr: TCP("127.0.0.1"), |
| 16 | network: "tcp", |
| 17 | address: "127.0.0.1:9092", |
| 18 | }, |
| 19 | |
| 20 | { |
| 21 | addr: TCP("::1"), |
| 22 | network: "tcp", |
| 23 | address: "[::1]:9092", |
| 24 | }, |
| 25 | |
| 26 | { |
| 27 | addr: TCP("localhost"), |
| 28 | network: "tcp", |
| 29 | address: "localhost:9092", |
| 30 | }, |
| 31 | |
| 32 | { |
| 33 | addr: TCP("localhost:9092"), |
| 34 | network: "tcp", |
| 35 | address: "localhost:9092", |
| 36 | }, |
| 37 | |
| 38 | { |
| 39 | addr: TCP("localhost", "localhost:9093", "localhost:9094"), |
| 40 | network: "tcp,tcp,tcp", |
| 41 | address: "localhost:9092,localhost:9093,localhost:9094", |
| 42 | }, |
| 43 | } |
| 44 | |
| 45 | for _, test := range tests { |
| 46 | t.Run(test.network+"+"+test.address, func(t *testing.T) { |
| 47 | if s := test.addr.Network(); s != test.network { |
| 48 | t.Errorf("network mismatch: want %q but got %q", test.network, s) |
| 49 | } |
| 50 | if s := test.addr.String(); s != test.address { |
| 51 | t.Errorf("network mismatch: want %q but got %q", test.address, s) |
| 52 | } |
| 53 | }) |
| 54 | } |
| 55 | } |