34 lines
955 B
Go
34 lines
955 B
Go
package synthetic
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
|
|
"git.ilapage.cn/ila/yovision/Bell/server/app/event"
|
|
testevents "git.ilapage.cn/ila/yovision/Bell/server/testdata/events"
|
|
)
|
|
|
|
var ErrFixture = errors.New("合成夹具验证失败")
|
|
|
|
type Service struct{ Events event.Service }
|
|
type Input struct {
|
|
Fixture string `json:"fixture"`
|
|
SourceEventID string `json:"source_event_id,omitempty"`
|
|
}
|
|
|
|
func (s Service) Fixtures() ([]testevents.Fixture, error) { return testevents.All() }
|
|
func (s Service) Inject(ctx context.Context, input Input) (event.Result, error) {
|
|
fixture, err := testevents.Find(input.Fixture)
|
|
if err != nil {
|
|
return event.Result{}, err
|
|
}
|
|
if fixture.ValidationError != "" {
|
|
return event.Result{}, errors.Join(ErrFixture, errors.New(fixture.ValidationError))
|
|
}
|
|
if value := strings.TrimSpace(input.SourceEventID); value != "" {
|
|
fixture.Command.SourceEventID = value
|
|
}
|
|
return s.Events.Ingest(ctx, fixture.Command)
|
|
}
|