MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / TestStorage

Function TestStorage

storage/storage_test.go:111–378  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

109}
110
111func TestStorage(t *testing.T) {
112 fl, err := ioutil.TempFile("", "sqlite3-")
113
114 if err != nil {
115 t.Fatalf("error occurred: %v", err)
116 }
117
118 st, err := New(fmt.Sprintf("file:%s", fl.Name()))
119 defer st.Close()
120
121 if err != nil {
122 t.Fatalf("error occurred: %v", err)
123 }
124
125 el1 := &ExecLog{
126 ConnectionID: 1,
127 SeqNo: 1,
128 Timestamp: time.Now().UnixNano(),
129 Queries: []Query{
130 newQuery("CREATE TABLE IF NOT EXISTS `kv` (`key` TEXT PRIMARY KEY, `value` BLOB)"),
131 newQuery("INSERT OR IGNORE INTO `kv` VALUES ('k0', NULL)"),
132 newQuery("INSERT OR IGNORE INTO `kv` VALUES ('k1', 'v1')"),
133 newQuery("INSERT OR IGNORE INTO `kv` VALUES ('k2', 'v2')"),
134 newQuery("INSERT OR IGNORE INTO `kv` VALUES ('k3', 'v3')"),
135 newQuery("INSERT OR REPLACE INTO `kv` VALUES ('k3', 'v3-2')"),
136 newQuery("DELETE FROM `kv` WHERE `key`='k2'"),
137 },
138 }
139
140 el2 := &ExecLog{
141 ConnectionID: 1,
142 SeqNo: 2,
143 Timestamp: time.Now().UnixNano(),
144 Queries: []Query{
145 newQuery("INSERT OR REPLACE INTO `kv` VALUES ('k1', 'v1-2')"),
146 },
147 }
148
149 if err = st.Prepare(context.Background(), el1); err != nil {
150 t.Fatalf("error occurred: %v", err)
151 }
152
153 if err = st.Prepare(context.Background(), el1); err != nil {
154 t.Fatalf("error occurred: %v", err)
155 }
156
157 if err = st.Prepare(context.Background(), el2); err == nil {
158 t.Fatal("unexpected result: returned nil while expecting an error")
159 } else {
160 t.Logf("Error occurred as expected: %v", err)
161 }
162
163 if _, err = st.Commit(context.Background(), el2); err == nil {
164 t.Fatal("unexpected result: returned nil while expecting an error")
165 } else {
166 t.Logf("Error occurred as expected: %v", err)
167 }
168

Callers

nothing calls this directly

Calls 14

newQueryFunction · 0.85
newNamedQueryFunction · 0.85
FatalfMethod · 0.80
NameMethod · 0.80
FatalMethod · 0.80
ErrorMethod · 0.80
NewFunction · 0.70
CloseMethod · 0.65
PrepareMethod · 0.65
CommitMethod · 0.65
RollbackMethod · 0.65
QueryMethod · 0.65

Tested by

no test coverage detected