-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
2,653 additions
and
2,264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
//go:build !consulent | ||
|
||
package consul | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
gogrpc "google.golang.org/grpc" | ||
|
||
"github.com/hashicorp/consul/proto/private/pbconfigentry" | ||
"github.com/hashicorp/consul/sdk/freeport" | ||
"github.com/hashicorp/consul/testrpc" | ||
) | ||
|
||
func TestConfigEntryBackend_RejectsPartition(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("too slow for testing.Short") | ||
} | ||
|
||
t.Parallel() | ||
|
||
_, s1 := testServerWithConfig(t, func(c *Config) { | ||
c.GRPCTLSPort = freeport.GetOne(t) | ||
}) | ||
testrpc.WaitForLeader(t, s1.RPC, "dc1") | ||
|
||
// make a grpc client to dial s1 directly | ||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) | ||
t.Cleanup(cancel) | ||
|
||
conn, err := gogrpc.DialContext(ctx, s1.config.RPCAddr.String(), | ||
gogrpc.WithContextDialer(newServerDialer(s1.config.RPCAddr.String())), | ||
//nolint:staticcheck | ||
gogrpc.WithInsecure(), | ||
gogrpc.WithBlock()) | ||
require.NoError(t, err) | ||
t.Cleanup(func() { conn.Close() }) | ||
|
||
configEntryClient := pbconfigentry.NewConfigEntryServiceClient(conn) | ||
|
||
req := pbconfigentry.GetResolvedExportedServicesRequest{ | ||
Partition: "test", | ||
} | ||
_, err = configEntryClient.GetResolvedExportedServices(ctx, &req) | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), "Partitions are a Consul Enterprise feature") | ||
} | ||
|
||
func TestConfigEntryBackend_IgnoresDefaultPartition(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("too slow for testing.Short") | ||
} | ||
|
||
t.Parallel() | ||
|
||
_, s1 := testServerWithConfig(t, func(c *Config) { | ||
c.GRPCTLSPort = freeport.GetOne(t) | ||
}) | ||
|
||
testrpc.WaitForLeader(t, s1.RPC, "dc1") | ||
|
||
// make a grpc client to dial s1 directly | ||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) | ||
t.Cleanup(cancel) | ||
|
||
conn, err := gogrpc.DialContext(ctx, s1.config.RPCAddr.String(), | ||
gogrpc.WithContextDialer(newServerDialer(s1.config.RPCAddr.String())), | ||
//nolint:staticcheck | ||
gogrpc.WithInsecure(), | ||
gogrpc.WithBlock()) | ||
require.NoError(t, err) | ||
t.Cleanup(func() { conn.Close() }) | ||
|
||
configEntryClient := pbconfigentry.NewConfigEntryServiceClient(conn) | ||
|
||
req := pbconfigentry.GetResolvedExportedServicesRequest{ | ||
Partition: "DeFaUlT", | ||
} | ||
_, err = configEntryClient.GetResolvedExportedServices(ctx, &req) | ||
require.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
agent/consul/state/config_entry_exported_services_ce_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
//go:build !consulent | ||
|
||
package state | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/consul/agent/structs" | ||
"github.com/hashicorp/consul/proto/private/pbconfigentry" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestStore_prepareExportedServicesResponse(t *testing.T) { | ||
var exportedServices = make(map[structs.ServiceName]map[structs.ServiceConsumer]struct{}) | ||
|
||
svc1 := structs.NewServiceName("db", nil) | ||
exportedServices[svc1] = make(map[structs.ServiceConsumer]struct{}) | ||
exportedServices[svc1][structs.ServiceConsumer{Peer: "west"}] = struct{}{} | ||
exportedServices[svc1][structs.ServiceConsumer{Peer: "east"}] = struct{}{} | ||
|
||
// Adding partition to ensure that it's not included in response | ||
exportedServices[svc1][structs.ServiceConsumer{Partition: "east"}] = struct{}{} | ||
|
||
svc2 := structs.NewServiceName("web", nil) | ||
exportedServices[svc2] = make(map[structs.ServiceConsumer]struct{}) | ||
exportedServices[svc2][structs.ServiceConsumer{Peer: "peer-a"}] = struct{}{} | ||
exportedServices[svc2][structs.ServiceConsumer{Peer: "peer-b"}] = struct{}{} | ||
|
||
resp := prepareExportedServicesResponse(exportedServices) | ||
|
||
expected := []*pbconfigentry.ResolvedExportedService{ | ||
{ | ||
Service: "db", | ||
Consumers: &pbconfigentry.Consumers{ | ||
Peers: []string{"east", "west"}, | ||
}, | ||
}, | ||
{ | ||
Service: "web", | ||
Consumers: &pbconfigentry.Consumers{ | ||
Peers: []string{"peer-a", "peer-b"}, | ||
}, | ||
}, | ||
} | ||
|
||
require.ElementsMatch(t, expected, resp) | ||
} |
Oops, something went wrong.