2017-05-07 03:37:30 +02:00
|
|
|
package runtime
|
|
|
|
|
|
|
|
import (
|
2018-06-30 01:45:51 +02:00
|
|
|
"net"
|
2017-05-07 03:37:30 +02:00
|
|
|
"testing"
|
2019-06-05 23:39:13 +02:00
|
|
|
"time"
|
2017-05-07 03:37:30 +02:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2018-06-30 01:45:51 +02:00
|
|
|
yanicData "github.com/FreifunkBremen/yanic/data"
|
2017-05-07 03:37:30 +02:00
|
|
|
yanicRuntime "github.com/FreifunkBremen/yanic/runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNode(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
2018-06-30 01:45:51 +02:00
|
|
|
node1 := &yanicRuntime.Node{
|
|
|
|
Address: &net.UDPAddr{IP: net.ParseIP("ff02::1")},
|
|
|
|
}
|
2018-07-24 15:07:11 +02:00
|
|
|
n1 := NewNode(node1, "")
|
2017-05-07 03:37:30 +02:00
|
|
|
assert.Nil(n1)
|
|
|
|
|
2019-06-03 16:26:53 +02:00
|
|
|
node1.Nodeinfo = &yanicData.Nodeinfo{
|
2018-06-30 01:45:51 +02:00
|
|
|
Owner: &yanicData.Owner{Contact: "blub"},
|
|
|
|
Wireless: &yanicData.Wireless{},
|
|
|
|
Location: &yanicData.Location{Altitude: 13},
|
2017-05-07 03:37:30 +02:00
|
|
|
}
|
2018-07-24 15:07:11 +02:00
|
|
|
n1 = NewNode(node1, "")
|
2017-05-07 03:37:30 +02:00
|
|
|
assert.NotNil(n1)
|
|
|
|
assert.Equal(float64(13), n1.Location.Altitude)
|
|
|
|
|
2018-08-10 13:46:18 +02:00
|
|
|
assert.True(n1.CheckRespondd())
|
2017-05-07 03:37:30 +02:00
|
|
|
|
|
|
|
node1.Nodeinfo.Owner.Contact = "blub2"
|
2018-08-10 13:46:18 +02:00
|
|
|
n1.Update(node1, "")
|
|
|
|
assert.False(n1.CheckRespondd())
|
2017-05-07 03:37:30 +02:00
|
|
|
}
|
2019-06-05 23:39:13 +02:00
|
|
|
|
|
|
|
func TestNodeTimeFilter(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
d := time.Minute
|
|
|
|
now := time.Now()
|
|
|
|
before := now.Add(-time.Second)
|
|
|
|
after := before.Add(-d)
|
|
|
|
|
|
|
|
node := Node{}
|
|
|
|
|
|
|
|
node.Lastseen = nil
|
|
|
|
node.Blacklist = nil
|
|
|
|
assert.True(node.TimeFilter(d))
|
|
|
|
|
|
|
|
node.Lastseen = &after
|
|
|
|
node.Blacklist = nil
|
|
|
|
assert.True(node.TimeFilter(d))
|
|
|
|
|
|
|
|
node.Lastseen = &before
|
|
|
|
node.Blacklist = nil
|
|
|
|
assert.False(node.TimeFilter(d))
|
|
|
|
|
|
|
|
node.Lastseen = nil
|
|
|
|
node.Blacklist = &after
|
|
|
|
assert.True(node.TimeFilter(d))
|
|
|
|
|
|
|
|
node.Lastseen = &after
|
|
|
|
node.Blacklist = &after
|
|
|
|
assert.True(node.TimeFilter(d))
|
|
|
|
|
|
|
|
node.Lastseen = &before
|
|
|
|
node.Blacklist = &after
|
|
|
|
assert.False(node.TimeFilter(d))
|
|
|
|
|
|
|
|
node.Lastseen = nil
|
|
|
|
node.Blacklist = &before
|
|
|
|
assert.True(node.TimeFilter(d))
|
|
|
|
|
|
|
|
node.Lastseen = &after
|
|
|
|
node.Blacklist = &before
|
|
|
|
assert.True(node.TimeFilter(d))
|
|
|
|
|
|
|
|
node.Lastseen = &before
|
|
|
|
node.Blacklist = &before
|
|
|
|
assert.True(node.TimeFilter(d))
|
|
|
|
}
|