fix(provider): detect source code drift and validate package/function references

This commit is contained in:
Naeel
2026-04-15 10:51:40 +03:00
parent e2b6a4472e
commit 1b8bff8364
6 changed files with 252 additions and 0 deletions
@@ -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")
}
}