MCPcopy Index your code
hub / github.com/Masterminds/structable / TestStructWithPointerLoad

Function TestStructWithPointerLoad

sqlite_ptr_test.go:93–123  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

91}
92
93func TestStructWithPointerLoad(t *testing.T) {
94
95 db := getMoviesDb()
96
97 msql := &Movie{}
98 if res, err := db.Exec("INSERT INTO movies (title, genre, budget) VALUES ('2001: A Space Odyssey', 'Science-Fiction', 1500000)"); err != nil {
99 t.Fatalf("Sqlite Exec failed: %s", err)
100 } else if msql.Id, err = res.LastInsertId(); err != nil {
101 t.Fatalf("Sqlite LastInsertId failed: %s", err)
102 }
103
104 m := &Movie{Id: msql.Id, Genre: new(string)}
105 m.Recorder = New(squirrel.NewStmtCacheProxy(db), "mysql").Bind("movies", m)
106 if err := m.Load(); err != nil {
107 t.Fatalf("Failed Load: %s", err)
108 }
109
110 if !CompareStringPtr(m.Genre, stringPtr("Science-Fiction")) {
111 t.Fatal("Load should load pointer fields")
112 }
113
114 m.Genre = nil
115 m.Recorder = New(squirrel.NewStmtCacheProxy(db), "mysql").Bind("movies", m)
116 if err := m.Load(); err != nil {
117 t.Fatalf("Failed Load: %s", err)
118 }
119
120 if !CompareStringPtr(m.Genre, stringPtr("Science-Fiction")) {
121 t.Fatal("Load should instantiate nil pointers")
122 }
123}
124
125func TestStructWithPointerLoadWhere(t *testing.T) {
126

Callers

nothing calls this directly

Calls 8

getMoviesDbFunction · 0.85
NewFunction · 0.85
CompareStringPtrFunction · 0.85
stringPtrFunction · 0.85
ExecMethod · 0.80
LastInsertIdMethod · 0.80
BindMethod · 0.65
LoadMethod · 0.65

Tested by

no test coverage detected