Ejemplo n.º 1
0
func testStorageStoreRetrieveNodes(storage cluster.Storage, t *testing.T) {
	node1 := cluster.Node{Address: "my-addr-1"}
	defer storage.RemoveNode("my-addr-1")
	err := storage.StoreNode(node1)
	assertIsNil(err, t)
	node2 := cluster.Node{Address: "my-addr-2", Metadata: map[string]string{"foo": "bar"}}
	defer storage.RemoveNode("my-addr-2")
	err = storage.StoreNode(node2)
	assertIsNil(err, t)
	nodes, err := storage.RetrieveNodes()
	assertIsNil(err, t)
	if len(nodes) != 2 {
		t.Fatalf("unexpected number of nodes, expected 2, got: %d", len(nodes))
	}
	sort.Sort(cluster.NodeList(nodes))
	if nodes[0].Address != node1.Address || nodes[1].Address != node2.Address {
		t.Errorf("unexpected nodes: %#v", nodes)
	}
	if !reflect.DeepEqual(node2.Metadata, nodes[1].Metadata) {
		t.Errorf("unexpected node metadata. expected: %#v got: %#v", node2.Metadata, nodes[1].Metadata)
	}
	if !reflect.DeepEqual(nodes[0].Metadata, map[string]string{}) {
		t.Errorf("unexpected node metadata. expected empty map got: %#v", nodes[0].Metadata)
	}
}
Ejemplo n.º 2
0
func testStorageStoreEmptyMetadata(storage cluster.Storage, t *testing.T) {
	defer storage.RemoveNode("my-addr-1")
	node1 := cluster.Node{Address: "my-addr-1", Metadata: map[string]string{}}
	err := storage.StoreNode(node1)
	assertIsNil(err, t)
	nodes, err := storage.RetrieveNodes()
	assertIsNil(err, t)
	if len(nodes) != 1 || nodes[0].Address != node1.Address {
		t.Errorf("unexpected nodes: %#v", nodes)
	}
}
Ejemplo n.º 3
0
func testStorageStoreRemoveNode(storage cluster.Storage, t *testing.T) {
	node1 := cluster.Node{Address: "my-addr-1"}
	err := storage.StoreNode(node1)
	assertIsNil(err, t)
	err = storage.RemoveNode("my-addr-1")
	assertIsNil(err, t)
	err = storage.RemoveNode("my-addr-1")
	if err != cstorage.ErrNoSuchNode {
		t.Errorf("cstorage.ErrNoSuchNode was expected, got: %s", err)
	}
	nodes, err := storage.RetrieveNodes()
	assertIsNil(err, t)
	if len(nodes) > 0 {
		t.Errorf("nodes should be empty, found: %#v", nodes)
	}
}
Ejemplo n.º 4
0
func testStorageStoreClearMetadata(storage cluster.Storage, t *testing.T) {
	defer storage.RemoveNode("my-addr-1")
	err := storage.StoreNode(cluster.Node{Address: "my-addr-1", Metadata: map[string]string{"pool": "p1"}})
	assertIsNil(err, t)
	err = storage.RemoveNode("my-addr-1")
	assertIsNil(err, t)
	err = storage.StoreNode(cluster.Node{Address: "my-addr-1"})
	assertIsNil(err, t)
	nodes, err := storage.RetrieveNodes()
	assertIsNil(err, t)
	if len(nodes) != 1 || nodes[0].Address != "my-addr-1" {
		t.Errorf("unexpected nodes: %#v", nodes)
	}
	if !reflect.DeepEqual(nodes[0].Metadata, map[string]string{}) {
		t.Errorf("unexpected node metadata. expected empty map, got: %#v", nodes[0].Metadata)
	}
}