github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/test/scenario/responses.go (about) 1 package scenario 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/filecoin-project/bacalhau/pkg/model" 8 ) 9 10 // A CheckSubmitResponse is a function that will examine and validate submitJob response. 11 // Useful when validating that a job should be rejected. 12 type CheckSubmitResponse func(job *model.Job, err error) error 13 14 // SubmitJobSuccess returns a CheckSubmitResponse that asserts no error was returned when submitting a job. 15 func SubmitJobSuccess() CheckSubmitResponse { 16 return func(job *model.Job, err error) error { 17 if err != nil { 18 return fmt.Errorf("expected no error, got %v", err) 19 } 20 if job == nil { 21 return fmt.Errorf("expected job, got nil") 22 } 23 return nil 24 } 25 } 26 27 // SubmitJobFail returns a CheckSubmitResponse that asserts an error was returned when submitting a job. 28 func SubmitJobFail() CheckSubmitResponse { 29 return func(_ *model.Job, err error) error { 30 if err == nil { 31 return fmt.Errorf("expected error, got nil") 32 } 33 return nil 34 } 35 } 36 37 func SubmitJobErrorContains(msg string) CheckSubmitResponse { 38 return func(job *model.Job, err error) error { 39 e := SubmitJobFail()(job, err) 40 if e != nil { 41 return e 42 } 43 44 if !strings.Contains(err.Error(), msg) { 45 return fmt.Errorf("expected error to contain %q, got %q", msg, err.Error()) 46 } 47 return nil 48 } 49 }