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

Function TestRemoteMigration1

pkg/cli/migrate/migrate_test.go:1146–1217  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1144}
1145
1146func TestRemoteMigration1(t *testing.T) {
1147 // set up
1148 db := database.InitTestMemoryDBRaw(t, "./fixtures/remote-1-pre-schema.sql")
1149 ctx := context.InitTestCtxWithDB(t, db)
1150 testutils.Login(t, &ctx)
1151
1152 JSBookUUID := "existing-js-book-uuid"
1153 CSSBookUUID := "existing-css-book-uuid"
1154 linuxBookUUID := "existing-linux-book-uuid"
1155 newJSBookUUID := "new-js-book-uuid"
1156 newCSSBookUUID := "new-css-book-uuid"
1157
1158 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1159 if r.URL.String() == "/v3/books" {
1160 res := []struct {
1161 UUID string `json:"uuid"`
1162 Label string `json:"label"`
1163 }{
1164 {
1165 UUID: newJSBookUUID,
1166 Label: "js",
1167 },
1168 {
1169 UUID: newCSSBookUUID,
1170 Label: "css",
1171 },
1172 // book that only exists on the server. client must ignore.
1173 {
1174 UUID: "golang-book-uuid",
1175 Label: "golang",
1176 },
1177 }
1178
1179 w.Header().Set("Content-Type", "application/json")
1180 if err := json.NewEncoder(w).Encode(res); err != nil {
1181 t.Fatal(errors.Wrap(err, "encoding response"))
1182 }
1183 }
1184 }))
1185 defer server.Close()
1186
1187 ctx.APIEndpoint = server.URL
1188
1189 database.MustExec(t, "inserting js book", db, "INSERT INTO books (uuid, label) VALUES (?, ?)", JSBookUUID, "js")
1190 database.MustExec(t, "inserting css book", db, "INSERT INTO books (uuid, label) VALUES (?, ?)", CSSBookUUID, "css")
1191 database.MustExec(t, "inserting linux book", db, "INSERT INTO books (uuid, label) VALUES (?, ?)", linuxBookUUID, "linux")
1192 database.MustExec(t, "inserting sessionKey", db, "INSERT INTO system (key, value) VALUES (?, ?)", consts.SystemSessionKey, "someSessionKey")
1193 database.MustExec(t, "inserting sessionKeyExpiry", db, "INSERT INTO system (key, value) VALUES (?, ?)", consts.SystemSessionKeyExpiry, time.Now().Add(24*time.Hour).Unix())
1194
1195 tx, err := db.Begin()
1196 if err != nil {
1197 t.Fatal(errors.Wrap(err, "beginning a transaction"))
1198 }
1199
1200 err = rm1.run(ctx, tx)
1201 if err != nil {
1202 tx.Rollback()
1203 t.Fatal(errors.Wrap(err, "failed to run"))

Callers

nothing calls this directly

Calls 12

InitTestMemoryDBRawFunction · 0.92
InitTestCtxWithDBFunction · 0.92
LoginFunction · 0.92
MustExecFunction · 0.92
MustScanFunction · 0.92
EqualFunction · 0.92
CloseMethod · 0.65
NowMethod · 0.65
BeginMethod · 0.65
RollbackMethod · 0.65
CommitMethod · 0.65
QueryRowMethod · 0.65

Tested by

no test coverage detected