package system import ( "context" "strings" "testing" ) // Third review of mesh-catalog #147: a unit's name reaches systemctl as an argument, and since a setting // may now name a template's instance, a name beginning with '-' must never be read as an option. Every // call that names a unit passes `--` before it. func TestEverySystemctlCallPassesDashDashBeforeTheUnit(t *testing.T) { var asked [][]string run := func(_ context.Context, name string, args ...string) (string, error) { if name == "systemctl" { asked = append(asked, args) } return "LoadState=loaded\nActiveState=active\nType=simple\nFragmentPath=/x\n", nil } ctx := context.Background() a := arch{} unit := "-x@y.timer" a.ServiceState(ctx, run, unit) a.SetServiceState(ctx, run, unit, "running") a.SetServiceState(ctx, run, unit, "stopped") a.ServiceBoot(ctx, run, unit) a.SetServiceBoot(ctx, run, unit, "enabled") a.SetServiceBoot(ctx, run, unit, "disabled") if len(asked) != 6 { t.Fatalf("asked %d times: %v", len(asked), asked) } for _, args := range asked { if len(args) < 2 || args[len(args)-1] != unit || args[len(args)-2] != "--" { t.Errorf("systemctl %s", strings.Join(args, " ")) } } }