|
@@ -0,0 +1,36 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+package netutil
|
|
|
+
|
|
|
+import (
|
|
|
+ "testing"
|
|
|
+
|
|
|
+ "github.com/stretchr/testify/assert"
|
|
|
+)
|
|
|
+
|
|
|
+func TestIsLocalHostname(t *testing.T) {
|
|
|
+ tests := []struct {
|
|
|
+ hostname string
|
|
|
+ want bool
|
|
|
+ }{
|
|
|
+ {hostname: "localhost", want: true},
|
|
|
+ {hostname: "127.0.0.1", want: true},
|
|
|
+ {hostname: "::1", want: true},
|
|
|
+ {hostname: "0:0:0:0:0:0:0:1", want: true},
|
|
|
+ {hostname: "fuf.me", want: true},
|
|
|
+ {hostname: "127.0.0.95", want: true},
|
|
|
+ {hostname: "0.0.0.0", want: true},
|
|
|
+ {hostname: "192.168.123.45", want: true},
|
|
|
+
|
|
|
+ {hostname: "gogs.io", want: false},
|
|
|
+ {hostname: "google.com", want: false},
|
|
|
+ {hostname: "165.232.140.255", want: false},
|
|
|
+ }
|
|
|
+ for _, test := range tests {
|
|
|
+ t.Run("", func(t *testing.T) {
|
|
|
+ assert.Equal(t, test.want, IsLocalHostname(test.hostname))
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|