1
0
Fork 0
httpserver/funcs/funcs_test.go

48 Zeilen
1.2 KiB
Go

package funcs_test
import (
"testing"
"go.sebtobie.de/httpserver/funcs"
)
type testtype struct {
name string
arg string
want bool
}
func TestIsUnix(t *testing.T) {
tests := []testtype{
{name: "absolute unix", arg: "/tmp/xyz", want: true},
{name: "relative unix", arg: "xyz", want: true},
{name: "simple tcp4 address", arg: "127.0.0.1:0", want: false},
{name: "simple tcp6 address", arg: "[::1]:0", want: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := funcs.IsUnix(tt.arg); got != tt.want {
t.Errorf("IsUnix() = %v, want %v", got, tt.want)
}
})
}
}
func TestIsTCP(t *testing.T) {
tests := []testtype{
{name: "simple tcp4 address", arg: "127.0.0.1:0", want: true},
{name: "simple tcp6 address", arg: "[::1]:0", want: true},
{name: "too big ip address", arg: "999.0.0.1:0", want: false},
{name: "too big port", arg: "127.0.0.1:65536", want: false},
{name: "unix relative", arg: "xyz.sock", want: false},
{name: "unix absolute", arg: "/xyz.sock", want: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := funcs.IsTCP(tt.arg); got != tt.want {
t.Errorf("IsTCP() = %v, want %v", got, tt.want)
}
})
}
}