title: sqlmock with gorm INSERT
body: <p>I'm having a lot of trouble mocking gorm INSERT queries. I was able to get my tests passing when selecting fine, but I am running into this error when inserting.</p>
  
  <pre><code># gorms's debug output
  INSERT INTO "groups" ("created_at","updated_at","deleted_at","name","description") VALUES ('2018-05-01 17:46:15','2018-05-01 17:46:15',NULL,'Group 1','A good group') RETURNING "groups"."id"
  
  # Error returned from *gorm.DB.Create
  2018/05/01 17:46:15 Error creating group: call to Query 'INSERT INTO "groups" ("created_at","updated_at","deleted_at","name","description") VALUES ($1,$2,$3,$4,$5) RETURNING "groups"."id"' with args [{Name: Ordinal:1 Value:2018-05-01 17:46:15.384319544 -0700 PDT m=+0.005382104} {Name: Ordinal:2 Value:2018-05-01 17:46:15.384319544 -0700 PDT m=+0.005382104} {Name: Ordinal:3 Value:&lt;nil&gt;} {Name: Ordinal:4 Value:Group 1} {Name: Ordinal:5 Value:A good group}], was not expected, next expectation is: ExpectedExec =&gt; expecting Exec or ExecContext which:
    - matches sql: '^INSERT INTO "groups" (.+)$'
    - is with arguments:
      0 - {}
      1 - {}
      2 - &lt;nil&gt;
      3 - Group 1
      4 - A good group
    - should return Result having:
        LastInsertId: 1
        RowsAffected: 1
  </code></pre>
  
  <p>I have tried multiple different versions of the regex, even tested the match using golang on regex101.com, but I can't seem to get my sqlmock to match gorm's insert.</p>
  
  <p>Here is my test:</p>
  
  <pre><code>type AnyTime struct{} // I don't actually know if I even need this
  
  func (a AnyTime) Match(v driver.Value) bool {
      _, ok := v.(time.Time)
      return ok
  }
  
  func TestGroupService_Create(t *testing.T) {
      db, mock, err := sqlmock.New()
      if err != nil {
          log.Fatalf("can't create sqlmock: %s", err)
      }
      models.DB, err = gorm.Open("postgres", db)
      if err != nil {
          log.Fatalf("can't open gorm connection: %s", err)
      }
      defer db.Close()
  
      models.DB.LogMode(true)
  
      name := "Group 1"
      description := "A good group"
  
      mock.ExpectExec("^INSERT INTO \"groups\" (.+)$").WithArgs(AnyTime{}, AnyTime{}, nil, name, description).WillReturnResult(sqlmock.NewResult(1, 1))
  
      s := GroupService{}
  
      req := &amp;pb.CreateGroupRequest{
          Name: name,
          Description: description,
      }
  
      resp, err := s.Create(context.Background(), req)
      assert.Nil(t, err)
  
      if assert.NotNil(t, resp) {
          assert.Equal(t, resp.Group.Name, name)
          assert.Equal(t, resp.Group.Description, description)
      }
  
      err = mock.ExpectationsWereMet()
      assert.Nil(t, err)
  }
  </code></pre>
  
  <p>and my service method I'm trying to test:</p>
  
  <pre><code>func (server *GroupService) Create(ctx context.Context, request *pb.CreateGroupRequest) (*pb.CreateGroupReply, error) {
      var group models.Group
  
      group.Name = request.Name
      group.Description = request.Description
  
      db := models.DB
  
      if err := db.Create(&amp;group).Error; err != nil {
          log.Printf("Error creating group: %v", err)
          return nil, err
      }
  
      createReply := pb.CreateGroupReply{
          Group: mapGroupToService(group),
      }
  
      return &amp;createReply, nil
  }
  </code></pre>
  
  <p>I just can't seem to figure this out. Thanks!</p>