package microvm

import (
	"strings"
	"testing"
)

func validImageSpec() ImageSpec {
	return ImageSpec{
		Arch:     "x86_64-linux",
		BootArgs: "console=ttyS0",
		Initrd:   "initrd",
		Kernel:   "kernel",
		RunnerConfig: RunnerConfig{
			Machine: "microvm",
		},
		MemoryMiB: 2048,
		Shell:     "/bin/sh",
		StoreDisk: "store-disk",
		VCPUs:     2,
	}
}

func TestImageSpecValidateWithoutBaseConfigHash(t *testing.T) {
	spec := validImageSpec()
	if err := spec.Validate(); err != nil {
		t.Fatalf("non-NixOS image spec should validate: %v", err)
	}
	if spec.SupportsConfigActivation() {
		t.Fatal("spec without baseConfigHash should not support config activation")
	}

	spec.BaseConfigHash = "abcdef"
	if !spec.SupportsConfigActivation() {
		t.Fatal("spec with baseConfigHash should support config activation")
	}
}

func TestImageSpecRequiresShell(t *testing.T) {
	spec := validImageSpec()
	spec.Shell = ""
	err := spec.Validate()
	if err == nil || !strings.Contains(err.Error(), "shell") {
		t.Fatalf("spec without shell should fail validation, got: %v", err)
	}
}
