erigon-pulse/cmd/ef-tests-cl/spectest/format.go
a 9644e6d220
Implement SpecTests in native go, add fork_choice handler (#7422)
a few TODO: remain to make this not a draft

---------

Co-authored-by: Giulio <giulio.rebuffo@gmail.com>
2023-05-02 16:19:22 +02:00

44 lines
737 B
Go

package spectest
import (
"golang.org/x/exp/slices"
)
type Format struct {
handlers map[string]Handler
}
func NewFormat() *Format {
o := &Format{
handlers: map[string]Handler{},
}
return o
}
func (r *Format) With(name string, handler Handler) *Format {
r.handlers[name] = handler
return r
}
func (r *Format) WithFn(name string, handler HandlerFunc) *Format {
r.handlers[name] = handler
return r
}
func (r *Format) GetHandlers() []string {
o := make([]string, 0, len(r.handlers))
for k := range r.handlers {
o = append(o, k)
}
slices.Sort(o)
return o
}
func (r *Format) GetHandler(name string) (Handler, error) {
val, ok := r.handlers[name]
if !ok {
return nil, ErrHandlerNotFound(name)
}
return val, nil
}