title: How to test mysql insert method
body: <p>I'm setting up <code>testing</code> in Go. I use <code>go-sqlmock</code> to test <code>mysql</code> connection. Now I try to test mysql <code>insert</code> logic. But the error occurs.<br>
  I want to know how to resolve this error.</p>
  
  <pre><code>server side: golang
  db: mysql
  web framework: gin
  </code></pre>
  
  <p>dao.go</p>
  
  <pre class="lang-golang prettyprint-override"><code>func PostDao(db *sql.DB, article util.Article, uu string) {
      ins, err := db.Prepare("INSERT INTO articles(uuid, title,content) VALUES(?,?,?)")
      if err != nil {
          log.Fatal(err)
      }
      ins.Exec(uu, article.TITLE, article.CONTENT)
  }
  </code></pre>
  
  <p>dao_test.go</p>
  
  <pre class="lang-golang prettyprint-override"><code>func TestPostArticleDao(t *testing.T) {
      db, mock, err := sqlmock.New()
  
      if err != nil {
          t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
      }
  
      defer db.Close()
  
      mock.ExpectExec("^INSERT INTO articles*").
          WithArgs("bea1b24d-0627-4ea0-aa2b-8af4c6c2a41c", "test", "test").
          WillReturnResult(sqlmock.NewResult(1, 1))
  
      article := util.Article{
          ID:      1,
          TITLE:   "test",
          CONTENT: "test",
      }
  
      PostDao(db, article, "bea1b24d-0627-4ea0-aa2b-8af4c6c2a41c")
  
      if err := mock.ExpectationsWereMet(); err != nil {
          t.Errorf("there were unfulfilled expections: %s", err)
      }
  }
  </code></pre>
  
  <p>I expect <code>go test -v</code> runs without error.<br>
  But the actual is not.<br>
  Here is the error.<br></p>
  
  <pre><code>=== RUN   TestPostArticleDao
  2019/08/31 00:08:11 call to Prepare statement with query 'INSERT INTO articles(uuid, title,content) VALUES(?,?,?)', was not expected, next expectation is: ExpectedExec =&gt; expecting Exec or ExecContext which:
    - matches sql: 'INSERT INTO articles(uuid, title,content) VALUES(?,?,?)'
    - is with arguments:
      0 - bea1b24d-0627-4ea0-aa2b-8af4c6c2a41c
      1 - test
      2 - test
    - should return Result having:
        LastInsertId: 1
        RowsAffected: 1
  exit status 1
  FAIL    article/api/dao 0.022s
  </code></pre>