fix(server):add test file
This commit is contained in:
parent
f3cc22d611
commit
949e8a7ed5
1
go.mod
1
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
|
||||
|
28
server/utils/util_test.go
Normal file
28
server/utils/util_test.go
Normal file
@ -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()
|
||||
}()
|
||||
}
|
Loading…
Reference in New Issue
Block a user