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-15 10:17:11 +02:00
|
|
|
defaultStatePath = "/tmp/%s.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-15 10:17:11 +02:00
|
|
|
if err := cluster.state.save("test"); err != nil {
|
2020-05-13 10:42:37 +02:00
|
|
|
t.Error(err)
|
|
|
|
}
|
2020-05-10 16:48:20 +02:00
|
|
|
loaded := &state{}
|
2020-05-15 10:17:11 +02:00
|
|
|
loadState(loaded, "test")
|
2020-05-07 12:27:25 +02:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(cluster.state, loaded) {
|
|
|
|
t.Errorf("cluster state save then reload mistmatch: %s / %s", cluster.state, loaded)
|
|
|
|
}
|
|
|
|
}
|