migration_28_test.go
TLDR
This file contains a single test function, Test28RemoveTemplateChannelLink
, which tests the removal of a channel link from templates in a database. The test sets up the necessary test environment, executes a migration to a specific database state, checks the initial state of the data, applies the migration being tested, and then checks that the data has been correctly updated as expected.
Methods
Test28RemoveTemplateChannelLink
This method is a test function that verifies the removal of a channel link from templates in a database. It performs the following steps:
- Sets up the test environment.
- Executes a migration to a specific database state using a SQL file.
- Checks the initial state of two struct objects representing a board and a template in the database.
- Applies the migration being tested, which is MigrateToStep(28).
- Re-queries and checks the state of the board and template objects to ensure the changes were correctly applied.
END
package migrationstests
import (
"testing"
"github.com/stretchr/testify/require"
)
func Test28RemoveTemplateChannelLink(t *testing.T) {
t.Run("should correctly remove the channel link from templates", func(t *testing.T) {
th, tearDown := SetupTestHelper(t)
defer tearDown()
th.f.MigrateToStep(27).
ExecFile("./fixtures/test28RemoveTemplateChannelLink.sql")
// first we check that the data has the expected shape
board := struct {
ID string
Is_template bool
Channel_id string
}{}
template := struct {
ID string
Is_template bool
Channel_id string
}{}
bErr := th.f.DB().Get(&board, "SELECT id, is_template, channel_id FROM focalboard_boards WHERE id = 'board-id'")
require.NoError(t, bErr)
require.False(t, board.Is_template)
require.Equal(t, "linked-channel", board.Channel_id)
tErr := th.f.DB().Get(&template, "SELECT id, is_template, channel_id FROM focalboard_boards WHERE id = 'template-id'")
require.NoError(t, tErr)
require.True(t, template.Is_template)
require.Equal(t, "linked-channel", template.Channel_id)
// we apply the migration
th.f.MigrateToStep(28)
// then we reuse the structs to load again the data and check
// that the changes were correctly applied
bErr = th.f.DB().Get(&board, "SELECT id, is_template, channel_id FROM focalboard_boards WHERE id = 'board-id'")
require.NoError(t, bErr)
require.False(t, board.Is_template)
require.Equal(t, "linked-channel", board.Channel_id)
tErr = th.f.DB().Get(&template, "SELECT id, is_template, channel_id FROM focalboard_boards WHERE id = 'template-id'")
require.NoError(t, tErr)
require.True(t, template.Is_template)
require.Empty(t, template.Channel_id)
})
}