package inventory

import (
	"os"
	"path/filepath"
	"testing"
)

func TestLoadAndFindNodeBranches(t *testing.T) {
	dir := t.TempDir()
	path := filepath.Join(dir, "inventory.yaml")
	if err := os.WriteFile(path, []byte(`
classes:
  - name: ${CLASS}
    arch: arm64
    os: armbian
    image: file:///tmp/base.img
nodes:
  - name: node1
    class: ${CLASS}
    hostname: node1
    k3s_role: agent
`), 0o644); err != nil {
		t.Fatal(err)
	}
	t.Setenv("CLASS", "rpi4")
	inv, err := Load(path)
	if err != nil {
		t.Fatalf("Load: %v", err)
	}
	if _, _, err := inv.FindNode("missing"); err == nil {
		t.Fatal("expected missing node error")
	}
	if _, cls, err := inv.FindNode("node1"); err != nil || cls == nil {
		t.Fatalf("expected class lookup for node1, got class=%#v err=%v", cls, err)
	}
}
