fix(api): OSS<->ENT exported service incompatibility

This commit is contained in:
DanStough 2022-08-31 17:15:32 -04:00 committed by Dan Stough
parent ecc43db774
commit 08f7e52d82
10 changed files with 63 additions and 63 deletions

View File

@ -363,7 +363,7 @@ func TestAPI_AgentServicesWithFilterOpts(t *testing.T) {
}
require.NoError(t, agent.ServiceRegister(reg))
opts := &QueryOptions{Namespace: splitDefaultNamespace}
opts := &QueryOptions{Namespace: defaultNamespace}
services, err := agent.ServicesWithFilterOpts("foo in Tags", opts)
require.NoError(t, err)
require.Len(t, services, 1)
@ -791,8 +791,8 @@ func TestAPI_AgentService(t *testing.T) {
Warning: 1,
},
Meta: map[string]string{},
Namespace: splitDefaultNamespace,
Partition: splitDefaultPartition,
Namespace: defaultNamespace,
Partition: defaultPartition,
Datacenter: "dc1",
}
require.Equal(t, expect, got)
@ -932,7 +932,7 @@ func TestAPI_AgentUpdateTTLOpts(t *testing.T) {
}
}
opts := &QueryOptions{Namespace: splitDefaultNamespace}
opts := &QueryOptions{Namespace: defaultNamespace}
if err := agent.UpdateTTLOpts("service:foo", "foo", HealthWarning, opts); err != nil {
t.Fatalf("err: %v", err)
@ -1007,7 +1007,7 @@ func TestAPI_AgentChecksWithFilterOpts(t *testing.T) {
reg.TTL = "15s"
require.NoError(t, agent.CheckRegister(reg))
opts := &QueryOptions{Namespace: splitDefaultNamespace}
opts := &QueryOptions{Namespace: defaultNamespace}
checks, err := agent.ChecksWithFilterOpts("Name == foo", opts)
require.NoError(t, err)
require.Len(t, checks, 1)
@ -1382,7 +1382,7 @@ func TestAPI_ServiceMaintenanceOpts(t *testing.T) {
}
// Specify namespace in query option
opts := &QueryOptions{Namespace: splitDefaultNamespace}
opts := &QueryOptions{Namespace: defaultNamespace}
// Enable maintenance mode
if err := agent.EnableServiceMaintenanceOpts("redis", "broken", opts); err != nil {
@ -1701,7 +1701,7 @@ func TestAPI_AgentHealthServiceOpts(t *testing.T) {
requireServiceHealthID := func(t *testing.T, serviceID, expected string, shouldExist bool) {
msg := fmt.Sprintf("service id:%s, shouldExist:%v, expectedStatus:%s : bad %%s", serviceID, shouldExist, expected)
opts := &QueryOptions{Namespace: splitDefaultNamespace}
opts := &QueryOptions{Namespace: defaultNamespace}
state, out, err := agent.AgentHealthServiceByIDOpts(serviceID, opts)
require.Nil(t, err, msg, "err")
require.Equal(t, expected, state, msg, "state")
@ -1715,7 +1715,7 @@ func TestAPI_AgentHealthServiceOpts(t *testing.T) {
requireServiceHealthName := func(t *testing.T, serviceName, expected string, shouldExist bool) {
msg := fmt.Sprintf("service name:%s, shouldExist:%v, expectedStatus:%s : bad %%s", serviceName, shouldExist, expected)
opts := &QueryOptions{Namespace: splitDefaultNamespace}
opts := &QueryOptions{Namespace: defaultNamespace}
state, outs, err := agent.AgentHealthServiceByNameOpts(serviceName, opts)
require.Nil(t, err, msg, "err")
require.Equal(t, expected, state, msg, "state")

View File

@ -51,7 +51,7 @@ func TestAPI_CatalogNodes(t *testing.T) {
want := &Node{
ID: s.Config.NodeID,
Node: s.Config.NodeName,
Partition: splitDefaultPartition,
Partition: defaultPartition,
Address: "127.0.0.1",
Datacenter: "dc1",
TaggedAddresses: map[string]string{
@ -1144,8 +1144,8 @@ func TestAPI_CatalogGatewayServices_Terminating(t *testing.T) {
expect := []*GatewayService{
{
Service: CompoundServiceName{Name: "api", Namespace: splitDefaultNamespace, Partition: splitDefaultPartition},
Gateway: CompoundServiceName{Name: "terminating", Namespace: splitDefaultNamespace, Partition: splitDefaultPartition},
Service: CompoundServiceName{Name: "api", Namespace: defaultNamespace, Partition: defaultPartition},
Gateway: CompoundServiceName{Name: "terminating", Namespace: defaultNamespace, Partition: defaultPartition},
GatewayKind: ServiceKindTerminatingGateway,
CAFile: "api/ca.crt",
CertFile: "api/client.crt",
@ -1153,8 +1153,8 @@ func TestAPI_CatalogGatewayServices_Terminating(t *testing.T) {
SNI: "my-domain",
},
{
Service: CompoundServiceName{Name: "redis", Namespace: splitDefaultNamespace, Partition: splitDefaultPartition},
Gateway: CompoundServiceName{Name: "terminating", Namespace: splitDefaultNamespace, Partition: splitDefaultPartition},
Service: CompoundServiceName{Name: "redis", Namespace: defaultNamespace, Partition: defaultPartition},
Gateway: CompoundServiceName{Name: "terminating", Namespace: defaultNamespace, Partition: defaultPartition},
GatewayKind: ServiceKindTerminatingGateway,
CAFile: "ca.crt",
CertFile: "client.crt",
@ -1212,15 +1212,15 @@ func TestAPI_CatalogGatewayServices_Ingress(t *testing.T) {
expect := []*GatewayService{
{
Service: CompoundServiceName{Name: "api", Namespace: splitDefaultNamespace, Partition: splitDefaultPartition},
Gateway: CompoundServiceName{Name: "ingress", Namespace: splitDefaultNamespace, Partition: splitDefaultPartition},
Service: CompoundServiceName{Name: "api", Namespace: defaultNamespace, Partition: defaultPartition},
Gateway: CompoundServiceName{Name: "ingress", Namespace: defaultNamespace, Partition: defaultPartition},
GatewayKind: ServiceKindIngressGateway,
Protocol: "tcp",
Port: 8888,
},
{
Service: CompoundServiceName{Name: "redis", Namespace: splitDefaultNamespace, Partition: splitDefaultPartition},
Gateway: CompoundServiceName{Name: "ingress", Namespace: splitDefaultNamespace, Partition: splitDefaultPartition},
Service: CompoundServiceName{Name: "redis", Namespace: defaultNamespace, Partition: defaultPartition},
Gateway: CompoundServiceName{Name: "ingress", Namespace: defaultNamespace, Partition: defaultPartition},
GatewayKind: ServiceKindIngressGateway,
Protocol: "tcp",
Port: 9999,

View File

@ -139,8 +139,8 @@ func TestAPI_ConfigEntry_DiscoveryChain(t *testing.T) {
entry: &ServiceResolverConfigEntry{
Kind: ServiceResolver,
Name: "test-failover",
Partition: splitDefaultPartition,
Namespace: splitDefaultNamespace,
Partition: defaultPartition,
Namespace: defaultNamespace,
DefaultSubset: "v1",
Subsets: map[string]ServiceResolverSubset{
"v1": {
@ -159,7 +159,7 @@ func TestAPI_ConfigEntry_DiscoveryChain(t *testing.T) {
},
"v1": {
Service: "alternate",
Namespace: splitDefaultNamespace,
Namespace: defaultNamespace,
},
"v3": {
Targets: []ServiceResolverFailoverTarget{
@ -182,12 +182,12 @@ func TestAPI_ConfigEntry_DiscoveryChain(t *testing.T) {
entry: &ServiceResolverConfigEntry{
Kind: ServiceResolver,
Name: "test-redirect",
Partition: splitDefaultPartition,
Namespace: splitDefaultNamespace,
Partition: defaultPartition,
Namespace: defaultNamespace,
Redirect: &ServiceResolverRedirect{
Service: "test-failover",
ServiceSubset: "v2",
Namespace: splitDefaultNamespace,
Namespace: defaultNamespace,
Datacenter: "d",
},
},
@ -198,8 +198,8 @@ func TestAPI_ConfigEntry_DiscoveryChain(t *testing.T) {
entry: &ServiceResolverConfigEntry{
Kind: ServiceResolver,
Name: "test-redirect",
Partition: splitDefaultPartition,
Namespace: splitDefaultNamespace,
Partition: defaultPartition,
Namespace: defaultNamespace,
Redirect: &ServiceResolverRedirect{
Service: "test-failover",
Peer: "cluster-01",
@ -212,14 +212,14 @@ func TestAPI_ConfigEntry_DiscoveryChain(t *testing.T) {
entry: &ServiceSplitterConfigEntry{
Kind: ServiceSplitter,
Name: "test-split",
Partition: splitDefaultPartition,
Namespace: splitDefaultNamespace,
Partition: defaultPartition,
Namespace: defaultNamespace,
Splits: []ServiceSplit{
{
Weight: 90,
Service: "test-failover",
ServiceSubset: "v1",
Namespace: splitDefaultNamespace,
Namespace: defaultNamespace,
RequestHeaders: &HTTPHeaderModifiers{
Set: map[string]string{
"x-foo": "bar",
@ -232,7 +232,7 @@ func TestAPI_ConfigEntry_DiscoveryChain(t *testing.T) {
{
Weight: 10,
Service: "test-redirect",
Namespace: splitDefaultNamespace,
Namespace: defaultNamespace,
},
},
Meta: map[string]string{
@ -247,8 +247,8 @@ func TestAPI_ConfigEntry_DiscoveryChain(t *testing.T) {
entry: &ServiceRouterConfigEntry{
Kind: ServiceRouter,
Name: "test-route",
Partition: splitDefaultPartition,
Namespace: splitDefaultNamespace,
Partition: defaultPartition,
Namespace: defaultNamespace,
Routes: []ServiceRoute{
{
Match: &ServiceRouteMatch{
@ -265,8 +265,8 @@ func TestAPI_ConfigEntry_DiscoveryChain(t *testing.T) {
Destination: &ServiceRouteDestination{
Service: "test-failover",
ServiceSubset: "v2",
Namespace: splitDefaultNamespace,
Partition: splitDefaultPartition,
Namespace: defaultNamespace,
Partition: defaultPartition,
PrefixRewrite: "/",
RequestTimeout: 5 * time.Second,
NumRetries: 5,
@ -358,8 +358,8 @@ func TestAPI_ConfigEntry_ServiceResolver_LoadBalancer(t *testing.T) {
entry: &ServiceResolverConfigEntry{
Kind: ServiceResolver,
Name: "test-least-req",
Partition: splitDefaultPartition,
Namespace: splitDefaultNamespace,
Partition: defaultPartition,
Namespace: defaultNamespace,
LoadBalancer: &LoadBalancer{
Policy: "least_request",
LeastRequestConfig: &LeastRequestConfig{ChoiceCount: 10},
@ -372,8 +372,8 @@ func TestAPI_ConfigEntry_ServiceResolver_LoadBalancer(t *testing.T) {
entry: &ServiceResolverConfigEntry{
Kind: ServiceResolver,
Name: "test-ring-hash",
Namespace: splitDefaultNamespace,
Partition: splitDefaultPartition,
Namespace: defaultNamespace,
Partition: defaultPartition,
LoadBalancer: &LoadBalancer{
Policy: "ring_hash",
RingHashConfig: &RingHashConfig{

View File

@ -57,7 +57,7 @@ type ServiceConsumer struct {
func (e *ExportedServicesConfigEntry) GetKind() string { return ExportedServices }
func (e *ExportedServicesConfigEntry) GetName() string { return e.Name }
func (e *ExportedServicesConfigEntry) GetPartition() string { return e.Name }
func (e *ExportedServicesConfigEntry) GetNamespace() string { return splitDefaultNamespace }
func (e *ExportedServicesConfigEntry) GetNamespace() string { return "" }
func (e *ExportedServicesConfigEntry) GetMeta() map[string]string { return e.Meta }
func (e *ExportedServicesConfigEntry) GetCreateIndex() uint64 { return e.CreateIndex }
func (e *ExportedServicesConfigEntry) GetModifyIndex() uint64 { return e.ModifyIndex }

View File

@ -17,7 +17,7 @@ func TestAPI_ConfigEntries_ExportedServices(t *testing.T) {
testutil.RunStep(t, "set and get", func(t *testing.T) {
exports := &ExportedServicesConfigEntry{
Name: PartitionDefaultName,
Partition: splitDefaultPartition,
Partition: defaultPartition,
Meta: map[string]string{
"gir": "zim",
},
@ -48,7 +48,7 @@ func TestAPI_ConfigEntries_ExportedServices(t *testing.T) {
Services: []ExportedService{
{
Name: "db",
Namespace: splitDefaultNamespace,
Namespace: defaultNamespace,
Consumers: []ServiceConsumer{
{
PeerName: "alpha",
@ -60,7 +60,7 @@ func TestAPI_ConfigEntries_ExportedServices(t *testing.T) {
"foo": "bar",
"gir": "zim",
},
Partition: splitDefaultPartition,
Partition: defaultPartition,
}
_, wm, err := entries.Set(updated, nil)

View File

@ -215,8 +215,8 @@ func TestAPI_ConfigEntries(t *testing.T) {
"foo": "bar",
"gir": "zim",
},
Partition: splitDefaultPartition,
Namespace: splitDefaultNamespace,
Partition: defaultPartition,
Namespace: defaultNamespace,
}
ce := c.ConfigEntries()

View File

@ -87,7 +87,7 @@ func TestAPI_CoordinateUpdate(t *testing.T) {
newCoord.Height = 0.5
entry := &CoordinateEntry{
Node: node,
Partition: splitDefaultPartition,
Partition: defaultPartition,
Coord: newCoord,
}
_, err = coord.Update(entry, nil)

View File

@ -223,8 +223,8 @@ func TestAPI_HealthChecks(t *testing.T) {
ServiceName: "foo",
ServiceTags: []string{"bar"},
Type: "ttl",
Partition: splitDefaultPartition,
Namespace: splitDefaultNamespace,
Partition: defaultPartition,
Namespace: defaultNamespace,
},
}

View File

@ -6,5 +6,5 @@ package api
// The following defaults return "default" in enterprise and "" in OSS.
// This constant is useful when a default value is needed for an
// operation that will reject non-empty values in OSS.
const splitDefaultNamespace = ""
const splitDefaultPartition = ""
const defaultNamespace = ""
const defaultPartition = ""

View File

@ -187,7 +187,7 @@ func TestAPI_ClientTxn(t *testing.T) {
CreateIndex: ret.Results[0].KV.CreateIndex,
ModifyIndex: ret.Results[0].KV.ModifyIndex,
Namespace: ret.Results[0].KV.Namespace,
Partition: splitDefaultPartition,
Partition: defaultPartition,
},
},
&TxnResult{
@ -199,14 +199,14 @@ func TestAPI_ClientTxn(t *testing.T) {
CreateIndex: ret.Results[1].KV.CreateIndex,
ModifyIndex: ret.Results[1].KV.ModifyIndex,
Namespace: ret.Results[0].KV.Namespace,
Partition: splitDefaultPartition,
Partition: defaultPartition,
},
},
&TxnResult{
Node: &Node{
ID: nodeID,
Node: "foo",
Partition: splitDefaultPartition,
Partition: defaultPartition,
Address: "2.2.2.2",
Datacenter: "dc1",
CreateIndex: ret.Results[2].Node.CreateIndex,
@ -218,8 +218,8 @@ func TestAPI_ClientTxn(t *testing.T) {
ID: "foo1",
CreateIndex: ret.Results[3].Service.CreateIndex,
ModifyIndex: ret.Results[3].Service.CreateIndex,
Partition: splitDefaultPartition,
Namespace: splitDefaultNamespace,
Partition: defaultPartition,
Namespace: defaultNamespace,
},
},
&TxnResult{
@ -237,8 +237,8 @@ func TestAPI_ClientTxn(t *testing.T) {
DeregisterCriticalServiceAfterDuration: 20 * time.Second,
},
Type: "tcp",
Partition: splitDefaultPartition,
Namespace: splitDefaultNamespace,
Partition: defaultPartition,
Namespace: defaultNamespace,
CreateIndex: ret.Results[4].Check.CreateIndex,
ModifyIndex: ret.Results[4].Check.CreateIndex,
},
@ -258,8 +258,8 @@ func TestAPI_ClientTxn(t *testing.T) {
DeregisterCriticalServiceAfterDuration: 160 * time.Second,
},
Type: "tcp",
Partition: splitDefaultPartition,
Namespace: splitDefaultNamespace,
Partition: defaultPartition,
Namespace: defaultNamespace,
CreateIndex: ret.Results[4].Check.CreateIndex,
ModifyIndex: ret.Results[4].Check.CreateIndex,
},
@ -279,8 +279,8 @@ func TestAPI_ClientTxn(t *testing.T) {
DeregisterCriticalServiceAfterDuration: 20 * time.Second,
},
Type: "udp",
Partition: splitDefaultPartition,
Namespace: splitDefaultNamespace,
Partition: defaultPartition,
Namespace: defaultNamespace,
CreateIndex: ret.Results[4].Check.CreateIndex,
ModifyIndex: ret.Results[4].Check.CreateIndex,
},
@ -300,8 +300,8 @@ func TestAPI_ClientTxn(t *testing.T) {
DeregisterCriticalServiceAfterDuration: 20 * time.Second,
},
Type: "udp",
Partition: splitDefaultPartition,
Namespace: splitDefaultNamespace,
Partition: defaultPartition,
Namespace: defaultNamespace,
CreateIndex: ret.Results[4].Check.CreateIndex,
ModifyIndex: ret.Results[4].Check.CreateIndex,
},
@ -342,14 +342,14 @@ func TestAPI_ClientTxn(t *testing.T) {
CreateIndex: ret.Results[0].KV.CreateIndex,
ModifyIndex: ret.Results[0].KV.ModifyIndex,
Namespace: ret.Results[0].KV.Namespace,
Partition: splitDefaultPartition,
Partition: defaultPartition,
},
},
&TxnResult{
Node: &Node{
ID: s.Config.NodeID,
Node: s.Config.NodeName,
Partition: splitDefaultPartition,
Partition: defaultPartition,
Address: "127.0.0.1",
Datacenter: "dc1",
TaggedAddresses: map[string]string{