(t *testing.T)
| 197 | } |
| 198 | |
| 199 | func TestMigrateToV5(t *testing.T) { |
| 200 | // set up |
| 201 | ctx := setupEnv(t, "../tmp") |
| 202 | defer teardownEnv(t, ctx) |
| 203 | |
| 204 | testutils.CopyFixture(t, ctx, "./fixtures/legacy-5-pre-actions.json", "actions") |
| 205 | |
| 206 | // execute |
| 207 | if err := migrateToV5(ctx); err != nil { |
| 208 | t.Fatal(errors.Wrap(err, "migrating").Error()) |
| 209 | } |
| 210 | |
| 211 | // test |
| 212 | var oldActions []migrateToV5PreAction |
| 213 | testutils.ReadJSON("./fixtures/legacy-5-pre-actions.json", &oldActions) |
| 214 | |
| 215 | b := testutils.ReadFile(ctx, "actions") |
| 216 | var migratedActions []migrateToV5PostAction |
| 217 | if err := json.Unmarshal(b, &migratedActions); err != nil { |
| 218 | t.Fatal(errors.Wrap(err, "unmarshalling migrated actions").Error()) |
| 219 | } |
| 220 | |
| 221 | if len(oldActions) != len(migratedActions) { |
| 222 | t.Fatalf("There were %d actions but after migration there were %d", len(oldActions), len(migratedActions)) |
| 223 | } |
| 224 | |
| 225 | for idx := range migratedActions { |
| 226 | migrated := migratedActions[idx] |
| 227 | old := oldActions[idx] |
| 228 | |
| 229 | assert.NotEqual(t, migrated.UUID, "", fmt.Sprintf("uuid mismatch for migrated item with index %d", idx)) |
| 230 | assert.Equal(t, migrated.Schema, 1, fmt.Sprintf("schema mismatch for migrated item with index %d", idx)) |
| 231 | assert.Equal(t, migrated.Timestamp, old.Timestamp, fmt.Sprintf("timestamp mismatch for migrated item with index %d", idx)) |
| 232 | assert.Equal(t, migrated.Type, old.Type, fmt.Sprintf("timestamp mismatch for migrated item with index %d", idx)) |
| 233 | |
| 234 | switch migrated.Type { |
| 235 | case migrateToV5ActionAddNote: |
| 236 | var oldData, migratedData migrateToV5AddNoteData |
| 237 | if err := json.Unmarshal(old.Data, &oldData); err != nil { |
| 238 | t.Fatal(errors.Wrap(err, "unmarshalling old data").Error()) |
| 239 | } |
| 240 | if err := json.Unmarshal(migrated.Data, &migratedData); err != nil { |
| 241 | t.Fatal(errors.Wrap(err, "unmarshalling new data").Error()) |
| 242 | } |
| 243 | |
| 244 | assert.Equal(t, oldData.BookName, migratedData.BookName, fmt.Sprintf("data book_name mismatch for item idx %d", idx)) |
| 245 | assert.Equal(t, oldData.Content, migratedData.Content, fmt.Sprintf("data content mismatch for item idx %d", idx)) |
| 246 | assert.Equal(t, oldData.NoteUUID, migratedData.NoteUUID, fmt.Sprintf("data note_uuid mismatch for item idx %d", idx)) |
| 247 | case migrateToV5ActionRemoveNote: |
| 248 | var oldData, migratedData migrateToV5RemoveNoteData |
| 249 | if err := json.Unmarshal(old.Data, &oldData); err != nil { |
| 250 | t.Fatal(errors.Wrap(err, "unmarshalling old data").Error()) |
| 251 | } |
| 252 | if err := json.Unmarshal(migrated.Data, &migratedData); err != nil { |
| 253 | t.Fatal(errors.Wrap(err, "unmarshalling new data").Error()) |
| 254 | } |
| 255 | |
| 256 | assert.Equal(t, oldData.BookName, migratedData.BookName, fmt.Sprintf("data book_name mismatch for item idx %d", idx)) |
nothing calls this directly
no test coverage detected