MCPcopy Create free account
hub / github.com/cli/cli / Test_humanFileSize

Function Test_humanFileSize

pkg/cmd/release/view/view_test.go:284–343  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

282}
283
284func Test_humanFileSize(t *testing.T) {
285 tests := []struct {
286 name string
287 size int64
288 want string
289 }{
290 {
291 name: "min bytes",
292 size: 1,
293 want: "1 B",
294 },
295 {
296 name: "max bytes",
297 size: 1023,
298 want: "1023 B",
299 },
300 {
301 name: "min kibibytes",
302 size: 1024,
303 want: "1.00 KiB",
304 },
305 {
306 name: "max kibibytes",
307 size: 1024*1024 - 1,
308 want: "1023.99 KiB",
309 },
310 {
311 name: "min mibibytes",
312 size: 1024 * 1024,
313 want: "1.00 MiB",
314 },
315 {
316 name: "fractional mibibytes",
317 size: 1024*1024*12 + 1024*350,
318 want: "12.34 MiB",
319 },
320 {
321 name: "max mibibytes",
322 size: 1024*1024*1024 - 1,
323 want: "1023.99 MiB",
324 },
325 {
326 name: "min gibibytes",
327 size: 1024 * 1024 * 1024,
328 want: "1.00 GiB",
329 },
330 {
331 name: "fractional gibibytes",
332 size: 1024 * 1024 * 1024 * 1.5,
333 want: "1.50 GiB",
334 },
335 }
336 for _, tt := range tests {
337 t.Run(tt.name, func(t *testing.T) {
338 if got := humanFileSize(tt.size); got != tt.want {
339 t.Errorf("humanFileSize() = %v, want %v", got, tt.want)
340 }
341 })

Callers

nothing calls this directly

Calls 3

humanFileSizeFunction · 0.70
RunMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected