func TestPanicIfTrue(t *testing.T) { assert := assert.New(t) arg := "arg value" format := "could be a format: %s" formatted := fmt.Sprintf(format, arg) assert.Panics(func() { PanicIfTrue(true, "Panicking!!!!") }) assert.NotPanics(func() { PanicIfTrue(false, "Not panicking") }) err := Try(func() { PanicIfTrue(true, format) }) assert.Equal(errors.New(format), Unwrap(err)) err = Try(func() { PanicIfTrue(true, format, arg) }) assert.Equal(errors.New(formatted), Unwrap(err)) }
func TestEnsureChunksInCache(t *testing.T) { assert := assert.New(t) cs := chunks.NewTestStore() cvs := newLocalValueStore(cs) b := NewEmptyBlob() s := String("oy") bref := NewRef(b) sref := NewRef(s) l := NewList(bref, sref) cs.Put(EncodeValue(b, nil)) cs.Put(EncodeValue(s, nil)) cs.Put(EncodeValue(l, nil)) assert.NotPanics(func() { cvs.ensureChunksInCache(bref) }) assert.NotPanics(func() { cvs.ensureChunksInCache(l) }) }
func TestCheckChunksInCache(t *testing.T) { assert := assert.New(t) cs := chunks.NewTestStore() cvs := newLocalValueStore(cs) b := NewEmptyBlob() cs.Put(EncodeValue(b, nil)) cvs.set(b.Hash(), hintedChunk{b.Type(), b.Hash()}) bref := NewRef(b) assert.NotPanics(func() { cvs.chunkHintsFromCache(bref) }) }
func Test_Mock_On_WithFuncTypeArg(t *testing.T) { // make a test impl object var mockedService = new(TestExampleImplementation) c := mockedService. On("TheExampleMethodFuncType", AnythingOfType("mock.ExampleFuncType")). Return(nil) assert.Equal(t, []*Call{c}, mockedService.ExpectedCalls) assert.Equal(t, 1, len(c.Arguments)) assert.Equal(t, AnythingOfType("mock.ExampleFuncType"), c.Arguments[0]) fn := func(string) error { return nil } assert.NotPanics(t, func() { mockedService.TheExampleMethodFuncType(fn) }) }
func Test_Mock_On_WithVariadicFuncWithInterface(t *testing.T) { // make a test impl object var mockedService = new(TestExampleImplementation) c := mockedService.On("TheExampleMethodVariadicInterface", []interface{}{1, 2, 3}). Return(nil) assert.Equal(t, []*Call{c}, mockedService.ExpectedCalls) assert.Equal(t, 1, len(c.Arguments)) assert.Equal(t, []interface{}{1, 2, 3}, c.Arguments[0]) assert.NotPanics(t, func() { mockedService.TheExampleMethodVariadicInterface(1, 2, 3) }) assert.Panics(t, func() { mockedService.TheExampleMethodVariadicInterface(1, 2) }) }
func Test_Mock_On_WithIntArgMatcher(t *testing.T) { var mockedService TestExampleImplementation mockedService.On("TheExampleMethod", MatchedBy(func(a int) bool { return a == 1 }), MatchedBy(func(b int) bool { return b == 2 }), MatchedBy(func(c int) bool { return c == 3 })).Return(0, nil) assert.Panics(t, func() { mockedService.TheExampleMethod(1, 2, 4) }) assert.Panics(t, func() { mockedService.TheExampleMethod(2, 2, 3) }) assert.NotPanics(t, func() { mockedService.TheExampleMethod(1, 2, 3) }) }
// NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic. // // assert.NotPanics(t, func(){ // RemainCalm() // }, "Calling RemainCalm() should NOT panic") // // Returns whether the assertion was successful (true) or not (false). func NotPanics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { if !assert.NotPanics(t, f, msgAndArgs...) { t.FailNow() } }