Add unit tests for state functions

Currently unit tests only succeed if the state path
is writeable, since it is hardcoded.
This commit is contained in:
kaiyou 2020-05-07 12:27:25 +02:00 committed by Leo Antunes
parent 13e1515f7d
commit 0162f9da2c
1 changed files with 32 additions and 0 deletions

32
cluster/state_test.go Normal file
View File

@ -0,0 +1,32 @@
package cluster
import (
"net"
"reflect"
"testing"
"github.com/costela/wesher/common"
)
func Test_State_Save_Load(t *testing.T) {
key := "abcdefghijklmnopqrstuvwxyzABCDEF"
node := common.Node{
Name: "node",
Addr: net.ParseIP("10.0.0.2"),
}
cluster := Cluster{
state: &State{
ClusterKey: []byte(key),
Nodes: []common.Node{node},
},
}
cluster.saveState()
loaded := &State{}
loadState(loaded)
if !reflect.DeepEqual(cluster.state, loaded) {
t.Errorf("cluster state save then reload mistmatch: %s / %s", cluster.state, loaded)
}
}