mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-24 15:10:19 +00:00
* Adds logic to ensure nothing proceeds a connectivity check and adds tests * Adds waitgroup to verify monitor routine startup before shutdown is called thus eliminating race condition * fix func desc and test func naming convention * Add invalid address check * Fix race condition for okgroup on wait group when instant shutdown called * Fix fmt issue with gofmt
38 lines
727 B
Go
38 lines
727 B
Go
package connchecker
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestConnection(t *testing.T) {
|
|
faultyDomain := []string{"faultyIP"}
|
|
faultyHost := []string{"faultyHost"}
|
|
_, err := New(faultyDomain, nil, 100000)
|
|
if err == nil {
|
|
t.Fatal("Test Failed - New error cannot be nil")
|
|
}
|
|
|
|
_, err = New(DefaultDNSList, nil, 100000)
|
|
if err != nil {
|
|
t.Fatal("Test Failed - New error", err)
|
|
}
|
|
|
|
_, err = New(nil, faultyHost, 100000)
|
|
if err != nil {
|
|
t.Fatal("Test Failed - New error cannot be nil", err)
|
|
}
|
|
|
|
c, err := New(nil, nil, 0)
|
|
if err != nil {
|
|
t.Fatal("Test Failed - New error", err)
|
|
}
|
|
|
|
if !c.IsConnected() {
|
|
t.Log("Test - No internet connection found")
|
|
} else {
|
|
t.Log("Test - Internet connection found")
|
|
}
|
|
|
|
c.Shutdown()
|
|
}
|