Files
wesher/cluster/state_test.go
kaiyou 0162f9da2c Add unit tests for state functions
Currently unit tests only succeed if the state path
is writeable, since it is hardcoded.
2020-05-13 13:52:54 +02:00

33 lines
567 B
Go

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)
}
}