diff --git a/go.mod b/go.mod index dedeb70..c9aee8d 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( github.com/sirupsen/logrus v1.4.2 github.com/spf13/pflag v1.0.3 github.com/spf13/viper v1.7.1 + github.com/stretchr/testify v1.6.1 golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a gorm.io/driver/mysql v1.0.3 gorm.io/driver/sqlite v1.1.4 diff --git a/server/utils/util_test.go b/server/utils/util_test.go new file mode 100644 index 0000000..ef375a7 --- /dev/null +++ b/server/utils/util_test.go @@ -0,0 +1,28 @@ +package utils_test + +import ( + "net" + "testing" + + "next-terminal/server/utils" + + "github.com/stretchr/testify/assert" +) + +func TestTcping(t *testing.T) { + localhost4 := "127.0.0.1" + localhost6 := "::1" + conn, err := net.Listen("tcp", ":9999") + assert.NoError(t, err) + ip4resfalse := utils.Tcping(localhost4, 22) + assert.Equal(t, false, ip4resfalse) + + ip4res := utils.Tcping(localhost4, 9999) + assert.Equal(t, true, ip4res) + + ip6res := utils.Tcping(localhost6, 9999) + assert.Equal(t, true, ip6res) + defer func() { + conn.Close() + }() +}