(t *testing.T)
| 57 | } |
| 58 | |
| 59 | func TestStructWithPointerInsert(t *testing.T) { |
| 60 | |
| 61 | db := getMoviesDb() |
| 62 | |
| 63 | m := &Movie{ |
| 64 | Id: -1, |
| 65 | Title: "2001: A Space Odyssey", |
| 66 | Genre: stringPtr("Science-Fiction"), |
| 67 | Budget: 1500000} |
| 68 | m.Recorder = New(squirrel.NewStmtCacheProxy(db), "mysql").Bind("movies", m) |
| 69 | |
| 70 | if err := m.Insert(); err != nil { |
| 71 | t.Fatalf("Failed Insert: %s", err) |
| 72 | } |
| 73 | |
| 74 | msql := new(Movie) |
| 75 | msql.loadFromSql(m.Id, db) |
| 76 | |
| 77 | if *msql.Genre != "Science-Fiction" { |
| 78 | t.Fatal("Insert should dereference allocated pointers") |
| 79 | } |
| 80 | |
| 81 | m.Genre = nil |
| 82 | if err := m.Insert(); err != nil { |
| 83 | t.Fatalf("Failed Insert: %s", err) |
| 84 | } |
| 85 | |
| 86 | msql.loadFromSql(m.Id, db) |
| 87 | |
| 88 | if *msql.Genre != "unclassifiable" { |
| 89 | t.Fatal("Insert should ignore nil pointers") |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | func TestStructWithPointerLoad(t *testing.T) { |
| 94 |
nothing calls this directly
no test coverage detected