2020-05-07 12:27:25 +02:00
|
|
|
package cluster
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/costela/wesher/common"
|
|
|
|
)
|
|
|
|
|
2020-05-10 16:48:20 +02:00
|
|
|
func Test_state_save_soad(t *testing.T) {
|
2020-05-13 10:45:16 +02:00
|
|
|
statePath = "/tmp/wesher.json"
|
2020-05-07 12:27:25 +02:00
|
|
|
key := "abcdefghijklmnopqrstuvwxyzABCDEF"
|
|
|
|
node := common.Node{
|
|
|
|
Name: "node",
|
|
|
|
Addr: net.ParseIP("10.0.0.2"),
|
|
|
|
}
|
|
|
|
|
|
|
|
cluster := Cluster{
|
2020-05-10 16:48:20 +02:00
|
|
|
state: &state{
|
2020-05-07 12:27:25 +02:00
|
|
|
ClusterKey: []byte(key),
|
|
|
|
Nodes: []common.Node{node},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-05-13 10:42:37 +02:00
|
|
|
if err := cluster.state.save(); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2020-05-10 16:48:20 +02:00
|
|
|
loaded := &state{}
|
2020-05-07 12:27:25 +02:00
|
|
|
loadState(loaded)
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(cluster.state, loaded) {
|
|
|
|
t.Errorf("cluster state save then reload mistmatch: %s / %s", cluster.state, loaded)
|
|
|
|
}
|
|
|
|
}
|