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

Function TestStructWithPointerInsert

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

Source from the content-addressed store, hash-verified

57}
58
59func 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
93func TestStructWithPointerLoad(t *testing.T) {
94

Callers

nothing calls this directly

Calls 6

getMoviesDbFunction · 0.85
stringPtrFunction · 0.85
NewFunction · 0.85
BindMethod · 0.65
InsertMethod · 0.65
loadFromSqlMethod · 0.45

Tested by

no test coverage detected