func (me *crudExecTest) TestScanVal() { t := me.T() mDb, mock, err := sqlmock.New() assert.NoError(t, err) mock.ExpectQuery(`SELECT "id" FROM "items"`). WillReturnError(fmt.Errorf("query error")) mock.ExpectQuery(`SELECT "id" FROM "items"`). WithArgs(). WillReturnRows(sqlmock.NewRows([]string{"id"}).FromCSVString("1")) db := New("db-mock", mDb) exec := newCrudExec(db, nil, `SELECT "id" FROM "items"`) var id int64 var ids []int64 found, err := exec.ScanVal(id) assert.EqualError(t, err, "goqu: Type must be a pointer when calling ScanVal") assert.False(t, found) found, err = exec.ScanVal(&ids) assert.EqualError(t, err, "goqu: Cannot scan into a slice when calling ScanVal") assert.False(t, found) found, err = exec.ScanVal(&id) assert.EqualError(t, err, "query error") assert.False(t, found) var ptrId int64 found, err = exec.ScanVal(&ptrId) assert.NoError(t, err) assert.Equal(t, ptrId, 1) }
func (me *crudExecTest) TestScanStruct() { t := me.T() mDb, mock, err := sqlmock.New() assert.NoError(t, err) mock.ExpectQuery(`SELECT \* FROM "items"`). WillReturnError(fmt.Errorf("query error")) mock.ExpectQuery(`SELECT \* FROM "items"`). WithArgs(). WillReturnRows(sqlmock.NewRows([]string{"address", "name"}).FromCSVString("111 Test Addr,Test1")) mock.ExpectQuery(`SELECT \* FROM "items"`). WithArgs(). WillReturnRows(sqlmock.NewRows([]string{"address", "name", "phone_number", "age"}).FromCSVString("111 Test Addr,Test1,111-111-1111,20")) mock.ExpectQuery(`SELECT \* FROM "items"`). WithArgs(). WillReturnRows(sqlmock.NewRows([]string{"address", "name"}).FromCSVString("111 Test Addr,Test1")) db := New("db-mock", mDb) exec := newCrudExec(db, nil, `SELECT * FROM "items"`) var slicePtr []testCrudActionItem var item testCrudActionItem found, err := exec.ScanStruct(item) assert.EqualError(t, err, "goqu: Type must be a pointer to a struct when calling ScanStruct") assert.False(t, found) found, err = exec.ScanStruct(&slicePtr) assert.EqualError(t, err, "goqu: Type must be a pointer to a struct when calling ScanStruct") assert.False(t, found) found, err = exec.ScanStruct(&item) assert.EqualError(t, err, "query error") assert.False(t, found) found, err = exec.ScanStruct(&item) assert.NoError(t, err) assert.True(t, found) assert.Equal(t, item.Address, "111 Test Addr") assert.Equal(t, item.Name, "Test1") var composed testComposedCrudActionItem found, err = exec.ScanStruct(&composed) assert.NoError(t, err) assert.True(t, found) assert.Equal(t, composed.Address, "111 Test Addr") assert.Equal(t, composed.Name, "Test1") assert.Equal(t, composed.PhoneNumber, "111-111-1111") assert.Equal(t, composed.Age, 20) var noTag testCrudActionNoTagsItem found, err = exec.ScanStruct(&noTag) assert.NoError(t, err) assert.True(t, found) assert.Equal(t, noTag.Address, "111 Test Addr") assert.Equal(t, noTag.Name, "Test1") }
func (me *postgresTest) TestDelete() { t := me.T() ds := me.db.From("entry") var e entry found, err := ds.Where(goqu.I("int").Eq(9)).Select("id").ScanStruct(&e) assert.NoError(t, err) assert.True(t, found) _, err = ds.Where(goqu.I("id").Eq(e.Id)).Delete().Exec() assert.NoError(t, err) count, err := ds.Count() assert.NoError(t, err) assert.Equal(t, count, 9) var id uint32 found, err = ds.Where(goqu.I("id").Eq(e.Id)).ScanVal(&id) assert.NoError(t, err) assert.False(t, found) e = entry{} found, err = ds.Where(goqu.I("int").Eq(8)).Select("id").ScanStruct(&e) assert.NoError(t, err) assert.True(t, found) assert.NotEqual(t, e.Id, 0) id = 0 _, err = ds.Where(goqu.I("id").Eq(e.Id)).Returning("id").Delete().ScanVal(&id) assert.NoError(t, err) assert.Equal(t, id, e.Id) }
func (me *mysqlTest) TestDelete() { t := me.T() ds := me.db.From("entry") var e entry found, err := ds.Where(goqu.I("int").Eq(9)).Select("id").ScanStruct(&e) assert.NoError(t, err) assert.True(t, found) _, err = ds.Where(goqu.I("id").Eq(e.Id)).Delete().Exec() assert.NoError(t, err) count, err := ds.Count() assert.NoError(t, err) assert.Equal(t, count, 9) var id uint32 found, err = ds.Where(goqu.I("id").Eq(e.Id)).ScanVal(&id) assert.NoError(t, err) assert.False(t, found) e = entry{} found, err = ds.Where(goqu.I("int").Eq(8)).Select("id").ScanStruct(&e) assert.NoError(t, err) assert.True(t, found) assert.NotEqual(t, e.Id, 0) id = 0 _, err = ds.Where(goqu.I("id").Eq(e.Id)).Returning("id").Delete().ScanVal(&id) assert.Equal(t, err.Error(), "goqu: Adapter does not support RETURNING clause") }
// AssertNotCalled asserts that the method was not called. func (m *Mock) AssertNotCalled(t TestingT, methodName string, arguments ...interface{}) bool { if !assert.False(t, m.methodWasCalled(methodName, arguments), fmt.Sprintf("The \"%s\" method was called with %d argument(s), but should NOT have been.", methodName, len(arguments))) { t.Logf("%v", m.expectedCalls()) return false } return true }
func Test_Arguments_Is(t *testing.T) { var args Arguments = []interface{}{"string", 123, true} assert.True(t, args.Is("string", 123, true)) assert.False(t, args.Is("wrong", 456, false)) }
func (me *adapterTest) TestHasAdapter() { t := me.T() assert.False(t, HasAdapter("test")) RegisterAdapter("test", func(ds *Dataset) Adapter { return NewDefaultAdapter(ds) }) assert.True(t, HasAdapter("test")) removeAdapter("test") }
func (me *crudExecTest) TestWithError() { t := me.T() mDb, _, err := sqlmock.New() assert.NoError(t, err) db := New("db-mock", mDb) expectedErr := fmt.Errorf("crud exec error") exec := newCrudExec(db, expectedErr, `SELECT * FROM "items"`) var items []testCrudActionItem assert.EqualError(t, exec.ScanStructs(&items), expectedErr.Error()) found, err := exec.ScanStruct(&testCrudActionItem{}) assert.EqualError(t, err, expectedErr.Error()) assert.False(t, found) var vals []string assert.EqualError(t, exec.ScanVals(&vals), expectedErr.Error()) var val string found, err = exec.ScanVal(&val) assert.EqualError(t, err, expectedErr.Error()) assert.False(t, found) }
func (me *datasetTest) TestPrepared() { t := me.T() ds := From("test") preparedDs := ds.Prepared(true) assert.True(t, preparedDs.isPrepared) assert.False(t, ds.isPrepared) //should apply the prepared to any datasets created from the root assert.True(t, preparedDs.Where(Ex{"a": 1}).isPrepared) }
func Test_Mock_AssertExpectations_With_Repeatability(t *testing.T) { var mockedService *TestExampleImplementation = new(TestExampleImplementation) mockedService.On("Test_Mock_AssertExpectations_With_Repeatability", 1, 2, 3).Return(5, 6, 7).Twice() tt := new(testing.T) assert.False(t, mockedService.AssertExpectations(tt)) // make the call now mockedService.Called(1, 2, 3) assert.False(t, mockedService.AssertExpectations(tt)) mockedService.Called(1, 2, 3) // now assert expectations assert.True(t, mockedService.AssertExpectations(tt)) }
func Test_Mock_AssertCalled_WithArguments(t *testing.T) { var mockedService *TestExampleImplementation = new(TestExampleImplementation) mockedService.On("Test_Mock_AssertCalled_WithArguments", 1, 2, 3).Return(5, 6, 7) mockedService.Called(1, 2, 3) tt := new(testing.T) assert.True(t, mockedService.AssertCalled(tt, "Test_Mock_AssertCalled_WithArguments", 1, 2, 3)) assert.False(t, mockedService.AssertCalled(tt, "Test_Mock_AssertCalled_WithArguments", 2, 3, 4)) }
func Test_Mock_AssertCalled_WithArguments_With_Repeatability(t *testing.T) { var mockedService *TestExampleImplementation = new(TestExampleImplementation) mockedService.On("Test_Mock_AssertCalled_WithArguments_With_Repeatability", 1, 2, 3).Return(5, 6, 7).Once() mockedService.On("Test_Mock_AssertCalled_WithArguments_With_Repeatability", 2, 3, 4).Return(5, 6, 7).Once() mockedService.Called(1, 2, 3) mockedService.Called(2, 3, 4) tt := new(testing.T) assert.True(t, mockedService.AssertCalled(tt, "Test_Mock_AssertCalled_WithArguments_With_Repeatability", 1, 2, 3)) assert.True(t, mockedService.AssertCalled(tt, "Test_Mock_AssertCalled_WithArguments_With_Repeatability", 2, 3, 4)) assert.False(t, mockedService.AssertCalled(tt, "Test_Mock_AssertCalled_WithArguments_With_Repeatability", 3, 4, 5)) }
func Test_Mock_AssertExpectationsCustomType(t *testing.T) { var mockedService *TestExampleImplementation = new(TestExampleImplementation) mockedService.On("TheExampleMethod3", AnythingOfType("*mock.ExampleType")).Return(nil).Once() tt := new(testing.T) assert.False(t, mockedService.AssertExpectations(tt)) // make the call now mockedService.TheExampleMethod3(&ExampleType{}) // now assert expectations assert.True(t, mockedService.AssertExpectations(tt)) }
func Test_AssertExpectationsForObjects_Helper_Failed(t *testing.T) { var mockedService1 *TestExampleImplementation = new(TestExampleImplementation) var mockedService2 *TestExampleImplementation = new(TestExampleImplementation) var mockedService3 *TestExampleImplementation = new(TestExampleImplementation) mockedService1.On("Test_AssertExpectationsForObjects_Helper_Failed", 1).Return() mockedService2.On("Test_AssertExpectationsForObjects_Helper_Failed", 2).Return() mockedService3.On("Test_AssertExpectationsForObjects_Helper_Failed", 3).Return() mockedService1.Called(1) mockedService3.Called(3) tt := new(testing.T) assert.False(t, AssertExpectationsForObjects(tt, mockedService1.Mock, mockedService2.Mock, mockedService3.Mock)) }
func (me *datasetAdapterTest) TestSupportsReturn() { t := me.T() dsAdapter := me.GetDs("test").Adapter() assert.False(t, dsAdapter.SupportsReturn()) }
// False asserts that the specified value is true. // // require.False(t, myBool, "myBool should be false") func False(t TestingT, value bool, msgAndArgs ...interface{}) { if !assert.False(t, value, msgAndArgs...) { t.FailNow() } }