open-consul/agent/consul/discoverychain/testing.go
R.B. Boyer 11fdc70b34
configentry: make a new package to hold shared config entry structs that aren't used for RPC or the FSM (#12384)
First two candidates are ConfigEntryKindName and DiscoveryChainConfigEntries.
2022-02-22 10:36:36 -06:00

38 lines
959 B
Go

package discoverychain
import (
"github.com/mitchellh/go-testing-interface"
"github.com/stretchr/testify/require"
"github.com/hashicorp/consul/agent/configentry"
"github.com/hashicorp/consul/agent/structs"
)
func TestCompileConfigEntries(t testing.T,
serviceName string,
evaluateInNamespace string,
evaluateInPartition string,
evaluateInDatacenter string,
evaluateInTrustDomain string,
setup func(req *CompileRequest), entries ...structs.ConfigEntry) *structs.CompiledDiscoveryChain {
set := configentry.NewDiscoveryChainSet()
set.AddEntries(entries...)
req := CompileRequest{
ServiceName: serviceName,
EvaluateInNamespace: evaluateInNamespace,
EvaluateInPartition: evaluateInPartition,
EvaluateInDatacenter: evaluateInDatacenter,
EvaluateInTrustDomain: evaluateInTrustDomain,
Entries: set,
}
if setup != nil {
setup(&req)
}
chain, err := Compile(req)
require.NoError(t, err)
return chain
}