talm

Форк
0
/
poweroff_test.go 
103 строки · 2.3 Кб
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/.
4

5
package poweroff_test
6

7
import (
8
	"testing"
9

10
	"github.com/aenix-io/talm/internal/app/poweroff"
11
)
12

13
func TestParseArgs(t *testing.T) {
14
	t.Parallel()
15

16
	tests := []struct {
17
		name   string
18
		args   []string
19
		action poweroff.Action
20
	}{
21
		{
22
			name:   "shutdown no args",
23
			args:   []string{"shutdown"},
24
			action: poweroff.Shutdown,
25
		},
26
		{
27
			name:   "shutdown with reboot",
28
			args:   []string{"shutdown", "-r"},
29
			action: poweroff.Reboot,
30
		},
31
		{
32
			name:   "shutdown with reboot long",
33
			args:   []string{"shutdown", "--reboot"},
34
			action: poweroff.Reboot,
35
		},
36
		{
37
			name:   "shutdown with poweroff",
38
			args:   []string{"shutdown", "-P"},
39
			action: poweroff.Shutdown,
40
		},
41
		{
42
			name:   "shutdown with poweroff long",
43
			args:   []string{"shutdown", "--poweroff"},
44
			action: poweroff.Shutdown,
45
		},
46
		{
47
			name:   "shutdown with poweroff and reboot",
48
			args:   []string{"shutdown", "-h", "-r"},
49
			action: poweroff.Reboot,
50
		},
51
		{
52
			name:   "shutdown with poweroff, reboot and timer",
53
			args:   []string{"shutdown", "-h", "-r", "+0"},
54
			action: poweroff.Reboot,
55
		},
56
		{
57
			name:   "shutdown with poweroff and halt",
58
			args:   []string{"shutdown", "-h", "-H"},
59
			action: poweroff.Shutdown,
60
		},
61
		{
62
			name:   "shutdown with poweroff and halt long",
63
			args:   []string{"shutdown", "-h", "--halt"},
64
			action: poweroff.Shutdown,
65
		},
66
		{
67
			name:   "poweroff no args",
68
			args:   []string{"poweroff"},
69
			action: poweroff.Shutdown,
70
		},
71
		{
72
			name:   "poweroff with halt",
73
			args:   []string{"poweroff", "--halt"},
74
			action: poweroff.Shutdown,
75
		},
76
		{
77
			name:   "poweroff with poweroff",
78
			args:   []string{"poweroff", "-p"},
79
			action: poweroff.Shutdown,
80
		},
81
		{
82
			name:   "poweroff with poweroff long",
83
			args:   []string{"poweroff", "--poweroff"},
84
			action: poweroff.Shutdown,
85
		},
86
		{
87
			name:   "poweroff with reboot",
88
			args:   []string{"poweroff", "--reboot"},
89
			action: poweroff.Reboot,
90
		},
91
	}
92

93
	for _, tt := range tests {
94
		t.Run(tt.name, func(t *testing.T) {
95
			t.Parallel()
96

97
			action := poweroff.ActionFromArgs(tt.args)
98
			if action != tt.action {
99
				t.Errorf("expected %q, got %q", tt.action, action)
100
			}
101
		})
102
	}
103
}
104

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.