mirror of
https://github.com/status-im/consul.git
synced 2025-03-02 14:20:39 +00:00
* Exported services api implemented * Tests added, refactored code * Adding server tests * changelog added * Proto gen added * Adding codegen changes * changing url, response object * Fixing lint error by having namespace and partition directly * Tests changes * refactoring tests * Simplified uniqueness logic for exported services, sorted the response in order of service name * Fix lint errors, refactored code
88 lines
2.3 KiB
Go
88 lines
2.3 KiB
Go
// 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)
|
|
}
|