// NewCoverage provides coverage for the New function. func (t *StringRSuite) NewCoverage() async.R { expected := "a test string" r, s := async.NewStringR() s.Complete(expected) return async.When(r, func(val string, err error) error { if err != nil { return fmt.Errorf("Expected success. Got: %v, Want: nil", err) } if val != expected { return fmt.Errorf("Expected success. Got: %v, Want: %v", val, expected) } return nil }) }
// ForwardCoverage provides coverage for the Forward function. func (t *StringRSuite) ForwardCoverage() async.R { expected := "a test string" resolved, s0 := async.NewStringR() s0.Complete(expected) // Instead of resolving the return result, forward it to an already resolved value. w := async.WhenString(async.Done(), func() async.StringR { r, s := async.NewStringR() s.Forward(resolved) return r }) // Verify that the value was round-tripped. return async.When(w, func(val string, err error) error { if err != nil { return fmt.Errorf("Expected success. Got: %v, Want: nil", err) } if val != expected { return fmt.Errorf("Expected value. Got: %v, Want: %v", val, expected) } return nil }) }
// WhenCoverage provides coverage for the When function. func (t *StringRSuite) WhenCoverage() async.R { expected := "a test string" w := async.WhenString(async.Done(), func() async.StringR { r, s := async.NewStringR() s.Complete(expected) return r }) // Verify that the value was round-tripped. return async.When(w, func(val string, err error) error { if err != nil { return fmt.Errorf("Expected success. Got: %v, Want: nil", err) } if val != expected { return fmt.Errorf("Expected value. Got: %v, Want: %v", val, expected) } return nil }) }
// FinallyCoverage provides coverage for the Finally function. func (t *StringRSuite) FinallyCoverage() async.R { expected := "a test string" didRun := false r, s := async.NewStringR() s.Complete(expected) w := async.FinallyString(r, func() { didRun = true }) // Verify that the value was round-tripped. return async.When(w, func(val string, err error) error { if !didRun { return fmt.Errorf("Expected finally to run. Got: false, Want: true") } if err != nil { return fmt.Errorf("Expected success. Got: %v, Want: nil", err) } if val != expected { return fmt.Errorf("Expected success. Got: %v, Want: %v", val, expected) } return nil }) }