title: How to test transaction rollback and commit in go lang
body: <p>I have such code:</p>
  
  <pre><code>tx, _ := db.Begin()
  defer tx.Rollback()
  
  err := db.Insert(foo)
  err = db.Delete(bar)
  
  if !err {
    tx.Commit()
  }
  </code></pre>
  
  <p>and I don't have idea how to write 2 test cases:</p>
  
  <ul>
  <li>successfull (data inserted and deleted)</li>
  <li>error (nothing changes)</li>
  </ul>
  
  <p>I was thinking about:</p>
  
  <ul>
  <li>monkey patching by function injection to method which is doing db operations, and change this function in test</li>
  <li>monkey patching by changing <code>foo</code> sql by making it global - I don't like it too much</li>
  <li>make db not allowing delete operation for test time</li>
  </ul>
  
  <p>Each of above options seems to be not ideal, how should I write this test cases?</p>