forked from linuxdeepin/startdde
-
Notifications
You must be signed in to change notification settings - Fork 0
/
startmanager_test.go
277 lines (266 loc) · 5.8 KB
/
startmanager_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
package main
import (
"fmt"
"os"
"reflect"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/linuxdeepin/go-lib/appinfo/desktopappinfo"
)
func _TestSetAutostart(t *testing.T) { //nolint
m := StartManager{}
if err := m.setAutostart("dropbox.desktop", true); err != nil {
fmt.Println(err)
}
if !m.isAutostart("dropbox.desktop") {
t.Error("set to autostart failed")
}
if err := m.setAutostart("dropbox.desktop", false); err != nil {
fmt.Println(err)
}
if m.isAutostart("dropbox.desktop") {
t.Error("set to not autostart failed")
}
}
func _TestScanDir(t *testing.T) { //nolint
scanDir("/tmp", func(p string, info os.FileInfo) bool {
t.Log(info.Name())
return false
})
}
func Test_getLaunchedHooks(t *testing.T) {
type args struct {
hookDir string
}
tests := []struct {
name string
args args
wantRet []string
}{
{
name: "getLaunchedHooks",
args: args{
hookDir: "testdata/launched_hook",
},
wantRet: []string{
"one",
"two",
"three",
},
},
{
name: "getLaunchedHooks_notexist",
args: args{
hookDir: "testdata/launched_hook.notexist",
},
wantRet: []string{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotRet := getLaunchedHooks(tt.args.hookDir)
assert.ElementsMatch(t, tt.wantRet, gotRet)
})
}
}
func TestStartManager_getCpuFreqAdjustMap(t *testing.T) {
type args struct {
path string
}
tests := []struct {
name string
obj *StartManager
args args
want map[string]int32
}{
{
name: "StartManager_getCpuFreqAdjustMap",
obj: &StartManager{},
args: args{
path: "testdata/cpuFreqAdjustFiles/app_startup.conf",
},
want: map[string]int32{
"dde-calendar": 3,
"dde-control-center": 3,
"dde-file-manager": 3,
"dde-printer": 3,
"deepin-album": 3,
"deepin-appstore": 3,
"deepin-calculator": 3,
"deepin-compressor": 3,
"deepin-draw": 3,
"deepin-image-viewer": 3,
"deepin-movie": 3,
"deepin-music": 3,
"deepin-reader": 3,
"deepin-screen-recorder": 3,
"deepin-voice-note": 3,
"dman": 3,
"uos-browser": 3,
},
},
{
name: "StartManager_getCpuFreqAdjustMap_notexist",
obj: &StartManager{},
args: args{
path: "testdata/cpuFreqAdjustFiles/app_startup.notexist",
},
want: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.obj.getCpuFreqAdjustMap(tt.args.path)
assert.Equal(t, tt.want, got)
})
}
}
func TestStartManager_enableCpuFreqLock(t *testing.T) {
type args struct {
desktopFile string
}
tests := []struct {
name string
obj *StartManager
args args
wantErr bool
}{
{
name: "StartManager_enableCpuFreqLock",
obj: &StartManager{
cpuFreqAdjustMap: map[string]int32{
"dde-file-manager": 3,
"dde-printer": 3,
"deepin-album": 3,
},
},
args: args{
desktopFile: "not exist",
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.obj.enableCpuFreqLock(tt.args.desktopFile)
if tt.wantErr {
assert.Error(t, err)
}
})
}
}
func TestStartManager_getRestartTime(t *testing.T) {
type args struct {
appInfo *desktopappinfo.DesktopAppInfo
}
type test struct {
name string
obj *StartManager
args args
want time.Time
wantSec bool
}
tests := []test{
func() test {
appInfo, _ := desktopappinfo.NewDesktopAppInfoFromFile("testdata/desktop/dde-file-manager.desktop")
now := time.Now()
return test{
name: "StartManager_getRestartTime",
obj: &StartManager{
restartTimeMap: map[string]time.Time{appInfo.GetFileName(): now},
},
args: args{
appInfo: appInfo,
},
want: now,
wantSec: true,
}
}(),
func() test {
appInfo, _ := desktopappinfo.NewDesktopAppInfoFromFile("testdata/desktop/dde-file-manager.desktop")
return test{
name: "StartManager_getRestartTime_notExist",
obj: &StartManager{},
args: args{
appInfo: appInfo,
},
want: time.Time{},
wantSec: false,
}
}(),
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, got1 := tt.obj.getRestartTime(tt.args.appInfo)
assert.Equal(t, tt.want, got)
assert.Equal(t, tt.wantSec, got1)
})
}
}
func Test_removeProxy(t *testing.T) {
type args struct {
sl []string
}
tests := []struct {
name string
args args
want []string
}{
// TODO: Add test cases.
{
name: "StartManager_removeProxy",
args: args{
sl: []string{
"ftp_proxy=http://127.0.0.1:8889",
"http_proxy=http://127.0.0.1:8889",
"https_proxy=http://127.0.0.1:8889",
"DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus",
"LANG=zh_CN.UTF-8",
},
},
want: []string{
"DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus",
"LANG=zh_CN.UTF-8",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := removeProxy(tt.args.sl); !reflect.DeepEqual(got, tt.want) {
t.Errorf("removeProxy() = %v, want %v", got, tt.want)
}
})
}
}
func Test_removeSl(t *testing.T) {
type args struct {
sl []string
mem string
}
tests := []struct {
name string
args args
want []string
}{
// TODO: Add test cases.
{
name: "StartManager_removeSl",
args: args{
sl: []string{"test", "mem"},
mem: "mem",
},
want: []string{"test"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := removeSl(tt.args.sl, tt.args.mem); !reflect.DeepEqual(got, tt.want) {
t.Errorf("removeSl() = %v, want %v", got, tt.want)
}
})
}
}