R.B. Boyer d574473fd1
mesh: make FailoverPolicy work in xdsv2 and ProxyStateTemplate (#18900)
Ensure that configuring a FailoverPolicy for a service that is reachable via a xRoute or a direct upstream causes an envoy aggregate cluster to be created for the original cluster name, but with separate clusters for each one of the possible destinations.
2023-09-20 11:59:01 -05:00

32 lines
739 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package resourcetest
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/hashicorp/consul/internal/resource"
"github.com/hashicorp/consul/proto-public/pbresource"
)
func ValidateAndNormalize(t *testing.T, registry resource.Registry, res *pbresource.Resource) {
t.Helper()
typ := res.Id.Type
typeInfo, ok := registry.Resolve(typ)
if !ok {
t.Fatalf("unhandled resource type: %q", resource.ToGVK(typ))
}
if typeInfo.Mutate != nil {
require.NoError(t, typeInfo.Mutate(res), "failed to apply type mutation to resource")
}
if typeInfo.Validate != nil {
require.NoError(t, typeInfo.Validate(res), "failed to validate resource")
}
}