809344a6f5
- Add endpoints related to peering: read, list, generate token, initiate peering - Update node/service/check table indexing to account for peers - Foundational changes for pushing service updates to a peer - Plumb peer name through Health.ServiceNodes path see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679, ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663, ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634, ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555 Co-authored-by: R.B. Boyer <rb@hashicorp.com> Co-authored-by: freddygv <freddy@hashicorp.com> Co-authored-by: Chris S. Kim <ckim@hashicorp.com> Co-authored-by: Evan Culver <eculver@hashicorp.com> Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
64 lines
1.4 KiB
Go
64 lines
1.4 KiB
Go
package prepared_query
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
"sort"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
)
|
|
|
|
func TestWalk_ServiceQuery(t *testing.T) {
|
|
var actual []string
|
|
fn := func(path string, v reflect.Value) error {
|
|
actual = append(actual, fmt.Sprintf("%s:%s", path, v.String()))
|
|
return nil
|
|
}
|
|
|
|
service := &structs.ServiceQuery{
|
|
Service: "the-service",
|
|
Failover: structs.QueryDatacenterOptions{
|
|
Datacenters: []string{"dc1", "dc2"},
|
|
},
|
|
Near: "_agent",
|
|
Tags: []string{"tag1", "tag2", "tag3"},
|
|
NodeMeta: map[string]string{"foo": "bar", "role": "server"},
|
|
EnterpriseMeta: *structs.DefaultEnterpriseMetaInDefaultPartition(),
|
|
}
|
|
if err := walk(service, fn); err != nil {
|
|
t.Fatalf("err: %v", err)
|
|
}
|
|
|
|
expected := []string{
|
|
".Failover.Datacenters[0]:dc1",
|
|
".Failover.Datacenters[1]:dc2",
|
|
".Near:_agent",
|
|
".NodeMeta[foo]:bar",
|
|
".NodeMeta[role]:server",
|
|
".Service:the-service",
|
|
".Tags[0]:tag1",
|
|
".Tags[1]:tag2",
|
|
".Tags[2]:tag3",
|
|
".PeerName:",
|
|
}
|
|
expected = append(expected, entMetaWalkFields...)
|
|
sort.Strings(expected)
|
|
sort.Strings(actual)
|
|
require.Equal(t, expected, actual)
|
|
}
|
|
|
|
func TestWalk_Visitor_Errors(t *testing.T) {
|
|
fn := func(path string, v reflect.Value) error {
|
|
return fmt.Errorf("bad")
|
|
}
|
|
|
|
service := &structs.ServiceQuery{}
|
|
err := walk(service, fn)
|
|
if err == nil || err.Error() != "bad" {
|
|
t.Fatalf("bad: %#v", err)
|
|
}
|
|
}
|