Last active
January 27, 2019 08:39
-
-
Save jarifibrahim/3650b2dc27a292008efd43c3b346c63a to your computer and use it in GitHub Desktop.
Gist showing a not-so-cool way of deleting test fixtures
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"database/sql" | |
"testing" | |
"github.com/jinzhu/gorm" | |
_ "github.com/jinzhu/gorm/dialects/sqlite" | |
) | |
type Product struct { | |
gorm.Model | |
Code string | |
Price uint | |
} | |
// Error checking intentionally skipped at some places | |
func TestCleanup(t *testing.T) { | |
db, _ := gorm.Open("sqlite3", "test.db") | |
defer db.Close() | |
// Create | |
db.Create(&Product{Code: "foo", Price: 100}) | |
db.Create(&Product{Code: "bar", Price: 2000}) | |
db.Create(&Product{Code: "fooBar", Price: 400}) | |
// Perform some test here | |
// ... | |
// ... | |
var product Product | |
db.Delete(&product, "code = ?", "foo") | |
db.Delete(&product, "code = ?", "foo") | |
db.Delete(&product, "code = ?", "foo") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment