本文整理汇总了Golang中github.com/tsuru/docker-cluster/cluster.Storage.RetrieveNodes方法的典型用法代码示例。如果您正苦于以下问题:Golang Storage.RetrieveNodes方法的具体用法?Golang Storage.RetrieveNodes怎么用?Golang Storage.RetrieveNodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/tsuru/docker-cluster/cluster.Storage
的用法示例。
在下文中一共展示了Storage.RetrieveNodes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: testStorageStoreRetrieveNodes
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)
}
}
示例2: testStorageStoreEmptyMetadata
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)
}
}
示例3: testStorageStoreRemoveNode
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)
}
}
示例4: testStorageStoreClearMetadata
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)
}
}