ceremonyclient/go-libp2p-kad-dht/internal/testing/helper.go
2024-10-12 11:48:25 -07:00

32 lines
552 B
Go

package testing
import (
"bytes"
"errors"
)
type TestValidator struct{}
func (TestValidator) Select(_ string, bs [][]byte) (int, error) {
index := -1
for i, b := range bs {
if bytes.Equal(b, []byte("newer")) {
index = i
} else if bytes.Equal(b, []byte("valid")) {
if index == -1 {
index = i
}
}
}
if index == -1 {
return -1, errors.New("no rec found")
}
return index, nil
}
func (TestValidator) Validate(_ string, b []byte) error {
if bytes.Equal(b, []byte("expired")) {
return errors.New("expired")
}
return nil
}