TestRunTopCore only tests the core functionality of runTop: formatting and printing of the output of (api.Compose).Top().
(t *testing.T)
| 204 | // TestRunTopCore only tests the core functionality of runTop: formatting |
| 205 | // and printing of the output of (api.Compose).Top(). |
| 206 | func TestRunTopCore(t *testing.T) { |
| 207 | t.Parallel() |
| 208 | |
| 209 | all := []api.ContainerProcSummary{} |
| 210 | |
| 211 | for _, tc := range topTestCases { |
| 212 | summary := api.ContainerProcSummary{ |
| 213 | Name: "not used", |
| 214 | Titles: tc.titles, |
| 215 | Processes: tc.procs, |
| 216 | Service: tc.name, |
| 217 | Replica: "1", |
| 218 | } |
| 219 | all = append(all, summary) |
| 220 | |
| 221 | t.Run(tc.name, func(t *testing.T) { |
| 222 | header, entries := collectTop([]api.ContainerProcSummary{summary}) |
| 223 | assert.DeepEqual(t, tc.header, header) |
| 224 | assert.DeepEqual(t, tc.entries, entries) |
| 225 | |
| 226 | var buf bytes.Buffer |
| 227 | err := topPrint(&buf, header, entries) |
| 228 | |
| 229 | assert.NilError(t, err) |
| 230 | assert.Equal(t, tc.output, buf.String()) |
| 231 | }) |
| 232 | } |
| 233 | |
| 234 | t.Run("all", func(t *testing.T) { |
| 235 | header, entries := collectTop(all) |
| 236 | assert.DeepEqual(t, topHeader{ |
| 237 | "SERVICE": 0, |
| 238 | "#": 1, |
| 239 | "UID": 2, |
| 240 | "PID": 3, |
| 241 | "PPID": 4, |
| 242 | "C": 5, |
| 243 | "STIME": 6, |
| 244 | "TTY": 7, |
| 245 | "TIME": 8, |
| 246 | "GID": 9, |
| 247 | "CMD": 10, |
| 248 | }, header) |
| 249 | assert.DeepEqual(t, []topEntries{ |
| 250 | { |
| 251 | "SERVICE": "simple", |
| 252 | "#": "1", |
| 253 | "UID": "root", |
| 254 | "PID": "1", |
| 255 | "PPID": "1", |
| 256 | "C": "0", |
| 257 | "STIME": "12:00", |
| 258 | "TTY": "?", |
| 259 | "TIME": "00:00:01", |
| 260 | "CMD": "/entrypoint", |
| 261 | }, { |
| 262 | "SERVICE": "noppid", |
| 263 | "#": "1", |
nothing calls this directly
no test coverage detected