1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-18 11:46:23 -07:00

Move board migration testing for pre2021 to a separate file

This commit is contained in:
Eggbertx 2025-01-02 20:36:19 -08:00
parent 00fbd8f6c3
commit d19f0eebe3
2 changed files with 77 additions and 69 deletions

View file

@ -0,0 +1,77 @@
package pre2021
import (
"testing"
"github.com/gochan-org/gochan/pkg/gcsql"
"github.com/stretchr/testify/assert"
)
func TestMigrateBoardsToNewDB(t *testing.T) {
outDir := t.TempDir()
migrator := setupMigrationTest(t, outDir, false)
if !assert.False(t, migrator.IsMigratingInPlace(), "This test should not be migrating in place") {
t.FailNow()
}
assert.NoError(t, gcsql.ResetBoardSectionArrays())
numBoards := len(gcsql.AllBoards)
numSections := len(gcsql.AllSections)
assert.Equal(t, 1, numBoards, "Expected to have 1 board pre-migration (/test/ is automatically created during provisioning)")
assert.Equal(t, 1, numSections, "Expected to have 1 section pre-migration (Main is automatically created during provisioning)")
if !assert.NoError(t, migrator.MigrateBoards()) {
t.FailNow()
}
migratedBoards, err := gcsql.GetAllBoards(false)
if !assert.NoError(t, err) {
t.FailNow()
}
migratedSections, err := gcsql.GetAllSections(false)
if !assert.NoError(t, err) {
t.FailNow()
}
assert.Equal(t, len(migratedBoards), 2, "Expected updated boards list to have two boards")
assert.Equal(t, len(migratedSections), 2, "Expected updated sections list to have two sections")
// Test migrated sections
mainSection, err := gcsql.GetSectionFromName("Main")
if !assert.NoError(t, err) {
t.FailNow()
}
assert.Equal(t, "mainmigration", mainSection.Abbreviation, "Expected Main section to have updated abbreviation name 'mainmigration'")
// Test migrated boards
testBoard, err := gcsql.GetBoardFromDir("test")
if !assert.NoError(t, err) {
t.FailNow()
}
assert.Equal(t, "Testing Board", testBoard.Title)
assert.Equal(t, "Board for testing pre-2021 migration", testBoard.Subtitle)
testBoardSection, err := gcsql.GetSectionFromID(testBoard.SectionID)
if !assert.NoError(t, err) {
t.FailNow()
}
assert.Equal(t, "Main", testBoardSection.Name, "Expected /test/ board to be in Main section")
hiddenBoard, err := gcsql.GetBoardFromDir("hidden")
if !assert.NoError(t, err) {
t.FailNow()
}
assert.Equal(t, "Hidden Board", hiddenBoard.Title)
}
func TestMigrateBoardsInPlace(t *testing.T) {
outDir := t.TempDir()
migrator := setupMigrationTest(t, outDir, true)
if !assert.True(t, migrator.IsMigratingInPlace(), "This test should be migrating in place") {
t.FailNow()
}
if !assert.Error(t, migrator.MigrateBoards(), "Not yet implemented") {
t.FailNow()
}
}

View file

@ -84,72 +84,3 @@ func setupMigrationTest(t *testing.T, outDir string, migrateInPlace bool) *Pre20
return migrator
}
func TestMigrateBoardsToNewDB(t *testing.T) {
outDir := t.TempDir()
migrator := setupMigrationTest(t, outDir, false)
if !assert.False(t, migrator.IsMigratingInPlace(), "This test should not be migrating in place") {
t.FailNow()
}
assert.NoError(t, gcsql.ResetBoardSectionArrays())
numBoards := len(gcsql.AllBoards)
numSections := len(gcsql.AllSections)
assert.Equal(t, 1, numBoards, "Expected to have 1 board pre-migration (/test/ is automatically created during provisioning)")
assert.Equal(t, 1, numSections, "Expected to have 1 section pre-migration (Main is automatically created during provisioning)")
if !assert.NoError(t, migrator.MigrateBoards()) {
t.FailNow()
}
migratedBoards, err := gcsql.GetAllBoards(false)
if !assert.NoError(t, err) {
t.FailNow()
}
migratedSections, err := gcsql.GetAllSections(false)
if !assert.NoError(t, err) {
t.FailNow()
}
assert.Equal(t, len(migratedBoards), 2, "Expected updated boards list to have two boards")
assert.Equal(t, len(migratedSections), 2, "Expected updated sections list to have two sections")
// Test migrated sections
mainSection, err := gcsql.GetSectionFromName("Main")
if !assert.NoError(t, err) {
t.FailNow()
}
assert.Equal(t, "mainmigration", mainSection.Abbreviation, "Expected Main section to have updated abbreviation name 'mainmigration'")
// Test migrated boards
testBoard, err := gcsql.GetBoardFromDir("test")
if !assert.NoError(t, err) {
t.FailNow()
}
assert.Equal(t, "Testing Board", testBoard.Title)
assert.Equal(t, "Board for testing pre-2021 migration", testBoard.Subtitle)
testBoardSection, err := gcsql.GetSectionFromID(testBoard.SectionID)
if !assert.NoError(t, err) {
t.FailNow()
}
assert.Equal(t, "Main", testBoardSection.Name, "Expected /test/ board to be in Main section")
hiddenBoard, err := gcsql.GetBoardFromDir("hidden")
if !assert.NoError(t, err) {
t.FailNow()
}
assert.Equal(t, "Hidden Board", hiddenBoard.Title)
}
func TestMigrateBoardsInPlace(t *testing.T) {
outDir := t.TempDir()
migrator := setupMigrationTest(t, outDir, true)
if !assert.True(t, migrator.IsMigratingInPlace(), "This test should be migrating in place") {
t.FailNow()
}
if !assert.Error(t, migrator.MigrateBoards(), "Not yet implemented") {
t.FailNow()
}
}