state: add tests for mesh-topology table indexers

This commit is contained in:
Daniel Nephin 2021-03-16 13:30:07 -04:00
parent c749c6c927
commit 65f5b99247
3 changed files with 47 additions and 0 deletions

View File

@ -40,6 +40,51 @@ func testIndexerTableChecks() map[string]indexerTestCase {
} }
} }
func testIndexerTableMeshTopology() map[string]indexerTestCase {
obj := structs.UpstreamDownstream{
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{
source: structs.ServiceName{Name: "UpStReAm"},
expected: []byte("upstream\x00"),
},
write: indexValue{
source: obj,
expected: []byte("upstream\x00"),
},
},
indexDownstream: {
read: indexValue{
source: structs.ServiceName{Name: "DownStream"},
expected: []byte("downstream\x00"),
},
write: indexValue{
source: obj,
expected: []byte("downstream\x00"),
},
},
}
}
func testIndexerTableNodes() map[string]indexerTestCase { func testIndexerTableNodes() map[string]indexerTestCase {
return map[string]indexerTestCase{ return map[string]indexerTestCase{
indexID: { indexID: {

View File

@ -132,6 +132,7 @@ func TestNewDBSchema_Indexers(t *testing.T) {
tableServices: testIndexerTableServices, tableServices: testIndexerTableServices,
tableNodes: testIndexerTableNodes, tableNodes: testIndexerTableNodes,
tableConfigEntries: testIndexerTableConfigEntries, tableConfigEntries: testIndexerTableConfigEntries,
tableMeshTopology: testIndexerTableMeshTopology,
} }
for _, table := range schema.Tables { for _, table := range schema.Tables {

View File

@ -2476,6 +2476,7 @@ func (m MessageType) String() string {
} }
// UpstreamDownstream pairs come from individual proxy registrations, which can be updated independently. // UpstreamDownstream pairs come from individual proxy registrations, which can be updated independently.
// TODO: move to state package
type UpstreamDownstream struct { type UpstreamDownstream struct {
Upstream ServiceName Upstream ServiceName
Downstream ServiceName Downstream ServiceName