fix(provider): detect source code drift and validate package/function references
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package resources
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
@@ -36,3 +37,40 @@ func TestFunctionToUnstructuredAndBack(t *testing.T) {
|
||||
t.Fatalf("InvokeStrategy not set correctly")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateEntrypointAgainstPackageSourcePythonOK(t *testing.T) {
|
||||
source := "def main():\n return 'ok'\n"
|
||||
pkg := &unstructured.Unstructured{Object: map[string]interface{}{
|
||||
"spec": map[string]interface{}{
|
||||
"deployment": map[string]interface{}{
|
||||
"literal": base64.StdEncoding.EncodeToString([]byte(source)),
|
||||
},
|
||||
},
|
||||
}}
|
||||
|
||||
if err := validateEntrypointAgainstPackageSource("main.main", pkg); err != nil {
|
||||
t.Fatalf("expected valid entrypoint, got error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateEntrypointAgainstPackageSourcePythonMissing(t *testing.T) {
|
||||
source := "def another():\n return 'ok'\n"
|
||||
pkg := &unstructured.Unstructured{Object: map[string]interface{}{
|
||||
"spec": map[string]interface{}{
|
||||
"deployment": map[string]interface{}{
|
||||
"literal": base64.StdEncoding.EncodeToString([]byte(source)),
|
||||
},
|
||||
},
|
||||
}}
|
||||
|
||||
if err := validateEntrypointAgainstPackageSource("main.main", pkg); err == nil {
|
||||
t.Fatalf("expected validation error for missing python function")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateEntrypointAgainstPackageSourceBadFormat(t *testing.T) {
|
||||
pkg := &unstructured.Unstructured{}
|
||||
if err := validateEntrypointAgainstPackageSource("main", pkg); err == nil {
|
||||
t.Fatalf("expected validation error for bad entrypoint format")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user