feat: add import support and unit tests for provider resources
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package resources
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
)
|
||||
|
||||
func TestFunctionToUnstructuredAndBack(t *testing.T) {
|
||||
input := functionResourceModel{
|
||||
Name: types.StringValue("fn-a"),
|
||||
Environment: types.StringValue("env-a"),
|
||||
PackageName: types.StringValue("pkg-a"),
|
||||
Entrypoint: types.StringValue("main.main"),
|
||||
}
|
||||
|
||||
obj := functionToUnstructured(input, "default")
|
||||
state := unstructuredToFunctionModel(obj, input)
|
||||
|
||||
if state.Name.ValueString() != "fn-a" {
|
||||
t.Fatalf("unexpected name: %q", state.Name.ValueString())
|
||||
}
|
||||
if state.Environment.ValueString() != "env-a" {
|
||||
t.Fatalf("unexpected environment: %q", state.Environment.ValueString())
|
||||
}
|
||||
if state.PackageName.ValueString() != "pkg-a" {
|
||||
t.Fatalf("unexpected package_name: %q", state.PackageName.ValueString())
|
||||
}
|
||||
if state.Entrypoint.ValueString() != "main.main" {
|
||||
t.Fatalf("unexpected entrypoint: %q", state.Entrypoint.ValueString())
|
||||
}
|
||||
|
||||
invoke, found, err := unstructured.NestedMap(obj.Object, "spec", "InvokeStrategy")
|
||||
if err != nil || !found || len(invoke) == 0 {
|
||||
t.Fatalf("InvokeStrategy not set correctly")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user