corso/src/internal/operations/operation_progress_test.go
Keepers 6e71e44024
introduce operations (#114) (#122)
* introduce operations (#114)

Adds the /internal/operations package.  This is a starting point
which only includes the base operation struct and handling.
Per-process (backup/restore) operations to come at a later time.

* adding comments for clarity in op_progress
2022-06-03 15:50:13 -06:00

87 lines
1.3 KiB
Go

package operations
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)
type OpProgressSuite struct {
suite.Suite
}
func TestOpProgressSuite(t *testing.T) {
suite.Run(t, new(OpProgressSuite))
}
func (suite *OpProgressSuite) TestNewOpProgress() {
t := suite.T()
op := newOpProgress()
assert.NotNil(t, op.progressChan)
assert.NotNil(t, op.errorChan)
op.Close()
assert.Nil(t, op.progressChan)
assert.Nil(t, op.errorChan)
}
func (suite *OpProgressSuite) TestOpProgress_Report() {
t := suite.T()
op := newOpProgress()
go func() {
for range op.progressChan {
}
}()
assert.NotPanics(t,
func() {
op.Report("test")
})
ch := op.progressChan
op.progressChan = nil
assert.NotPanics(t,
func() {
op.Report("test")
})
op.progressChan = ch
op.Close()
assert.NotPanics(t,
func() {
op.Report("test")
})
}
func (suite *OpProgressSuite) TestOpProgress_Error() {
t := suite.T()
op := newOpProgress()
go func() {
for range op.errorChan {
}
}()
assert.NotPanics(t,
func() {
op.Error(assert.AnError)
})
ch := op.errorChan
op.errorChan = nil
assert.NotPanics(t,
func() {
op.Error(assert.AnError)
})
op.errorChan = ch
op.Close()
assert.NotPanics(t,
func() {
op.Error(assert.AnError)
})
}