|
|
@@ -8,7 +8,8 @@ import (
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
)
|
|
|
|
|
|
-func TestSystemPing(t *testing.T) {
|
|
|
+// integration test
|
|
|
+func Test_SystemPing(t *testing.T) {
|
|
|
type testCase struct {
|
|
|
// constructors
|
|
|
address string
|
|
|
@@ -40,7 +41,7 @@ func TestSystemPing(t *testing.T) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-func TestSplitBytes(t *testing.T) {
|
|
|
+func Test_SplitBytes(t *testing.T) {
|
|
|
type testCase struct {
|
|
|
// test data
|
|
|
bytes *[]byte
|
|
|
@@ -66,34 +67,51 @@ func TestSplitBytes(t *testing.T) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-func TestPing(t *testing.T) {
|
|
|
+func Test_Ping(t *testing.T) {
|
|
|
type testCase struct {
|
|
|
address string
|
|
|
|
|
|
delay float64
|
|
|
err error
|
|
|
}
|
|
|
- t.Run("test golang ping interface", func(t *testing.T) {
|
|
|
- var tests []testCase
|
|
|
- // init tests
|
|
|
- for range 5 {
|
|
|
- tests = append(tests, testCase{
|
|
|
- address: "127.0.0.1",
|
|
|
- delay: 0,
|
|
|
- err: nil,
|
|
|
- })
|
|
|
- }
|
|
|
- tests = append(tests, testCase{address: "willneverresolveever", delay: -1, err: errors.New("test failure")})
|
|
|
+ var tests []testCase
|
|
|
+ // init tests
|
|
|
+ tests = append(tests, testCase{
|
|
|
+ address: "127.0.0.1",
|
|
|
+ delay: 0,
|
|
|
+ err: nil,
|
|
|
+ })
|
|
|
+ tests = append(tests,
|
|
|
+ testCase{
|
|
|
+ address: "willneverresolveever",
|
|
|
+ delay: -1,
|
|
|
+ err: errors.New("test failure"),
|
|
|
+ })
|
|
|
|
|
|
- for _, test := range tests {
|
|
|
- delay, err := Ping(test.address)
|
|
|
- assert.GreaterOrEqual(t, delay, test.delay)
|
|
|
- if test.err != nil {
|
|
|
- assert.Error(t, err)
|
|
|
- assert.Equal(t, delay, test.delay)
|
|
|
- } else {
|
|
|
- assert.NoError(t, err)
|
|
|
- }
|
|
|
+ for _, test := range tests {
|
|
|
+ delay, err := Ping(test.address)
|
|
|
+ assert.GreaterOrEqual(t, delay, test.delay)
|
|
|
+ if test.err != nil {
|
|
|
+ assert.Error(t, err)
|
|
|
+ assert.Equal(t, delay, test.delay)
|
|
|
+ } else {
|
|
|
+ assert.NoError(t, err)
|
|
|
}
|
|
|
- })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func spawnAddress(a string, r []float64, m int) Address {
|
|
|
+ return Address{Address: a, results: r, max_results: m}
|
|
|
+}
|
|
|
+func Test_Address_Truncate(t *testing.T) {
|
|
|
+ testA := spawnAddress("test", make([]float64, 20), 10)
|
|
|
+ postTruncate := testA.Truncate()
|
|
|
+ assert.True(t, len(postTruncate) == 10)
|
|
|
+}
|
|
|
+
|
|
|
+func Test_Address_Last(t *testing.T) {
|
|
|
+ testA := spawnAddress("test", []float64{20}, 10)
|
|
|
+ assert.True(t, testA.Last() == 20)
|
|
|
+ testA = spawnAddress("test", []float64{}, 10)
|
|
|
+ assert.True(t, testA.Last() == -1)
|
|
|
}
|