driftctl/pkg/output/progress_test.go

43 lines
1011 B
Go
Raw Normal View History

package output
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestProgressTimeoutDoesNotInc(t *testing.T) {
2021-05-03 16:41:52 +00:00
progress := NewProgress("loading", "loaded", false)
progress.Start()
2021-04-19 16:10:22 +00:00
progress.Inc()
progress.Stop() // should not hang
2021-04-19 16:10:22 +00:00
progress.Inc() // should restart progress and inc
assert.Equal(t, uint64(2), progress.Val())
assert.Equal(t, true, progress.started.Load())
progress.Stop()
assert.Equal(t, false, progress.started.Load())
}
func TestProgressTimeoutDoesNotHang(t *testing.T) {
2021-05-03 16:41:52 +00:00
progress := NewProgress("loading", "loaded", false)
progress.Start()
time.Sleep(progressTimeout)
for progress.started.Load() == true {
}
2021-04-19 16:10:22 +00:00
progress.Inc() // should not hang but inc
progress.Stop() // should not hang
2021-04-19 16:10:22 +00:00
assert.Equal(t, uint64(1), progress.Val())
}
func TestProgress(t *testing.T) {
2021-05-03 16:41:52 +00:00
progress := NewProgress("loading", "loaded", false)
progress.Start()
progress.Inc()
progress.Inc()
progress.Inc()
progress.Stop()
assert.Equal(t, uint64(3), progress.Val())
}