func TestClosePoolSizeUndefined(t *testing.T) { t.Parallel() defer ensure.PanicDeepEqual(t, "no close pool size configured") (&Pool{ Max: 1, IdleTimeout: time.Second, }).Acquire() }
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") }
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) }
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`) }
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`) }
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`) }
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) }
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", ) }
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.", ) }
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) }
func TestSentinelCloserPanic(t *testing.T) { defer ensure.PanicDeepEqual(t, "should never get called") sentinelCloser(0).Close() }
func TestIdleTimeoutUndefined(t *testing.T) { t.Parallel() defer ensure.PanicDeepEqual(t, "no idle timeout configured") (&Pool{Max: 1}).Acquire() }
func TestPanicDeepEqualSuccess(t *testing.T) { defer ensure.PanicDeepEqual(t, 1) panic(1) }
func TestPanicDeepEqualNil(t *testing.T) { defer ensure.PanicDeepEqual(t, "can't pass nil to ensure.PanicDeepEqual") ensure.PanicDeepEqual(t, nil) }
func TestAddMoreThanLimit(t *testing.T) { defer ensure.PanicDeepEqual(t, "delta greater than limit") limitgroup.NewLimitGroup(1).Add(2) }
func TestAddNegativeMoreThanExpected(t *testing.T) { defer ensure.PanicDeepEqual(t, "trying to return more slots than acquired") limitgroup.NewLimitGroup(1).Add(-1) }
func TestDoneMoreThanPossible(t *testing.T) { defer ensure.PanicDeepEqual(t, "trying to return more slots than acquired") limitgroup.NewLimitGroup(1).Done() }
func TestZeroLimit(t *testing.T) { defer ensure.PanicDeepEqual(t, "zero is not a valid limit") limitgroup.NewLimitGroup(0) }
func TestInvalidNilError(t *testing.T) { defer ensure.PanicDeepEqual(t, "error must not be nil") (&errgroup.Group{}).Error(nil) }
func TestMaxUndefined(t *testing.T) { t.Parallel() defer ensure.PanicDeepEqual(t, "no max configured") (&Pool{}).Acquire() }
func TestInvalidZeroLengthMultiError(t *testing.T) { defer ensure.PanicDeepEqual(t, "MultiError with no errors") (errgroup.MultiError{}).Error() }
func TestInvalidOneLengthMultiError(t *testing.T) { defer ensure.PanicDeepEqual(t, "MultiError with only 1 error") (errgroup.MultiError{errors.New("")}).Error() }