コード例 #1
0
ファイル: async_r_test.go プロジェクト: mehulsbhatt/drydock
// WhenErrorCoverage provides coverage for the When function.
func (t *RSuite) WhenErrorCoverage() async.R {
	expected := fmt.Errorf("some error")
	w := async.When(async.Done(), func() async.R {
		r, s := async.NewR()
		s.Fail(expected)
		return r
	})

	w1 := async.When(w, func(_ interface{}, err error) async.R {
		if err != expected {
			return async.NewErrorf("Expected executed w.  Got: %v, Want: %v", err, expected)
		}
		return w
	})

	w2 := async.When(w1, func(interface{}) async.R {
		return async.NewErrorf("Expected not executed w1")
	})
	w3 := async.When(w2, func(_ interface{}, err error) async.R {
		if err != expected {
			return async.NewErrorf("Expected executed w.  Got: %v, Want: %v", err, expected)
		}
		return w2
	})

	w4 := async.When(w3, func() async.R {
		return async.NewErrorf("Expected not executed w3")
	})
	return async.When(w4, func(_ interface{}, err error) async.R {
		if err != expected {
			return async.NewErrorf("Expected executed w.  Got: %v, Want: %v", err, expected)
		}
		return async.Done()
	})
}
コード例 #2
0
ファイル: async_r_test.go プロジェクト: mehulsbhatt/drydock
// NewErrorfCoverage provides coverage for the NewErrorf function.
func (t *RSuite) NewErrorfCoverage() async.R {
	expected := fmt.Errorf("some error")
	r := async.NewErrorf("%v", expected)
	return async.When(r, func(val interface{}, err error) async.R {
		if err.Error() != expected.Error() {
			return async.NewErrorf("Expected error.  Got: %v, Want: %v", err, expected)
		}
		return async.Done()
	})
}
コード例 #3
0
ファイル: async_r_test.go プロジェクト: mehulsbhatt/drydock
// WhenCoverage provides coverage for the When function.
func (t *RSuite) WhenCoverage() async.R {
	w := async.When(async.Done(), func(val interface{}, err error) async.R {
		r, s := async.NewR()
		s.Complete()
		return r
	})

	// Verify full signature.
	expected := interface{}(nil)
	w1 := async.When(w, func(val interface{}, err error) async.R {
		if err != nil {
			return async.NewErrorf("Expected success w1.  Got: %v, Want: nil", err)
		}
		if val != expected {
			return async.NewErrorf("Expected value w1.  Got: %v, Want: %v", val, expected)
		}
		return w
	})

	// Verify just error.
	w2 := async.When(w1, func(err error) async.R {
		if err != nil {
			return async.NewErrorf("Expected success w2.  Got: %v, Want: nil", err)
		}
		return w1
	})

	// Verify just value.
	w3 := async.When(w2, func(val interface{}) async.R {
		if val != expected {
			return async.NewErrorf("Expected value w3.  Got: %v, Want: %v", val, expected)
		}
		return w2
	})

	// Verify neither value nor error.
	didRun := false
	w4 := async.When(w3, func() async.R {
		didRun = true
		return w3
	})
	return async.When(w4, func() async.R {
		if !didRun {
			return async.NewErrorf("Expected executed w4.  Got: %v, Want: true", didRun)
		}
		return w4
	})
}
コード例 #4
0
ファイル: async_r_test.go プロジェクト: mehulsbhatt/drydock
// WhenErrorReturnCoverage provides coverage for the When function.
func (t *RSuite) WhenErrorReturnCoverage() async.R {
	expected := fmt.Errorf("some error")
	w := async.When(async.Done(), func() async.R {
		r, s := async.NewR()
		s.Fail(expected)
		return r
	})

	w1 := async.When(w, func(err error) (interface{}, error) {
		if err != expected {
			return nil, fmt.Errorf("Expected executed w.  Got: %v, Want: %v", err, expected)
		}
		return nil, err
	})

	w2 := async.When(w1, func(err error) error {
		if err != expected {
			return fmt.Errorf("Expected executed w1.  Got: %v, Want: %v", err, expected)
		}
		return err
	})

	return async.When(w2, func(err error) async.R {
		if err != expected {
			return async.NewErrorf("Expected executed w2.  Got: %v, Want: %v", err, expected)
		}
		return async.Done()
	})
}
コード例 #5
0
// NewErrorfCoverage tests Runner.Errorf().
func (t *TurnRunnerSuite) NewErrorfCoverage() async.R {
	e := async.NewErrorf("some %s %d", "error", 1)
	return async.When(e, func(err error) error {
		if err.Error() != "some error 1" {
			return fmt.Errorf("Got: %v, Want: %v", err, "some error 1")
		}
		return nil
	})
}
コード例 #6
0
ファイル: async_r_test.go プロジェクト: mehulsbhatt/drydock
// NewCoverage provides coverage for the New function.
func (t *RSuite) NewCoverage() async.R {
	r, s := async.NewR()
	s.Complete()
	return async.When(r, func(val interface{}, err error) async.R {
		if err != nil {
			return async.NewErrorf("Expected successful completion.  Got: %v, Want: nil", err)
		}
		return async.Done()
	})
}
コード例 #7
0
ファイル: async_r_test.go プロジェクト: mehulsbhatt/drydock
// FinallyCoverage provides coverage for the Finally function.
func (t *RSuite) FinallyCoverage() async.R {
	expected := fmt.Errorf("some error")
	didRun := false
	r, s := async.NewR()
	s.Fail(expected)
	w := async.Finally(r, func() {
		didRun = true
	})

	// Verify that the value was round-tripped.
	return async.When(w, func(val interface{}, err error) async.R {
		if !didRun {
			return async.NewErrorf("Expected finally to run.  Got: false, Want: true")
		}
		if err != expected {
			return async.NewErrorf("Expected error.  Got: %v, Want: %v", err, expected)
		}
		if val != nil {
			return async.NewErrorf("Expected error.  Got: %v, Want: nil", val)
		}
		return async.Done()
	})
}