Refactoring #3
@@ -1,5 +1,15 @@
|
|||||||
package playback
|
package playback
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
type Unit uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
UnitVideo Unit = iota
|
||||||
|
UnitAudio
|
||||||
|
UnitSync
|
||||||
|
)
|
||||||
|
|
||||||
type State uint8
|
type State uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -10,3 +20,14 @@ const (
|
|||||||
StateFailed
|
StateFailed
|
||||||
StateStopping
|
StateStopping
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Status struct {
|
||||||
|
Unit Unit
|
||||||
|
State State
|
||||||
|
Attempt int
|
||||||
|
FailedAttempts int
|
||||||
|
RetryIn time.Duration
|
||||||
|
Err error
|
||||||
|
}
|
||||||
|
|
||||||
|
type StatusObserver func(Status)
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package playback
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestStatusPreservesValues(t *testing.T) {
|
||||||
|
wantErr := errors.New("producer missing")
|
||||||
|
status := Status{
|
||||||
|
Unit: UnitVideo,
|
||||||
|
State: StateReconnecting,
|
||||||
|
Attempt: 2,
|
||||||
|
FailedAttempts: 1,
|
||||||
|
RetryIn: time.Second,
|
||||||
|
Err: wantErr,
|
||||||
|
}
|
||||||
|
|
||||||
|
if status.Unit != UnitVideo {
|
||||||
|
t.Errorf("Unit = %v, want %v", status.Unit, UnitVideo)
|
||||||
|
}
|
||||||
|
// Check the remaining fields similarly.
|
||||||
|
if !errors.Is(status.Err, wantErr) {
|
||||||
|
t.Errorf("Err = %v, want %v", status.Err, wantErr)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user