package facts

import "testing"

func TestChooseTargetsPicksMostCommon(t *testing.T) {
	sum := &ClassSummary{
		Kernels:     map[string]int{"k1": 2, "k2": 1},
		OSImages:    map[string]int{"os1": 1},
		Containerd:  map[string]int{"c1": 2, "c2": 2}, // tie -> empty
		K3sVersions: map[string]int{"k3s1": 3},
		PackageStats: map[string]map[string]int{
			"containerd": {"1.7": 1, "2.0": 2},
			"k3s":        {"v1": 1},
		},
	}
	tg := ChooseTargets(sum)
	if tg.Kernel != "k1" || tg.OSImage != "os1" || tg.K3sVersion != "k3s1" {
		t.Fatalf("unexpected targets: %+v", tg)
	}
	if tg.Containerd != "" {
		t.Fatalf("expected tie -> empty for containerd, got %q", tg.Containerd)
	}
	if tg.Packages["containerd"] != "2.0" {
		t.Fatalf("package target wrong: %+v", tg.Packages)
	}
}

func TestChooseTargetsHandlesNilSummary(t *testing.T) {
	tg := ChooseTargets(nil)
	if tg.Kernel != "" || len(tg.Packages) != 0 {
		t.Fatalf("expected zero targets, got %+v", tg)
	}
}
