R.B. Boyer 13ce787a3f
resource: adding various helpers for working with resources (#18342)
This is a bit of a grab bag of helpers that I found useful for working with them when authoring substantial Controllers. Subsequent PRs will make use of them.
2023-08-01 13:39:15 -05:00

24 lines
511 B
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package resourcetest
import (
"testing"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"
"github.com/hashicorp/consul/internal/resource"
"github.com/hashicorp/consul/proto-public/pbresource"
)
func MustDecode[V any, PV interface {
proto.Message
*V
}](t *testing.T, res *pbresource.Resource) *resource.DecodedResource[V, PV] {
dec, err := resource.Decode[V, PV](res)
require.NoError(t, err)
return dec
}