package panel import ( "strings" "testing" ) // Item 20: the stable channel compares V-series display versions with // the segment rule; the native self-update is systemd-gated and records // its outcome in the shared update status file. func TestDisplayUpdateFields(t *testing.T) { // The test binary runs the default display version V1.0.0. if disp, avail := displayUpdateFields("V1.0.1"); disp != "V1.0.1" || !avail { t.Fatalf("V1.0.1 vs V1.0.0 = %q, %v; want V1.0.1, true", disp, avail) } if disp, avail := displayUpdateFields("V1.0.0"); disp != "V1.0.0" || avail { t.Fatalf("V1.0.0 vs V1.0.0 = %q, %v; want V1.0.0, false", disp, avail) } if disp, avail := displayUpdateFields("3.7.0-agent.1"); disp != "" || avail { t.Fatalf("legacy tag = %q, %v; want empty, false", disp, avail) } if _, avail := displayUpdateFields("V1.0.9"); !avail { t.Fatal("V1.0.9 must be newer than V1.0.0") } } func TestServiceUnitFromCgroup(t *testing.T) { content := "0::/system.slice/x-ui.service\n" if got := serviceUnitFromCgroup(content); got != "x-ui" { t.Fatalf("unit = %q, want x-ui", got) } if got := serviceUnitFromCgroup("0::/user.slice/session-3.scope\n"); got != "" { t.Fatalf("unit = %q, want empty", got) } if got := serviceUnitFromCgroup(""); got != "" { t.Fatalf("unit = %q, want empty", got) } } func TestNativeUpdateStatusRoundtrip(t *testing.T) { t.Setenv("XUI_DB_FOLDER", t.TempDir()) writeUpdateStatus(424242, updateStateSuccess, 0) st := (&PanelService{}).GetUpdateStatus() if st.RunID != "424242" || st.State != updateStateSuccess || st.ExitCode != 0 { t.Fatalf("status roundtrip = %+v", st) } writeUpdateStatus(424243, updateStateFailed, 1) st = (&PanelService{}).GetUpdateStatus() if st.RunID != "424243" || st.State != updateStateFailed || st.ExitCode != 1 { t.Fatalf("status roundtrip = %+v", st) } } func TestStartUpdateStableRequiresSystemd(t *testing.T) { // Force the gate closed regardless of the host running the test. orig := nativeSystemdAvailable nativeSystemdAvailable = func() bool { return false } t.Cleanup(func() { nativeSystemdAvailable = orig }) _, err := (&PanelService{}).startNativeUpdate() if err == nil || !strings.Contains(err.Error(), "systemd") { t.Fatalf("want systemd gate error, got %v", err) } }