Add test for node expiration
This commit is contained in:
parent
e9420828a2
commit
997735ffce
@ -4,11 +4,45 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/FreifunkBremen/respond-collector/data"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestExpire(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
config := &Config{}
|
||||
config.Nodes.MaxAge = 6
|
||||
nodes := &Nodes{
|
||||
config: config,
|
||||
List: make(map[string]*Node),
|
||||
}
|
||||
|
||||
nodes.Update("expire", &data.ResponseData{}) // should expire
|
||||
nodes.Update("offline", &data.ResponseData{}) // should become offline
|
||||
nodes.Update("online", &data.ResponseData{}) // should stay online
|
||||
|
||||
expire := nodes.List["expire"]
|
||||
expire.Lastseen = expire.Lastseen.Add((-6 * time.Hour * 24) - time.Minute)
|
||||
offline := nodes.List["offline"]
|
||||
offline.Lastseen = offline.Lastseen.Add((-6 * time.Hour * 24) + time.Minute)
|
||||
|
||||
nodes.expire()
|
||||
|
||||
// one expired?
|
||||
assert.Equal(2, len(nodes.List))
|
||||
assert.Nil(nodes.List["expire"])
|
||||
|
||||
// one offline?
|
||||
assert.NotNil(nodes.List["offline"])
|
||||
assert.False(nodes.List["offline"].Flags.Online)
|
||||
|
||||
// one online?
|
||||
assert.NotNil(nodes.List["online"])
|
||||
assert.True(nodes.List["online"].Flags.Online)
|
||||
}
|
||||
|
||||
func TestLoadAndSave(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user