Various improvements.
This commit is contained in:
@@ -2,6 +2,7 @@ package serial_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
"testing/quick"
|
||||
|
||||
@@ -243,7 +244,30 @@ func TestRandomCodeFailsWhenAllIndicesInUse(t *testing.T) {
|
||||
_, _, err := serial.RandomCode(func(candidate uint32) bool {
|
||||
return true
|
||||
})
|
||||
if !errors.Is(err, serial.ErrRandomGenerationFailed) {
|
||||
t.Fatalf("expected random generation failed error, got: %v", err)
|
||||
if !errors.Is(err, serial.ErrNoAvailableIndex) {
|
||||
t.Fatalf("expected no available index error, got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRandomCodeWithOptionsMaxAttempts(t *testing.T) {
|
||||
_, _, err := serial.RandomCodeWithOptions(serial.RandomCodeOptions{
|
||||
MaxAttempts: 1,
|
||||
IsInUse: func(candidate uint32) bool {
|
||||
return true
|
||||
},
|
||||
})
|
||||
if !errors.Is(err, serial.ErrNoAvailableIndex) {
|
||||
t.Fatalf("expected no available index error, got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRandomCodeWithOptionsRandomSourceFailure(t *testing.T) {
|
||||
_, _, err := serial.RandomCodeWithOptions(serial.RandomCodeOptions{
|
||||
RandomIndex: func(max uint32) (uint32, error) {
|
||||
return 0, fmt.Errorf("rng down")
|
||||
},
|
||||
})
|
||||
if !errors.Is(err, serial.ErrRandomSourceFailed) {
|
||||
t.Fatalf("expected random source failed error, got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user