shad-go/distbuild/disttest/recorder.go

58 lines
968 B
Go
Raw Permalink Normal View History

2020-03-11 22:46:45 +00:00
package disttest
import (
"gitlab.com/slon/shad-go/distbuild/pkg/build"
2020-03-11 22:46:45 +00:00
)
type JobResult struct {
Stdout string
Stderr string
Code *int
Error string
}
type Recorder struct {
Jobs map[build.ID]*JobResult
}
func NewRecorder() *Recorder {
return &Recorder{
Jobs: map[build.ID]*JobResult{},
}
}
func (r *Recorder) job(jobID build.ID) *JobResult {
j, ok := r.Jobs[jobID]
if !ok {
j = &JobResult{}
r.Jobs[jobID] = j
}
return j
}
func (r *Recorder) OnJobStdout(jobID build.ID, stdout []byte) error {
j := r.job(jobID)
j.Stdout += string(stdout)
return nil
}
func (r *Recorder) OnJobStderr(jobID build.ID, stderr []byte) error {
j := r.job(jobID)
j.Stderr += string(stderr)
return nil
}
func (r *Recorder) OnJobFinished(jobID build.ID) error {
j := r.job(jobID)
j.Code = new(int)
return nil
}
func (r *Recorder) OnJobFailed(jobID build.ID, code int, error string) error {
j := r.job(jobID)
j.Code = &code
j.Error = error
return nil
}