MCPcopy Index your code
hub / github.com/dnote/dnote / TestNoteInsert

Function TestNoteInsert

pkg/cli/database/models_test.go:73–154  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

71}
72
73func TestNoteInsert(t *testing.T) {
74 testCases := []struct {
75 uuid string
76 bookUUID string
77 body string
78 addedOn int64
79 editedOn int64
80 usn int
81 deleted bool
82 dirty bool
83 }{
84 {
85 uuid: "n1-uuid",
86 bookUUID: "b1-uuid",
87 body: "n1-body",
88 addedOn: 1542058875,
89 editedOn: 0,
90 usn: 0,
91 deleted: false,
92 dirty: false,
93 },
94 {
95 uuid: "n2-uuid",
96 bookUUID: "b2-uuid",
97 body: "n2-body",
98 addedOn: 1542058875,
99 editedOn: 1542058876,
100 usn: 1008,
101 deleted: true,
102 dirty: true,
103 },
104 }
105
106 for idx, tc := range testCases {
107 func() {
108 // Setup
109 db := InitTestMemoryDB(t)
110
111 n := Note{
112 UUID: tc.uuid,
113 BookUUID: tc.bookUUID,
114 Body: tc.body,
115 AddedOn: tc.addedOn,
116 EditedOn: tc.editedOn,
117 USN: tc.usn,
118 Deleted: tc.deleted,
119 Dirty: tc.dirty,
120 }
121
122 // execute
123 tx, err := db.Begin()
124 if err != nil {
125 t.Fatal(errors.Wrap(err, fmt.Sprintf("beginning a transaction for test case %d", idx)).Error())
126 }
127
128 if err := n.Insert(tx); err != nil {
129 tx.Rollback()
130 t.Fatal(errors.Wrap(err, fmt.Sprintf("executing for test case %d", idx)).Error())

Callers

nothing calls this directly

Calls 9

InsertMethod · 0.95
EqualFunction · 0.92
InitTestMemoryDBFunction · 0.85
MustScanFunction · 0.85
BeginMethod · 0.65
RollbackMethod · 0.65
CommitMethod · 0.65
QueryRowMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected