TestIsLoopback tests the IsLoopback helper function.
(t *testing.T)
| 7 | |
| 8 | // TestIsLoopback tests the IsLoopback helper function. |
| 9 | func TestIsLoopback(t *testing.T) { |
| 10 | tests := []struct { |
| 11 | addr string |
| 12 | want bool |
| 13 | }{ |
| 14 | {"localhost", true}, |
| 15 | {"localhost:3000", true}, |
| 16 | {"127.0.0.1", true}, |
| 17 | {"127.0.0.1:3000", true}, |
| 18 | {"[::1]", true}, |
| 19 | {"[::1]:3000", true}, |
| 20 | {"::1", true}, |
| 21 | {"", false}, |
| 22 | {"evil.com", false}, |
| 23 | {"evil.com:80", false}, |
| 24 | {"localhost.evil.com", false}, |
| 25 | {"127.0.0.1.evil.com", false}, |
| 26 | } |
| 27 | |
| 28 | for _, tt := range tests { |
| 29 | t.Run(tt.addr, func(t *testing.T) { |
| 30 | if got := IsLoopback(tt.addr); got != tt.want { |
| 31 | t.Errorf("IsLoopback(%q) = %v, want %v", tt.addr, got, tt.want) |
| 32 | } |
| 33 | }) |
| 34 | } |
| 35 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…