1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
kyverno/ext/resource/convert/convert_test.go
Charles-Edouard Brétéché 32d16059be
refactor: move resource/convert in ext (#8769)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-10-29 10:39:39 +01:00

42 lines
984 B
Go

package convert
import (
"os"
"testing"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/yaml"
)
func TestTo(t *testing.T) {
{
data, err := os.ReadFile("../../../cmd/cli/kubectl-kyverno/_testdata/policies/check-image.yaml")
require.NoError(t, err)
json, err := yaml.YAMLToJSON(data)
require.NoError(t, err)
var untyped unstructured.Unstructured
require.NoError(t, untyped.UnmarshalJSON(json))
typed, err := To[corev1.ConfigMap](untyped)
require.Nil(t, typed)
require.Error(t, err)
}
{
data, err := os.ReadFile("../../../cmd/cli/kubectl-kyverno/_testdata/resources/namespace.yaml")
require.NoError(t, err)
json, err := yaml.YAMLToJSON(data)
require.NoError(t, err)
var untyped unstructured.Unstructured
require.NoError(t, untyped.UnmarshalJSON(json))
typed, err := To[corev1.Namespace](untyped)
require.NotNil(t, typed)
require.NoError(t, err)
}
}