1
// This Source Code Form is subject to the terms of the Mozilla Public
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
10
"github.com/aenix-io/talm/internal/app/poweroff"
13
func TestParseArgs(t *testing.T) {
19
action poweroff.Action
22
name: "shutdown no args",
23
args: []string{"shutdown"},
24
action: poweroff.Shutdown,
27
name: "shutdown with reboot",
28
args: []string{"shutdown", "-r"},
29
action: poweroff.Reboot,
32
name: "shutdown with reboot long",
33
args: []string{"shutdown", "--reboot"},
34
action: poweroff.Reboot,
37
name: "shutdown with poweroff",
38
args: []string{"shutdown", "-P"},
39
action: poweroff.Shutdown,
42
name: "shutdown with poweroff long",
43
args: []string{"shutdown", "--poweroff"},
44
action: poweroff.Shutdown,
47
name: "shutdown with poweroff and reboot",
48
args: []string{"shutdown", "-h", "-r"},
49
action: poweroff.Reboot,
52
name: "shutdown with poweroff, reboot and timer",
53
args: []string{"shutdown", "-h", "-r", "+0"},
54
action: poweroff.Reboot,
57
name: "shutdown with poweroff and halt",
58
args: []string{"shutdown", "-h", "-H"},
59
action: poweroff.Shutdown,
62
name: "shutdown with poweroff and halt long",
63
args: []string{"shutdown", "-h", "--halt"},
64
action: poweroff.Shutdown,
67
name: "poweroff no args",
68
args: []string{"poweroff"},
69
action: poweroff.Shutdown,
72
name: "poweroff with halt",
73
args: []string{"poweroff", "--halt"},
74
action: poweroff.Shutdown,
77
name: "poweroff with poweroff",
78
args: []string{"poweroff", "-p"},
79
action: poweroff.Shutdown,
82
name: "poweroff with poweroff long",
83
args: []string{"poweroff", "--poweroff"},
84
action: poweroff.Shutdown,
87
name: "poweroff with reboot",
88
args: []string{"poweroff", "--reboot"},
89
action: poweroff.Reboot,
93
for _, tt := range tests {
94
t.Run(tt.name, func(t *testing.T) {
97
action := poweroff.ActionFromArgs(tt.args)
98
if action != tt.action {
99
t.Errorf("expected %q, got %q", tt.action, action)