mirror of
https://github.com/status-im/consul.git
synced 2025-01-10 13:55:55 +00:00
89e6725eee
This new controller produces an intermediate output (ComputedRoutes) that is meant to summarize all relevant xRoutes and related mesh configuration in an easier-to-use format for downstream use to construct the ProxyStateTemplate. It also applies status updates to the xRoute resource types to indicate that they are themselves semantically valid inputs.
78 lines
1.8 KiB
Go
78 lines
1.8 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package controller
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/hashicorp/consul/internal/resource"
|
|
"github.com/hashicorp/consul/proto-public/pbresource"
|
|
"github.com/hashicorp/consul/proto/private/prototest"
|
|
)
|
|
|
|
func TestMakeRequests(t *testing.T) {
|
|
redType := &pbresource.Type{
|
|
Group: "colors",
|
|
GroupVersion: "vfake",
|
|
Kind: "red",
|
|
}
|
|
blueType := &pbresource.Type{
|
|
Group: "colors",
|
|
GroupVersion: "vfake",
|
|
Kind: "blue",
|
|
}
|
|
|
|
casparID := &pbresource.ID{
|
|
Type: redType,
|
|
Tenancy: resource.DefaultNamespacedTenancy(),
|
|
Name: "caspar",
|
|
Uid: "ignored",
|
|
}
|
|
babypantsID := &pbresource.ID{
|
|
Type: redType,
|
|
Tenancy: resource.DefaultNamespacedTenancy(),
|
|
Name: "babypants",
|
|
Uid: "ignored",
|
|
}
|
|
zimRef := &pbresource.Reference{
|
|
Type: redType,
|
|
Tenancy: resource.DefaultNamespacedTenancy(),
|
|
Name: "zim",
|
|
Section: "ignored",
|
|
}
|
|
girRef := &pbresource.Reference{
|
|
Type: redType,
|
|
Tenancy: resource.DefaultNamespacedTenancy(),
|
|
Name: "gir",
|
|
Section: "ignored",
|
|
}
|
|
|
|
newBlueReq := func(name string) Request {
|
|
return Request{
|
|
ID: &pbresource.ID{
|
|
Type: blueType,
|
|
Tenancy: resource.DefaultNamespacedTenancy(),
|
|
Name: name,
|
|
},
|
|
}
|
|
}
|
|
|
|
require.Nil(t, MakeRequests[*pbresource.ID](blueType, nil))
|
|
require.Nil(t, MakeRequests[*pbresource.Reference](blueType, nil))
|
|
|
|
prototest.AssertElementsMatch(t, []Request{
|
|
newBlueReq("caspar"), newBlueReq("babypants"),
|
|
}, MakeRequests[*pbresource.ID](blueType, []*pbresource.ID{
|
|
casparID, babypantsID,
|
|
}))
|
|
|
|
prototest.AssertElementsMatch(t, []Request{
|
|
newBlueReq("gir"), newBlueReq("zim"),
|
|
}, MakeRequests[*pbresource.Reference](blueType, []*pbresource.Reference{
|
|
girRef, zimRef,
|
|
}))
|
|
}
|