mirror of
https://github.com/status-im/consul.git
synced 2025-02-03 09:24:25 +00:00
state: add tests for services table service and connect indexers
This commit is contained in:
parent
2d2c3e1190
commit
395ebce510
@ -1368,7 +1368,7 @@ func (s *Store) deleteServiceTxn(tx WriteTxn, idx uint64, nodeName, serviceID st
|
|||||||
return fmt.Errorf("failed to clean up mesh-topology associations for %q: %v", name.String(), err)
|
return fmt.Errorf("failed to clean up mesh-topology associations for %q: %v", name.String(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, remainingService, err := firstWatchWithTxn(tx, tableServices, "service", svc.ServiceName, entMeta); err == nil {
|
if _, remainingService, err := firstWatchWithTxn(tx, tableServices, indexService, svc.ServiceName, entMeta); err == nil {
|
||||||
if remainingService != nil {
|
if remainingService != nil {
|
||||||
// We have at least one remaining service, update the index
|
// We have at least one remaining service, update the index
|
||||||
if err := catalogUpdateServiceIndexes(tx, svc.ServiceName, idx, entMeta); err != nil {
|
if err := catalogUpdateServiceIndexes(tx, svc.ServiceName, idx, entMeta); err != nil {
|
||||||
|
@ -168,6 +168,12 @@ func testIndexerTableNodes() map[string]indexerTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testIndexerTableServices() map[string]indexerTestCase {
|
func testIndexerTableServices() map[string]indexerTestCase {
|
||||||
|
obj := &structs.ServiceNode{
|
||||||
|
Node: "NoDeId",
|
||||||
|
ServiceID: "SeRviCe",
|
||||||
|
ServiceName: "ServiceName",
|
||||||
|
}
|
||||||
|
|
||||||
return map[string]indexerTestCase{
|
return map[string]indexerTestCase{
|
||||||
indexID: {
|
indexID: {
|
||||||
read: indexValue{
|
read: indexValue{
|
||||||
@ -178,10 +184,7 @@ func testIndexerTableServices() map[string]indexerTestCase {
|
|||||||
expected: []byte("nodeid\x00service\x00"),
|
expected: []byte("nodeid\x00service\x00"),
|
||||||
},
|
},
|
||||||
write: indexValue{
|
write: indexValue{
|
||||||
source: &structs.ServiceNode{
|
source: obj,
|
||||||
Node: "NoDeId",
|
|
||||||
ServiceID: "SeRviCe",
|
|
||||||
},
|
|
||||||
expected: []byte("nodeid\x00service\x00"),
|
expected: []byte("nodeid\x00service\x00"),
|
||||||
},
|
},
|
||||||
prefix: []indexValue{
|
prefix: []indexValue{
|
||||||
@ -202,16 +205,36 @@ func testIndexerTableServices() map[string]indexerTestCase {
|
|||||||
indexNode: {
|
indexNode: {
|
||||||
read: indexValue{
|
read: indexValue{
|
||||||
source: Query{
|
source: Query{
|
||||||
Value: "NoDe",
|
Value: "NoDeId",
|
||||||
},
|
},
|
||||||
expected: []byte("node\x00"),
|
expected: []byte("nodeid\x00"),
|
||||||
|
},
|
||||||
|
write: indexValue{
|
||||||
|
source: obj,
|
||||||
|
expected: []byte("nodeid\x00"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
indexService: {
|
||||||
|
read: indexValue{
|
||||||
|
source: "ServiceName",
|
||||||
|
expected: []byte("servicename\x00"),
|
||||||
|
},
|
||||||
|
write: indexValue{
|
||||||
|
source: obj,
|
||||||
|
expected: []byte("servicename\x00"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
indexConnect: {
|
||||||
|
read: indexValue{
|
||||||
|
source: Query{Value: "ConnectName"},
|
||||||
|
expected: []byte("connectname\x00"),
|
||||||
},
|
},
|
||||||
write: indexValue{
|
write: indexValue{
|
||||||
source: &structs.ServiceNode{
|
source: &structs.ServiceNode{
|
||||||
Node: "NoDe",
|
ServiceName: "ConnectName",
|
||||||
ServiceID: "SeRvIcE",
|
ServiceConnect: structs.ServiceConnect{Native: true},
|
||||||
},
|
},
|
||||||
expected: []byte("node\x00"),
|
expected: []byte("connectname\x00"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ func updateUsage(tx WriteTxn, changes Changes) error {
|
|||||||
func updateServiceNameUsage(tx WriteTxn, usageDeltas map[string]int, serviceNameChanges map[structs.ServiceName]int) (map[structs.ServiceName]uniqueServiceState, error) {
|
func updateServiceNameUsage(tx WriteTxn, usageDeltas map[string]int, serviceNameChanges map[structs.ServiceName]int) (map[structs.ServiceName]uniqueServiceState, error) {
|
||||||
serviceStates := make(map[structs.ServiceName]uniqueServiceState, len(serviceNameChanges))
|
serviceStates := make(map[structs.ServiceName]uniqueServiceState, len(serviceNameChanges))
|
||||||
for svc, delta := range serviceNameChanges {
|
for svc, delta := range serviceNameChanges {
|
||||||
serviceIter, err := getWithTxn(tx, tableServices, "service", svc.Name, &svc.EnterpriseMeta)
|
serviceIter, err := getWithTxn(tx, tableServices, indexService, svc.Name, &svc.EnterpriseMeta)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user