clusterviz/cluster_mock.go

26 lines
8.2 KiB
Go
Raw Normal View History

2018-06-19 13:06:42 +00:00
package main
import (
"bytes"
2018-06-20 14:45:05 +00:00
"context"
2018-06-19 13:06:42 +00:00
)
// MockConsulSource implements ClusterSource for local
// mock of cluster service.
type MockConsulSource struct {
}
// NewMockConsulSource creates new mocked source for tests.
func NewMockConsulSource() ClusterSource {
return &MockConsulSource{}
}
// Node returns the list of mock nodes for the given datacentre 'dc' and tag.
// Satisfies ClusterSource interface.
2018-06-20 14:45:05 +00:00
func (c *MockConsulSource) IPs(ctx context.Context, dc, tag string) ([]string, error) {
2018-06-19 13:06:42 +00:00
r := bytes.NewBufferString(mockClusterIPsJSON)
2018-06-19 15:40:46 +00:00
return ParseConsulResponse(r)
2018-06-19 13:06:42 +00:00
}
const mockClusterIPsJSON = `[{"ID":"edaddefa-f894-703a-69db-6158dd56aa5a","Node":"mail-01.do-ams3.eth.beta","Address":"206.189.243.162","Datacenter":"do-ams3","TaggedAddresses":{"lan":"206.189.243.162","wan":"206.189.243.162"},"NodeMeta":{"consul-network-segment":"","env":"eth","stage":"beta"},"ServiceID":"statusd-mail-rpc-1","ServiceName":"statusd-rpc","ServiceTags":["eth.beta","statusd","mail","rpc"],"ServiceAddress":"10.1.0.13","ServiceMeta":{},"ServicePort":8546,"ServiceEnableTagOverride":true,"CreateIndex":719808,"ModifyIndex":719808},{"ID":"d62fa419-49f7-32e5-52f9-64478b4e104b","Node":"mail-02.do-ams3.eth.beta","Address":"206.189.243.169","Datacenter":"do-ams3","TaggedAddresses":{"lan":"206.189.243.169","wan":"206.189.243.169"},"NodeMeta":{"consul-network-segment":"","env":"eth","stage":"beta"},"ServiceID":"statusd-mail-rpc-1","ServiceName":"statusd-rpc","ServiceTags":["eth.beta","statusd","mail","rpc"],"ServiceAddress":"10.1.0.14","ServiceMeta":{},"ServicePort":8546,"ServiceEnableTagOverride":true,"CreateIndex":718197,"ModifyIndex":718197},{"ID":"ad5cbd92-b28e-d5fa-3e49-17674eb91de9","Node":"mail-03.do-ams3.eth.beta","Address":"206.189.243.168","Datacenter":"do-ams3","TaggedAddresses":{"lan":"206.189.243.168","wan":"206.189.243.168"},"NodeMeta":{"consul-network-segment":"","env":"eth","stage":"beta"},"ServiceID":"statusd-mail-rpc-1","ServiceName":"statusd-rpc","ServiceTags":["eth.beta","statusd","mail","rpc"],"ServiceAddress":"10.1.0.12","ServiceMeta":{},"ServicePort":8546,"ServiceEnableTagOverride":true,"CreateIndex":725592,"ModifyIndex":725592},{"ID":"3b6ae627-d8c2-c39a-0628-0792ad1c46e4","Node":"node-01.do-ams3.eth.beta","Address":"206.189.243.176","Datacenter":"do-ams3","TaggedAddresses":{"lan":"206.189.243.176","wan":"206.189.243.176"},"NodeMeta":{"consul-network-segment":"","env":"eth","stage":"beta"},"ServiceID":"statusd-whisper-rpc-1","ServiceName":"statusd-rpc","ServiceTags":["eth.beta","statusd","whisper","rpc"],"ServiceAddress":"10.1.1.99","ServiceMeta":{},"ServicePort":8546,"ServiceEnableTagOverride":true,"CreateIndex":719848,"ModifyIndex":719848},{"ID":"3b6ae627-d8c2-c39a-0628-0792ad1c46e4","Node":"node-01.do-ams3.eth.beta","Address":"206.189.243.176","Datacenter":"do-ams3","TaggedAddresses":{"lan":"206.189.243.176","wan":"206.189.243.176"},"NodeMeta":{"consul-network-segment":"","env":"eth","stage":"beta"},"ServiceID":"statusd-whisper-rpc-2","ServiceName":"statusd-rpc","ServiceTags":["eth.beta","statusd","whisper","rpc"],"ServiceAddress":"10.1.1.99","ServiceMeta":{},"ServicePort":8547,"ServiceEnableTagOverride":true,"CreateIndex":719849,"ModifyIndex":719849},{"ID":"79eacab7-006c-1a19-0bfd-046f874ec1ec","Node":"node-02.do-ams3.eth.beta","Address":"206.189.243.178","Datacenter":"do-ams3","TaggedAddresses":{"lan":"206.189.243.178","wan":"206.189.243.178"},"NodeMeta":{"consul-network-segment":"","env":"eth","stage":"beta"},"ServiceID":"statusd-whisper-rpc-1","ServiceName":"statusd-rpc","ServiceTags":["eth.beta","statusd","whisper","rpc"],"ServiceAddress":"10.1.0.9","ServiceMeta":{},"ServicePort":8546,"ServiceEnableTagOverride":true,"CreateIndex":718374,"ModifyIndex":718374},{"ID":"79eacab7-006c-1a19-0bfd-046f874ec1ec","Node":"node-02.do-ams3.eth.beta","Address":"206.189.243.178","Datacenter":"do-ams3","TaggedAddresses":{"lan":"206.189.243.178","wan":"206.189.243.178"},"NodeMeta":{"consul-network-segment":"","env":"eth","stage":"beta"},"ServiceID":"statusd-whisper-rpc-2","ServiceName":"statusd-rpc","ServiceTags":["eth.beta","statusd","whisper","rpc"],"ServiceAddress":"10.1.0.9","ServiceMeta":{},"ServicePort":8547,"ServiceEnableTagOverride":true,"CreateIndex":718375,"ModifyIndex":718375},{"ID":"dd349135-a34a-1452-b1ea-b00987d588f2","Node":"node-03.do-ams3.eth.beta","Address":"206.189.243.179","Datacenter":"do-ams3","TaggedAddresses":{"lan":"206.189.243.179","wan":"206.189.243.179"},"NodeMeta":{"consul-network-segment":"","env":"eth","stage":"beta"},"ServiceID":"statusd-whisper-rpc-1","ServiceName":"statusd-rpc","ServiceTags":["eth.beta","statusd","whisper","rpc"],"ServiceAddress":"10.1.0.6","ServiceMeta":