Files
fission-console/terraform/provider/internal/resources/environment_resource_test.go
T
Naeel fd236d87ea feat: provider audit — builder support, function tuning, source archive
Аудит провайдера vs каноничный Fission. Добавлено:

Environment:
- builder_image, builder_command для Go и языков с build step

Package:
- deploy_type (literal/source) для переключения deployment/source archive
- loadPackageSourceArchive() — zip-упаковка source_dir
- Убран пустой source:{} из literal mode

Function:
- executor_type (poolmgr/newdeploy/container)
- function_timeout, idle_timeout
- min_scale, max_scale для ExecutionStrategy

Все 21 тест пройден. Обратная совместимость проверена.
Документация: doc/AUDIT_PROVIDER_VS_FISSION_2026-06-03.md
2026-04-15 17:46:47 +03:00

85 lines
2.9 KiB
Go

package resources
import (
"testing"
"github.com/hashicorp/terraform-plugin-framework/types"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
func TestEnvironmentToUnstructuredAndBack(t *testing.T) {
input := environmentResourceModel{
Name: types.StringValue("env-a"),
Image: types.StringValue("ghcr.io/fission/python-env"),
Version: types.Int64Value(3),
PoolSize: types.Int64Value(5),
}
obj := environmentToUnstructured(input, "default")
state := unstructuredToEnvironmentModel(obj, input)
if state.Name.ValueString() != "env-a" {
t.Fatalf("unexpected name: %q", state.Name.ValueString())
}
if state.Namespace.ValueString() != "default" {
t.Fatalf("unexpected namespace: %q", state.Namespace.ValueString())
}
if state.Image.ValueString() != "ghcr.io/fission/python-env" {
t.Fatalf("unexpected image: %q", state.Image.ValueString())
}
if state.Version.ValueInt64() != 3 {
t.Fatalf("unexpected version: %d", state.Version.ValueInt64())
}
if state.PoolSize.ValueInt64() != 5 {
t.Fatalf("unexpected poolsize: %d", state.PoolSize.ValueInt64())
}
}
func TestEnvironmentToUnstructuredWithBuilder(t *testing.T) {
input := environmentResourceModel{
Name: types.StringValue("go-env"),
Image: types.StringValue("ghcr.io/fission/go-env"),
Version: types.Int64Value(3),
PoolSize: types.Int64Value(3),
BuilderImage: types.StringValue("ghcr.io/fission/go-builder"),
BuilderCommand: types.StringValue("build"),
}
obj := environmentToUnstructured(input, "default")
state := unstructuredToEnvironmentModel(obj, input)
if state.BuilderImage.ValueString() != "ghcr.io/fission/go-builder" {
t.Fatalf("unexpected builder_image: %q", state.BuilderImage.ValueString())
}
if state.BuilderCommand.ValueString() != "build" {
t.Fatalf("unexpected builder_command: %q", state.BuilderCommand.ValueString())
}
// Verify the unstructured object has builder section
builderImage, found, _ := unstructured.NestedString(obj.Object, "spec", "builder", "image")
if !found || builderImage != "ghcr.io/fission/go-builder" {
t.Fatalf("builder.image not set correctly in unstructured: %q", builderImage)
}
builderCmd, found, _ := unstructured.NestedString(obj.Object, "spec", "builder", "command")
if !found || builderCmd != "build" {
t.Fatalf("builder.command not set correctly in unstructured: %q", builderCmd)
}
}
func TestEnvironmentToUnstructuredWithoutBuilder(t *testing.T) {
input := environmentResourceModel{
Name: types.StringValue("py-env"),
Image: types.StringValue("ghcr.io/fission/python-env"),
Version: types.Int64Value(3),
PoolSize: types.Int64Value(3),
}
obj := environmentToUnstructured(input, "default")
// Verify no builder section when builder_image is not set
_, found, _ := unstructured.NestedString(obj.Object, "spec", "builder", "image")
if found {
t.Fatalf("builder should not be present when builder_image is not set")
}
}