2023-08-01 18:39:15 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-08-01 18:39:15 +00:00
|
|
|
|
|
|
|
package resourcetest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/internal/resource"
|
|
|
|
"github.com/hashicorp/consul/proto-public/pbresource"
|
|
|
|
)
|
|
|
|
|
2023-09-19 14:42:32 +00:00
|
|
|
func MustDecode[Tp proto.Message](t T, res *pbresource.Resource) *resource.DecodedResource[Tp] {
|
|
|
|
dec, err := resource.Decode[Tp](res)
|
2023-08-01 18:39:15 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
return dec
|
|
|
|
}
|
2024-01-18 22:52:52 +00:00
|
|
|
|
|
|
|
func MustDecodeList[Tp proto.Message](t T, resources []*pbresource.Resource) []*resource.DecodedResource[Tp] {
|
|
|
|
dec, err := resource.DecodeList[Tp](resources)
|
|
|
|
require.NoError(t, err)
|
|
|
|
return dec
|
|
|
|
}
|