32 lines
733 B
Go
32 lines
733 B
Go
package mxgateway
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
type failingReader struct{}
|
|
|
|
func (failingReader) Read([]byte) (int, error) { return 0, errors.New("entropy unavailable") }
|
|
|
|
func TestNewCorrelationIDFallsBackWhenRandFails(t *testing.T) {
|
|
a := newCorrelationIDFrom(failingReader{})
|
|
b := newCorrelationIDFrom(failingReader{})
|
|
if a == "" || b == "" {
|
|
t.Fatal("fallback id must not be empty")
|
|
}
|
|
if a == b {
|
|
t.Fatalf("fallback ids must be unique, got %q twice", a)
|
|
}
|
|
if !strings.HasPrefix(a, "fallback-") {
|
|
t.Fatalf("unexpected fallback shape %q", a)
|
|
}
|
|
}
|
|
|
|
func TestNewCorrelationIDRandomIsHex32(t *testing.T) {
|
|
if id := newCorrelationID(); len(id) != 32 {
|
|
t.Fatalf("expected 32 hex chars, got %q", id)
|
|
}
|
|
}
|