Debian Codegraph @

test/format.bats

raw
1 #!/usr/bin/env bats -t
2
3 @test "Default header" {
4 run ./bin/psgo
5 [ "$status" -eq 0 ]
6 [[ ${lines[0]} =~ "USER" ]]
7 [[ ${lines[0]} =~ "PID" ]]
8 [[ ${lines[0]} =~ "PPID" ]]
9 [[ ${lines[0]} =~ "%CPU" ]]
10 [[ ${lines[0]} =~ "ELAPSED" ]]
11 [[ ${lines[0]} =~ "TTY" ]]
12 [[ ${lines[0]} =~ "TIME" ]]
13 [[ ${lines[0]} =~ "COMMAND" ]]
14 }
15
16 @test "%CPU header" {
17 run ./bin/psgo -format "%C"
18 [ "$status" -eq 0 ]
19 [[ ${lines[0]} =~ "%CPU" ]]
20
21 run ./bin/psgo -format "pcpu"
22 [ "$status" -eq 0 ]
23 [[ ${lines[0]} =~ "%CPU" ]]
24 }
25
26 @test "GROUP header" {
27 run ./bin/psgo -format "%G"
28 [ "$status" -eq 0 ]
29 [[ ${lines[0]} =~ "GROUP" ]]
30
31 run ./bin/psgo -format "group"
32 [ "$status" -eq 0 ]
33 [[ ${lines[0]} =~ "GROUP" ]]
34 }
35
36 @test "GROUPS header" {
37 run ./bin/psgo -format "groups"
38 [ "$status" -eq 0 ]
39 [[ ${lines[0]} =~ "GROUPS" ]]
40 }
41
42 @test "PPID header" {
43 run ./bin/psgo -format "%P"
44 [ "$status" -eq 0 ]
45 [[ ${lines[0]} =~ "PPID" ]]
46
47 run ./bin/psgo -format "ppid"
48 [ "$status" -eq 0 ]
49 [[ ${lines[0]} =~ "PPID" ]]
50 }
51
52 @test "USER header" {
53 run ./bin/psgo -format "%U"
54 [ "$status" -eq 0 ]
55 [[ ${lines[0]} =~ "USER" ]]
56
57 run ./bin/psgo -format "user"
58 [ "$status" -eq 0 ]
59 [[ ${lines[0]} =~ "USER" ]]
60 }
61
62 @test "UID header" {
63 run ./bin/psgo -format "uid"
64 [ "$status" -eq 0 ]
65 [[ ${lines[0]} =~ "UID" ]]
66 }
67
68 @test "COMMAND (args) header" {
69 run ./bin/psgo -format "%a"
70 [ "$status" -eq 0 ]
71 [[ ${lines[0]} =~ "COMMAND" ]]
72
73 run ./bin/psgo -format "args"
74 [ "$status" -eq 0 ]
75 [[ ${lines[0]} =~ "COMMAND" ]]
76 }
77
78 @test "COMMAND (comm) header" {
79 run ./bin/psgo -format "%c"
80 [ "$status" -eq 0 ]
81 [[ ${lines[0]} =~ "COMMAND" ]]
82
83 run ./bin/psgo -format "comm"
84 [ "$status" -eq 0 ]
85 [[ ${lines[0]} =~ "COMMAND" ]]
86 }
87
88 @test "RGROUP header" {
89 run ./bin/psgo -format "%g"
90 [ "$status" -eq 0 ]
91 [[ ${lines[0]} =~ "RGROUP" ]]
92
93 run ./bin/psgo -format "rgroup"
94 [ "$status" -eq 0 ]
95 [[ ${lines[0]} =~ "RGROUP" ]]
96 }
97
98 @test "NI" {
99 run ./bin/psgo -format "%n"
100 [ "$status" -eq 0 ]
101 [[ ${lines[0]} =~ "NI" ]]
102
103 run ./bin/psgo -format "nice"
104 [ "$status" -eq 0 ]
105 [[ ${lines[0]} =~ "NI" ]]
106 }
107
108 @test "PID header" {
109 run ./bin/psgo -format "%p"
110 [ "$status" -eq 0 ]
111 [[ ${lines[0]} =~ "PID" ]]
112
113 run ./bin/psgo -format "pid"
114 [ "$status" -eq 0 ]
115 [[ ${lines[0]} =~ "PID" ]]
116 }
117
118 @test "ELAPSED header" {
119 run ./bin/psgo -format "%t"
120 [ "$status" -eq 0 ]
121 [[ ${lines[0]} =~ "ELAPSED" ]]
122
123 run ./bin/psgo -format "etime"
124 [ "$status" -eq 0 ]
125 [[ ${lines[0]} =~ "ELAPSED" ]]
126 }
127
128 @test "RUSER header" {
129 run ./bin/psgo -format "%u"
130 [ "$status" -eq 0 ]
131 [[ ${lines[0]} =~ "RUSER" ]]
132
133 run ./bin/psgo -format "ruser"
134 [ "$status" -eq 0 ]
135 [[ ${lines[0]} =~ "RUSER" ]]
136 }
137
138 @test "TIME header" {
139 run ./bin/psgo -format "%x"
140 [ "$status" -eq 0 ]
141 [[ ${lines[0]} =~ "TIME" ]]
142
143 run ./bin/psgo -format "time"
144 [ "$status" -eq 0 ]
145 [[ ${lines[0]} =~ "TIME" ]]
146 }
147
148 @test "TTY header" {
149 run ./bin/psgo -format "%y"
150 [ "$status" -eq 0 ]
151 [[ ${lines[0]} =~ "TTY" ]]
152
153 run ./bin/psgo -format "tty"
154 [ "$status" -eq 0 ]
155 [[ ${lines[0]} =~ "TTY" ]]
156 }
157
158 @test "VSZ header" {
159 run ./bin/psgo -format "%z"
160 [ "$status" -eq 0 ]
161 [[ ${lines[0]} =~ "VSZ" ]]
162
163 run ./bin/psgo -format "vsz"
164 [ "$status" -eq 0 ]
165 [[ ${lines[0]} =~ "VSZ" ]]
166 }
167
168 @test "CAPAMB header" {
169 run ./bin/psgo -format "capamb"
170 [ "$status" -eq 0 ]
171 [[ ${lines[0]} =~ "AMBIENT CAPS" ]]
172 }
173
174 @test "CAPINH header" {
175 run ./bin/psgo -format "capinh"
176 [ "$status" -eq 0 ]
177 [[ ${lines[0]} =~ "INHERITED CAPS" ]]
178 }
179
180 @test "CAPPRM header" {
181 run ./bin/psgo -format "capprm"
182 [ "$status" -eq 0 ]
183 [[ ${lines[0]} =~ "PERMITTED CAPS" ]]
184 }
185
186 @test "CAPEFF header" {
187 run ./bin/psgo -format "capeff"
188 [ "$status" -eq 0 ]
189 [[ ${lines[0]} =~ "EFFECTIVE CAPS" ]]
190 }
191
192 @test "CAPBND header" {
193 run ./bin/psgo -format "capbnd"
194 [ "$status" -eq 0 ]
195 [[ ${lines[0]} =~ "BOUNDING CAPS" ]]
196 }
197
198 @test "SECCOMP header" {
199 run ./bin/psgo -format "seccomp"
200 [ "$status" -eq 0 ]
201 [[ ${lines[0]} =~ "SECCOMP" ]]
202 }
203
204 @test "HPID header" {
205 run ./bin/psgo -format "hpid"
206 [ "$status" -eq 0 ]
207 [[ ${lines[0]} =~ "HPID" ]]
208 # host PIDs are only extracted with `-pid`
209 [[ ${lines[1]} =~ "?" ]]
210 }
211
212 @test "HUSER header" {
213 run ./bin/psgo -format "huser"
214 [ "$status" -eq 0 ]
215 [[ ${lines[0]} =~ "HUSER" ]]
216 # host users are only extracted with `-pid`
217 [[ ${lines[1]} =~ "?" ]]
218 }
219
220 @test "HUID header" {
221 run ./bin/psgo -format "huid"
222 [ "$status" -eq 0 ]
223 [[ ${lines[0]} =~ "HUID" ]]
224 # host UIDs are only extracted with `-pid`
225 [[ ${lines[1]} =~ "?" ]]
226 }
227
228 @test "HGROUP header" {
229 run ./bin/psgo -format "hgroup"
230 [ "$status" -eq 0 ]
231 [[ ${lines[0]} =~ "HGROUP" ]]
232 # host groups are only extracted with `-pid`
233 [[ ${lines[1]} =~ "?" ]]
234 }
235
236 @test "HGROUPS header" {
237 run ./bin/psgo -format "hgroups"
238 [ "$status" -eq 0 ]
239 [[ ${lines[0]} =~ "HGROUPS" ]]
240 # host groups are only extracted with `-pid`
241 [[ ${lines[1]} =~ "?" ]]
242 }
243
244
245 function is_labeling_enabled() {
246 if [ -e /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
247 echo 1
248 return
249 fi
250 echo 0
251 }
252
253 @test "LABEL header" {
254 enabled=$(is_labeling_enabled)
255 if [[ "$enabled" -eq 0 ]]; then
256 skip "skip this test since labeling is not enabled."
257 fi
258 run ./bin/psgo -format "label"
259 [ "$status" -eq 0 ]
260 [[ ${lines[0]} =~ "LABEL" ]]
261 }
262
263 @test "RSS header" {
264 run ./bin/psgo -format "rss"
265 [ "$status" -eq 0 ]
266 [[ ${lines[0]} =~ "RSS" ]]
267 }
268
269 @test "STATE header" {
270 run ./bin/psgo -format "state"
271 [ "$status" -eq 0 ]
272 [[ ${lines[0]} =~ "STATE" ]]
273 }
274
275 @test "STIME header" {
276 run ./bin/psgo -format "stime"
277 [ "$status" -eq 0 ]
278 [[ ${lines[0]} =~ "STIME" ]]
279 }
280
281 @test "ALL header" {
282 run ./bin/psgo -format "pcpu, group, groups, ppid, user, uid, args, comm, rgroup, nice, pid, pgid, etime, ruser, time, tty, vsz, capamb, capinh, capprm, capeff, capbnd, seccomp, hpid, huser, huid, hgroup, hgroups, rss, state"
283 [ "$status" -eq 0 ]
284
285 [[ ${lines[0]} =~ "%CPU" ]]
286 [[ ${lines[0]} =~ "GROUP" ]]
287 [[ ${lines[0]} =~ "GROUPS" ]]
288 [[ ${lines[0]} =~ "PPID" ]]
289 [[ ${lines[0]} =~ "USER" ]]
290 [[ ${lines[0]} =~ "UID" ]]
291 [[ ${lines[0]} =~ "COMMAND" ]]
292 [[ ${lines[0]} =~ "COMMAND" ]]
293 [[ ${lines[0]} =~ "RGROUP" ]]
294 [[ ${lines[0]} =~ "NI" ]]
295 [[ ${lines[0]} =~ "PID" ]]
296 [[ ${lines[0]} =~ "ELAPSED" ]]
297 [[ ${lines[0]} =~ "RUSER" ]]
298 [[ ${lines[0]} =~ "TIME" ]]
299 [[ ${lines[0]} =~ "TTY" ]]
300 [[ ${lines[0]} =~ "VSZ" ]]
301 [[ ${lines[0]} =~ "AMBIENT CAPS" ]]
302 [[ ${lines[0]} =~ "INHERITED CAPS" ]]
303 [[ ${lines[0]} =~ "PERMITTED CAPS" ]]
304 [[ ${lines[0]} =~ "EFFECTIVE CAPS" ]]
305 [[ ${lines[0]} =~ "BOUNDING CAPS" ]]
306 [[ ${lines[0]} =~ "SECCOMP" ]]
307 [[ ${lines[0]} =~ "HPID" ]]
308 [[ ${lines[0]} =~ "HUSER" ]]
309 [[ ${lines[0]} =~ "HUID" ]]
310 [[ ${lines[0]} =~ "HGROUP" ]]
311 [[ ${lines[0]} =~ "HGROUPS" ]]
312 [[ ${lines[0]} =~ "RSS" ]]
313 [[ ${lines[0]} =~ "STATE" ]]
314 }