Debian Codegraph @

debian/go/src/github.com/modelcontextprotocol/go-sdk/internal/util/net_test.go

raw symbols SCIP
1 // Copyright 2025 The Go MCP SDK Authors. All rights reserved.
2 // Use of this source code is governed by the license
3 // that can be found in the LICENSE file.
4 package util
5
6 import "testing"
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 }