mirror of
https://github.com/ivuorinen/gibidify.git
synced 2026-02-06 11:50:34 +00:00
feat: update go to 1.25, add permissions and envs (#49)
* chore(ci): update go to 1.25, add permissions and envs * fix(ci): update pr-lint.yml * chore: update go, fix linting * fix: tests and linting * fix(lint): lint fixes, renovate should now pass * fix: updates, security upgrades * chore: workflow updates, lint * fix: more lint, checkmake, and other fixes * fix: more lint, convert scripts to POSIX compliant * fix: simplify codeql workflow * tests: increase test coverage, fix found issues * fix(lint): editorconfig checking, add to linters * fix(lint): shellcheck, add to linters * fix(lint): apply cr comment suggestions * fix(ci): remove step-security/harden-runner * fix(lint): remove duplication, apply cr fixes * fix(ci): tests in CI/CD pipeline * chore(lint): deduplication of strings * fix(lint): apply cr comment suggestions * fix(ci): actionlint * fix(lint): apply cr comment suggestions * chore: lint, add deps management
This commit is contained in:
147
cli/ui_progress_test.go
Normal file
147
cli/ui_progress_test.go
Normal file
@@ -0,0 +1,147 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestStartProgress(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
total int
|
||||
description string
|
||||
enabled bool
|
||||
expectBar bool
|
||||
}{
|
||||
{
|
||||
name: "progress enabled with valid total",
|
||||
total: 100,
|
||||
description: testProcessingMsg,
|
||||
enabled: true,
|
||||
expectBar: true,
|
||||
},
|
||||
{
|
||||
name: "progress disabled",
|
||||
total: 100,
|
||||
description: testProcessingMsg,
|
||||
enabled: false,
|
||||
expectBar: false,
|
||||
},
|
||||
{
|
||||
name: "zero total",
|
||||
total: 0,
|
||||
description: testProcessingMsg,
|
||||
enabled: true,
|
||||
expectBar: false,
|
||||
},
|
||||
{
|
||||
name: "negative total",
|
||||
total: -5,
|
||||
description: testProcessingMsg,
|
||||
enabled: true,
|
||||
expectBar: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(
|
||||
tt.name, func(t *testing.T) {
|
||||
ui := &UIManager{
|
||||
enableProgress: tt.enabled,
|
||||
output: &bytes.Buffer{},
|
||||
}
|
||||
|
||||
ui.StartProgress(tt.total, tt.description)
|
||||
|
||||
if tt.expectBar {
|
||||
assert.NotNil(t, ui.progressBar)
|
||||
} else {
|
||||
assert.Nil(t, ui.progressBar)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateProgress(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
setupBar bool
|
||||
enabledProg bool
|
||||
expectUpdate bool
|
||||
}{
|
||||
{
|
||||
name: "with progress bar",
|
||||
setupBar: true,
|
||||
enabledProg: true,
|
||||
expectUpdate: true,
|
||||
},
|
||||
{
|
||||
name: "without progress bar",
|
||||
setupBar: false,
|
||||
enabledProg: false,
|
||||
expectUpdate: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(
|
||||
tt.name, func(_ *testing.T) {
|
||||
ui := &UIManager{
|
||||
enableProgress: tt.enabledProg,
|
||||
output: &bytes.Buffer{},
|
||||
}
|
||||
|
||||
if tt.setupBar {
|
||||
ui.StartProgress(10, "Test")
|
||||
}
|
||||
|
||||
// Should not panic
|
||||
ui.UpdateProgress(1)
|
||||
|
||||
// Multiple updates should not panic
|
||||
ui.UpdateProgress(2)
|
||||
ui.UpdateProgress(3)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFinishProgress(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
setupBar bool
|
||||
}{
|
||||
{
|
||||
name: "with progress bar",
|
||||
setupBar: true,
|
||||
},
|
||||
{
|
||||
name: "without progress bar",
|
||||
setupBar: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(
|
||||
tt.name, func(t *testing.T) {
|
||||
ui := &UIManager{
|
||||
enableProgress: true,
|
||||
output: &bytes.Buffer{},
|
||||
}
|
||||
|
||||
if tt.setupBar {
|
||||
ui.StartProgress(10, "Test")
|
||||
}
|
||||
|
||||
// Should not panic
|
||||
ui.FinishProgress()
|
||||
|
||||
// Bar should be cleared
|
||||
assert.Nil(t, ui.progressBar)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user