(t *testing.T)
| 37 | } |
| 38 | |
| 39 | func TestProgressBarUpdate(t *testing.T) { |
| 40 | tests := []struct { |
| 41 | name string |
| 42 | total int64 |
| 43 | current int64 |
| 44 | expectedInTTY []string |
| 45 | expectedInNonTTY []string |
| 46 | }{ |
| 47 | { |
| 48 | name: "0% progress", |
| 49 | total: 1024, |
| 50 | current: 0, |
| 51 | expectedInTTY: []string{}, // Progress bar visual (can't easily test exact rendering) |
| 52 | expectedInNonTTY: []string{"0%", "0B", "1.0KB"}, |
| 53 | }, |
| 54 | { |
| 55 | name: "50% progress", |
| 56 | total: 1024, |
| 57 | current: 512, |
| 58 | expectedInTTY: []string{}, // Progress bar visual |
| 59 | expectedInNonTTY: []string{"50%", "512B", "1.0KB"}, |
| 60 | }, |
| 61 | { |
| 62 | name: "100% progress", |
| 63 | total: 1024, |
| 64 | current: 1024, |
| 65 | expectedInTTY: []string{}, // Progress bar visual |
| 66 | expectedInNonTTY: []string{"100%", "1.0KB", "1.0KB"}, |
| 67 | }, |
| 68 | { |
| 69 | name: "large file progress", |
| 70 | total: 1024 * 1024 * 1024, // 1GB |
| 71 | current: 512 * 1024 * 1024, // 512MB |
| 72 | expectedInTTY: []string{}, |
| 73 | expectedInNonTTY: []string{"50%", "512.0MB", "1.00GB"}, |
| 74 | }, |
| 75 | { |
| 76 | name: "zero total edge case", |
| 77 | total: 0, |
| 78 | current: 0, |
| 79 | expectedInTTY: []string{}, // Should show 100% |
| 80 | expectedInNonTTY: []string{"100%", "0B", "0B"}, |
| 81 | }, |
| 82 | } |
| 83 | |
| 84 | for _, tt := range tests { |
| 85 | t.Run(tt.name, func(t *testing.T) { |
| 86 | bar := NewProgressBar(tt.total) |
| 87 | output := bar.Update(tt.current) |
| 88 | |
| 89 | assert.NotEmpty(t, output, "Update should return non-empty string") |
| 90 | |
| 91 | // In non-TTY mode, we can validate the text output |
| 92 | // In TTY mode, the output contains ANSI codes which we can't easily validate |
| 93 | // but we ensure it doesn't panic |
| 94 | if !isTTY() { |
| 95 | for _, expected := range tt.expectedInNonTTY { |
| 96 | assert.Contains(t, output, expected, "Output should contain expected text in non-TTY mode") |
nothing calls this directly
no test coverage detected