You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
consul/internal/resource/resourcetest/validation.go

31 lines
726 B

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
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) {
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")
}
}