2021-02-19 19:38:07 +00:00
|
|
|
// +build !consulent
|
|
|
|
|
|
|
|
package state
|
|
|
|
|
2021-03-22 21:29:58 +00:00
|
|
|
import (
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
|
|
)
|
2021-02-19 19:38:07 +00:00
|
|
|
|
|
|
|
func testIndexerTableChecks() map[string]indexerTestCase {
|
2021-03-22 21:29:58 +00:00
|
|
|
obj := &structs.HealthCheck{
|
2021-03-29 20:07:49 +00:00
|
|
|
Node: "NoDe",
|
|
|
|
ServiceID: "SeRvIcE",
|
|
|
|
ServiceName: "ServiceName",
|
|
|
|
CheckID: "CheckID",
|
|
|
|
Status: "PASSING",
|
2021-03-22 21:29:58 +00:00
|
|
|
}
|
2021-02-19 19:38:07 +00:00
|
|
|
return map[string]indexerTestCase{
|
2021-03-22 21:29:58 +00:00
|
|
|
indexID: {
|
|
|
|
read: indexValue{
|
|
|
|
source: NodeCheckQuery{
|
|
|
|
Node: "NoDe",
|
|
|
|
CheckID: "CheckId",
|
|
|
|
},
|
|
|
|
expected: []byte("node\x00checkid\x00"),
|
|
|
|
},
|
|
|
|
write: indexValue{
|
|
|
|
source: obj,
|
|
|
|
expected: []byte("node\x00checkid\x00"),
|
|
|
|
},
|
|
|
|
prefix: []indexValue{
|
|
|
|
{
|
|
|
|
source: structs.EnterpriseMeta{},
|
|
|
|
expected: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
source: Query{Value: "nOdE"},
|
|
|
|
expected: []byte("node\x00"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-03-29 20:07:49 +00:00
|
|
|
indexStatus: {
|
|
|
|
read: indexValue{
|
2021-03-29 20:29:04 +00:00
|
|
|
source: Query{Value: "PASSING"},
|
|
|
|
expected: []byte("passing\x00"),
|
2021-03-29 20:07:49 +00:00
|
|
|
},
|
|
|
|
write: indexValue{
|
|
|
|
source: obj,
|
2021-03-29 20:29:04 +00:00
|
|
|
expected: []byte("passing\x00"),
|
2021-03-29 20:07:49 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
indexService: {
|
|
|
|
read: indexValue{
|
2021-03-29 20:37:37 +00:00
|
|
|
source: Query{Value: "ServiceName"},
|
2021-03-29 20:07:49 +00:00
|
|
|
expected: []byte("servicename\x00"),
|
|
|
|
},
|
|
|
|
write: indexValue{
|
|
|
|
source: obj,
|
|
|
|
expected: []byte("servicename\x00"),
|
|
|
|
},
|
|
|
|
},
|
2021-02-19 19:38:07 +00:00
|
|
|
indexNodeService: {
|
|
|
|
read: indexValue{
|
|
|
|
source: NodeServiceQuery{
|
|
|
|
Node: "NoDe",
|
|
|
|
Service: "SeRvIcE",
|
|
|
|
},
|
|
|
|
expected: []byte("node\x00service\x00"),
|
|
|
|
},
|
|
|
|
write: indexValue{
|
2021-03-22 21:29:58 +00:00
|
|
|
source: obj,
|
2021-02-19 19:38:07 +00:00
|
|
|
expected: []byte("node\x00service\x00"),
|
|
|
|
},
|
|
|
|
},
|
2021-02-12 22:31:02 +00:00
|
|
|
indexNode: {
|
|
|
|
read: indexValue{
|
|
|
|
source: Query{
|
|
|
|
Value: "NoDe",
|
|
|
|
},
|
|
|
|
expected: []byte("node\x00"),
|
|
|
|
},
|
|
|
|
write: indexValue{
|
2021-03-22 21:29:58 +00:00
|
|
|
source: obj,
|
2021-02-12 22:31:02 +00:00
|
|
|
expected: []byte("node\x00"),
|
|
|
|
},
|
|
|
|
},
|
2021-02-19 19:38:07 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-19 23:18:25 +00:00
|
|
|
|
2021-03-16 17:30:07 +00:00
|
|
|
func testIndexerTableMeshTopology() map[string]indexerTestCase {
|
2021-03-16 17:37:44 +00:00
|
|
|
obj := upstreamDownstream{
|
2021-03-16 17:30:07 +00:00
|
|
|
Upstream: structs.ServiceName{Name: "UpStReAm"},
|
|
|
|
Downstream: structs.ServiceName{Name: "DownStream"},
|
|
|
|
}
|
|
|
|
|
|
|
|
return map[string]indexerTestCase{
|
|
|
|
indexID: {
|
|
|
|
read: indexValue{
|
|
|
|
source: []interface{}{
|
|
|
|
structs.ServiceName{Name: "UpStReAm"},
|
|
|
|
structs.ServiceName{Name: "DownStream"},
|
|
|
|
},
|
|
|
|
expected: []byte("upstream\x00downstream\x00"),
|
|
|
|
},
|
|
|
|
write: indexValue{
|
|
|
|
source: obj,
|
|
|
|
expected: []byte("upstream\x00downstream\x00"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
indexUpstream: {
|
|
|
|
read: indexValue{
|
2021-03-16 18:20:11 +00:00
|
|
|
source: structs.ServiceName{Name: "UpStReAm"},
|
2021-03-16 17:30:07 +00:00
|
|
|
expected: []byte("upstream\x00"),
|
|
|
|
},
|
|
|
|
write: indexValue{
|
|
|
|
source: obj,
|
|
|
|
expected: []byte("upstream\x00"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
indexDownstream: {
|
|
|
|
read: indexValue{
|
2021-03-16 18:20:11 +00:00
|
|
|
source: structs.ServiceName{Name: "DownStream"},
|
2021-03-16 17:30:07 +00:00
|
|
|
expected: []byte("downstream\x00"),
|
|
|
|
},
|
|
|
|
write: indexValue{
|
|
|
|
source: obj,
|
|
|
|
expected: []byte("downstream\x00"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-16 18:20:11 +00:00
|
|
|
func testIndexerTableGatewayServices() map[string]indexerTestCase {
|
|
|
|
obj := &structs.GatewayService{
|
|
|
|
Gateway: structs.ServiceName{Name: "GateWay"},
|
|
|
|
Service: structs.ServiceName{Name: "SerVice"},
|
|
|
|
Port: 50123,
|
|
|
|
}
|
|
|
|
encodedPort := string([]byte{0x96, 0x8f, 0x06, 0, 0, 0, 0, 0, 0, 0})
|
|
|
|
return map[string]indexerTestCase{
|
|
|
|
indexID: {
|
|
|
|
read: indexValue{
|
|
|
|
source: []interface{}{
|
|
|
|
structs.ServiceName{Name: "GateWay"},
|
|
|
|
structs.ServiceName{Name: "SerVice"},
|
|
|
|
50123,
|
|
|
|
},
|
|
|
|
expected: []byte("gateway\x00service\x00" + encodedPort),
|
|
|
|
},
|
|
|
|
write: indexValue{
|
|
|
|
source: obj,
|
|
|
|
expected: []byte("gateway\x00service\x00" + encodedPort),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
indexGateway: {
|
|
|
|
read: indexValue{
|
|
|
|
source: structs.ServiceName{Name: "GateWay"},
|
|
|
|
expected: []byte("gateway\x00"),
|
|
|
|
},
|
|
|
|
write: indexValue{
|
|
|
|
source: obj,
|
|
|
|
expected: []byte("gateway\x00"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
indexService: {
|
|
|
|
read: indexValue{
|
|
|
|
source: structs.ServiceName{Name: "SerVice"},
|
|
|
|
expected: []byte("service\x00"),
|
|
|
|
},
|
|
|
|
write: indexValue{
|
|
|
|
source: obj,
|
|
|
|
expected: []byte("service\x00"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-19 23:18:25 +00:00
|
|
|
func testIndexerTableNodes() map[string]indexerTestCase {
|
|
|
|
return map[string]indexerTestCase{
|
|
|
|
indexID: {
|
|
|
|
read: indexValue{
|
|
|
|
source: Query{Value: "NoDeId"},
|
|
|
|
expected: []byte("nodeid\x00"),
|
|
|
|
},
|
|
|
|
write: indexValue{
|
|
|
|
source: &structs.Node{Node: "NoDeId"},
|
|
|
|
expected: []byte("nodeid\x00"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2021-02-12 22:31:02 +00:00
|
|
|
|
|
|
|
func testIndexerTableServices() map[string]indexerTestCase {
|
2021-03-26 20:11:03 +00:00
|
|
|
obj := &structs.ServiceNode{
|
|
|
|
Node: "NoDeId",
|
|
|
|
ServiceID: "SeRviCe",
|
|
|
|
ServiceName: "ServiceName",
|
|
|
|
}
|
|
|
|
|
2021-02-12 22:31:02 +00:00
|
|
|
return map[string]indexerTestCase{
|
2021-03-10 23:34:19 +00:00
|
|
|
indexID: {
|
|
|
|
read: indexValue{
|
|
|
|
source: NodeServiceQuery{
|
|
|
|
Node: "NoDeId",
|
|
|
|
Service: "SeRvIcE",
|
|
|
|
},
|
|
|
|
expected: []byte("nodeid\x00service\x00"),
|
|
|
|
},
|
|
|
|
write: indexValue{
|
2021-03-26 20:11:03 +00:00
|
|
|
source: obj,
|
2021-03-10 23:34:19 +00:00
|
|
|
expected: []byte("nodeid\x00service\x00"),
|
|
|
|
},
|
|
|
|
prefix: []indexValue{
|
|
|
|
{
|
|
|
|
source: (*structs.EnterpriseMeta)(nil),
|
|
|
|
expected: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
source: structs.EnterpriseMeta{},
|
|
|
|
expected: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
source: Query{Value: "NoDeId"},
|
|
|
|
expected: []byte("nodeid\x00"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-02-12 22:31:02 +00:00
|
|
|
indexNode: {
|
|
|
|
read: indexValue{
|
|
|
|
source: Query{
|
2021-03-26 20:11:03 +00:00
|
|
|
Value: "NoDeId",
|
2021-02-12 22:31:02 +00:00
|
|
|
},
|
2021-03-26 20:11:03 +00:00
|
|
|
expected: []byte("nodeid\x00"),
|
|
|
|
},
|
|
|
|
write: indexValue{
|
|
|
|
source: obj,
|
|
|
|
expected: []byte("nodeid\x00"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
indexService: {
|
|
|
|
read: indexValue{
|
2021-03-26 21:21:38 +00:00
|
|
|
source: Query{Value: "ServiceName"},
|
2021-03-26 20:11:03 +00:00
|
|
|
expected: []byte("servicename\x00"),
|
|
|
|
},
|
|
|
|
write: indexValue{
|
|
|
|
source: obj,
|
|
|
|
expected: []byte("servicename\x00"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
indexConnect: {
|
|
|
|
read: indexValue{
|
|
|
|
source: Query{Value: "ConnectName"},
|
|
|
|
expected: []byte("connectname\x00"),
|
2021-02-12 22:31:02 +00:00
|
|
|
},
|
|
|
|
write: indexValue{
|
|
|
|
source: &structs.ServiceNode{
|
2021-03-26 20:11:03 +00:00
|
|
|
ServiceName: "ConnectName",
|
|
|
|
ServiceConnect: structs.ServiceConnect{Native: true},
|
2021-02-12 22:31:02 +00:00
|
|
|
},
|
2021-03-26 20:11:03 +00:00
|
|
|
expected: []byte("connectname\x00"),
|
2021-02-12 22:31:02 +00:00
|
|
|
},
|
2021-03-31 18:37:21 +00:00
|
|
|
extra: []indexerTestCase{
|
|
|
|
{
|
|
|
|
write: indexValue{
|
|
|
|
source: &structs.ServiceNode{
|
|
|
|
ServiceName: "ServiceName",
|
|
|
|
ServiceKind: structs.ServiceKindConnectProxy,
|
|
|
|
ServiceProxy: structs.ConnectProxyConfig{
|
|
|
|
DestinationServiceName: "ConnectName",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
expected: []byte("connectname\x00"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
write: indexValue{
|
|
|
|
source: &structs.ServiceNode{ServiceName: "ServiceName"},
|
|
|
|
expectedIndexMissing: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
write: indexValue{
|
|
|
|
source: &structs.ServiceNode{
|
|
|
|
ServiceName: "ServiceName",
|
|
|
|
ServiceKind: structs.ServiceKindTerminatingGateway,
|
|
|
|
},
|
|
|
|
expectedIndexMissing: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-02-12 22:31:02 +00:00
|
|
|
},
|
2021-03-26 22:11:41 +00:00
|
|
|
indexKind: {
|
|
|
|
read: indexValue{
|
2021-03-26 22:38:52 +00:00
|
|
|
source: Query{Value: "connect-proxy"},
|
2021-03-26 22:11:41 +00:00
|
|
|
expected: []byte("connect-proxy\x00"),
|
|
|
|
},
|
|
|
|
write: indexValue{
|
|
|
|
source: &structs.ServiceNode{
|
|
|
|
ServiceKind: structs.ServiceKindConnectProxy,
|
|
|
|
},
|
|
|
|
expected: []byte("connect-proxy\x00"),
|
|
|
|
},
|
2021-03-31 18:37:21 +00:00
|
|
|
extra: []indexerTestCase{
|
|
|
|
{
|
|
|
|
write: indexValue{
|
|
|
|
source: &structs.ServiceNode{
|
|
|
|
ServiceName: "ServiceName",
|
|
|
|
ServiceKind: structs.ServiceKindTypical,
|
|
|
|
},
|
|
|
|
expected: []byte("\x00"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-03-26 22:11:41 +00:00
|
|
|
},
|
2021-02-12 22:31:02 +00:00
|
|
|
}
|
|
|
|
}
|