Add unit tests

This commit is contained in:
Mayuresh Gaitonde
2020-12-17 17:25:53 -08:00
parent 3702339f44
commit 6be4d69d02
705 changed files with 120529 additions and 150051 deletions

View File

@@ -0,0 +1,35 @@
package controller
import (
"net"
"testing"
"github.com/stretchr/testify/assert"
)
func TestPortMonitor(t *testing.T) {
a := assert.New(t)
addr, _ := net.ResolveTCPAddr("tcp", ":33333")
conn, err := net.ListenTCP("tcp", addr)
if err != nil {
a.FailNow(err.Error())
}
a.True(portMonitor("tcp", "33333"))
a.False(portMonitor("tcp", "44444"))
conn.Close()
uaddr, _ := net.ResolveUDPAddr("udp", ":33333")
udpconn, err := net.ListenUDP("udp", uaddr)
if err != nil {
a.FailNow(err.Error())
}
a.True(portMonitor("udp", "33333"))
a.False(portMonitor("udp", "44444"))
udpconn.Close()
}
func TestExecMonitor(t *testing.T) {
a := assert.New(t)
a.True(execMonitor("echo foo"))
a.False(execMonitor("echo foo && false"))
}