ports/main_test.go

40 lines
722 B
Go
Raw Normal View History

2022-06-20 20:07:41 +00:00
package main
import (
"reflect"
"strconv"
"testing"
)
func TestPortsSetup(t *testing.T) {
t.Run("Single Port", func(t *testing.T) {
want := []string{"1"}
got := portsSetup(want)
assertEqual(t, got, want)
})
t.Run("Multi Port", func(t *testing.T) {
want := []string{"1", "2"}
got := portsSetup(want)
assertEqual(t, got, want)
})
t.Run("Empty Port", func(t *testing.T) {
var ports, want []string
got := portsSetup(ports)
for i := 1; i < 65535; i++ {
want = append(want, strconv.FormatInt(int64(i), 10))
}
assertEqual(t, got, want)
})
}
func assertEqual(t testing.TB, got, want []string) {
t.Helper()
if !reflect.DeepEqual(got, want) {
t.Errorf("got %v, want %v", got, want)
}
}