Example #1
0
func TestClosePoolSizeUndefined(t *testing.T) {
	t.Parallel()
	defer ensure.PanicDeepEqual(t, "no close pool size configured")
	(&Pool{
		Max:         1,
		IdleTimeout: time.Second,
	}).Acquire()
}
Example #2
0
func TestRunNoArgsWithArg(t *testing.T) {
	t.Parallel()
	h := newHarness(t)
	defer h.Stop()
	h.env.Exit = func(i int) { panic(exitCode(i)) }
	func() {
		defer ensure.PanicDeepEqual(t, exitCode(1))
		r := runNoArgs(h.env, nil)
		r(noOpCmd(), []string{"foo"})
	}()
	ensure.StringContains(t, h.Err.String(), "unexpected arguments")
}
Example #3
0
func TestRunNoArgsFuncError(t *testing.T) {
	t.Parallel()
	const message = "hello world"
	h := newHarness(t)
	defer h.Stop()
	h.env.Exit = func(i int) { panic(exitCode(i)) }
	func() {
		defer ensure.PanicDeepEqual(t, exitCode(1))
		r := runNoArgs(h.env, func(*env) error { return errors.New(message) })
		r(noOpCmd(), nil)
	}()
	ensure.StringContains(t, h.Err.String(), message)
}
Example #4
0
func TestPanicDeepEqualFailure(t *testing.T) {
	var c capture
	func() {
		defer ensure.PanicDeepEqual(&c, 1)
		panic(2)
	}()
	c.Contains(t, `TestPanicDeepEqualFailure
expected these to be equal:
ACTUAL:
(int) 2

EXPECTED:
(int) 1`)
}
Example #5
0
func TestRunWithAppNotFound(t *testing.T) {
	t.Parallel()
	h := newHarness(t)
	defer h.Stop()
	c := legacyConfig{Applications: map[string]*parseAppConfig{"a": {}}}
	h.makeWithConfig(jsonStr(t, c))
	h.env.Exit = func(i int) { panic(exitCode(i)) }
	func() {
		defer ensure.PanicDeepEqual(t, exitCode(1))
		r := runWithClient(h.env, nil)
		r(noOpCmd(), []string{"b"})
	}()
	ensure.StringContains(t, h.Err.String(), `App "b" wasn't found`)
}
Example #6
0
func TestPanicDeepEqualFailure(t *testing.T) {
	var c capture
	func() {
		defer ensure.PanicDeepEqual(&c, 1)
		panic(2)
	}()
	c.Matches(t, `TestPanicDeepEqualFailure((.func1)?)
expected these to be equal:
ACTUAL:
\(int\) 2

EXPECTED:
\(int\) 1`)
}
Example #7
0
func TestDiscardInvalid(t *testing.T) {
	t.Parallel()
	defer ensure.PanicDeepEqual(t, errWrongPool)
	var cm resourceMaker
	p := Pool{
		New:           cm.New,
		Max:           1,
		MinIdle:       1,
		IdleTimeout:   time.Hour,
		ClosePoolSize: 1,
	}
	r, err := cm.New()
	ensure.Nil(t, err)
	p.Discard(r)
}
Example #8
0
func TestRunWithAppMultipleArgs(t *testing.T) {
	t.Parallel()
	h := newHarness(t)
	defer h.Stop()
	h.env.Exit = func(i int) { panic(exitCode(i)) }
	func() {
		defer ensure.PanicDeepEqual(t, exitCode(1))
		r := runWithClient(h.env, nil)
		r(noOpCmd(), []string{"foo", "bar"})
	}()
	ensure.StringContains(
		t,
		h.Err.String(),
		"only an optional app name is expected",
	)
}
Example #9
0
func TestRunWithAppNonProjectDir(t *testing.T) {
	t.Parallel()
	h := newHarness(t)
	defer h.Stop()
	h.makeEmptyRoot()
	h.env.Exit = func(i int) { panic(exitCode(i)) }
	func() {
		defer ensure.PanicDeepEqual(t, exitCode(1))
		r := runWithClient(h.env, nil)
		r(noOpCmd(), nil)
	}()
	ensure.StringContains(
		t,
		h.Err.String(),
		"Command must be run inside a Parse project.",
	)
}
Example #10
0
func TestRunWithAppError(t *testing.T) {
	t.Parallel()
	h := newHarness(t)
	defer h.Stop()
	const appName = "a"
	c := &parseConfig{
		Applications: map[string]*parseAppConfig{
			appName: {ApplicationID: "id", MasterKey: "token"},
		},
	}
	h.makeWithConfig(jsonStr(t, c))
	h.env.Exit = func(i int) { panic(exitCode(i)) }
	const message = "hello world"
	func() {
		defer ensure.PanicDeepEqual(t, exitCode(1))
		r := runWithClient(h.env, func(e *env, c *context) error {
			ensure.NotNil(t, c)
			return errors.New(message)
		})
		r(noOpCmd(), []string{"a"})
	}()
	ensure.StringContains(t, h.Err.String(), message)
}
Example #11
0
func TestSentinelCloserPanic(t *testing.T) {
	defer ensure.PanicDeepEqual(t, "should never get called")
	sentinelCloser(0).Close()
}
Example #12
0
func TestIdleTimeoutUndefined(t *testing.T) {
	t.Parallel()
	defer ensure.PanicDeepEqual(t, "no idle timeout configured")
	(&Pool{Max: 1}).Acquire()
}
Example #13
0
func TestPanicDeepEqualSuccess(t *testing.T) {
	defer ensure.PanicDeepEqual(t, 1)
	panic(1)
}
Example #14
0
func TestPanicDeepEqualNil(t *testing.T) {
	defer ensure.PanicDeepEqual(t, "can't pass nil to ensure.PanicDeepEqual")
	ensure.PanicDeepEqual(t, nil)
}
Example #15
0
func TestAddMoreThanLimit(t *testing.T) {
	defer ensure.PanicDeepEqual(t, "delta greater than limit")
	limitgroup.NewLimitGroup(1).Add(2)
}
Example #16
0
func TestAddNegativeMoreThanExpected(t *testing.T) {
	defer ensure.PanicDeepEqual(t, "trying to return more slots than acquired")
	limitgroup.NewLimitGroup(1).Add(-1)
}
Example #17
0
func TestDoneMoreThanPossible(t *testing.T) {
	defer ensure.PanicDeepEqual(t, "trying to return more slots than acquired")
	limitgroup.NewLimitGroup(1).Done()
}
Example #18
0
func TestZeroLimit(t *testing.T) {
	defer ensure.PanicDeepEqual(t, "zero is not a valid limit")
	limitgroup.NewLimitGroup(0)
}
Example #19
0
func TestInvalidNilError(t *testing.T) {
	defer ensure.PanicDeepEqual(t, "error must not be nil")
	(&errgroup.Group{}).Error(nil)
}
Example #20
0
func TestMaxUndefined(t *testing.T) {
	t.Parallel()
	defer ensure.PanicDeepEqual(t, "no max configured")
	(&Pool{}).Acquire()
}
Example #21
0
func TestInvalidZeroLengthMultiError(t *testing.T) {
	defer ensure.PanicDeepEqual(t, "MultiError with no errors")
	(errgroup.MultiError{}).Error()
}
Example #22
0
func TestInvalidOneLengthMultiError(t *testing.T) {
	defer ensure.PanicDeepEqual(t, "MultiError with only 1 error")
	(errgroup.MultiError{errors.New("")}).Error()
}