Create monitor for item acceptance/publishing
This commit is contained in:
61
monitor/item_test.go
Normal file
61
monitor/item_test.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package monitor
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Test_Item(t *testing.T) {
|
||||
a := NewItem("localhost:12345", time.Second)
|
||||
b := NewItem("localhost:54321", time.Minute)
|
||||
if a.Compare(b) != -1 {
|
||||
t.Errorf("incorrect item comparison")
|
||||
}
|
||||
was := b.next
|
||||
if was == b.increment().next {
|
||||
t.Errorf("increment didn't apply")
|
||||
}
|
||||
}
|
||||
|
||||
func Test_ItemCompare(t *testing.T) {
|
||||
cases := []struct {
|
||||
inter [2]time.Duration
|
||||
nexts [2]time.Time
|
||||
result int
|
||||
}{
|
||||
{
|
||||
nexts: [2]time.Time{time.Unix(0, 0), time.Unix(10, 10)},
|
||||
result: -1,
|
||||
},
|
||||
{
|
||||
nexts: [2]time.Time{time.Unix(10, 10), time.Unix(0, 0)},
|
||||
result: 1,
|
||||
},
|
||||
{
|
||||
nexts: [2]time.Time{time.Unix(10, 10), time.Unix(10, 10)},
|
||||
result: 0,
|
||||
},
|
||||
{
|
||||
nexts: [2]time.Time{time.Unix(0, 0), time.Unix(10, 10)},
|
||||
result: -1,
|
||||
},
|
||||
{
|
||||
inter: [2]time.Duration{time.Second, time.Minute},
|
||||
result: -1,
|
||||
},
|
||||
{
|
||||
inter: [2]time.Duration{time.Minute, time.Second},
|
||||
result: 1,
|
||||
},
|
||||
{
|
||||
inter: [2]time.Duration{time.Second, time.Second},
|
||||
result: 0,
|
||||
},
|
||||
}
|
||||
for _, c := range cases {
|
||||
comparison := (&Item{next: c.nexts[0], interval: c.inter[0]}).Compare(&Item{next: c.nexts[1], interval: c.inter[1]})
|
||||
if comparison != c.result {
|
||||
t.Errorf("failed to compare %v: got %v, expected %v", c.nexts, comparison, c.result)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user