2024-03-27 20:54:32 +00:00
|
|
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package v1_22 //nolint
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models/db"
|
2024-07-14 13:34:42 +00:00
|
|
|
migration_tests "code.gitea.io/gitea/models/migrations/test"
|
2024-03-27 20:54:32 +00:00
|
|
|
"code.gitea.io/gitea/models/project"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2024-07-30 19:41:10 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2024-03-27 20:54:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_CheckProjectColumnsConsistency(t *testing.T) {
|
|
|
|
// Prepare and load the testing database
|
2024-07-14 13:34:42 +00:00
|
|
|
x, deferable := migration_tests.PrepareTestEnv(t, 0, new(project.Project), new(project.Column))
|
2024-03-27 20:54:32 +00:00
|
|
|
defer deferable()
|
|
|
|
if x == nil || t.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, CheckProjectColumnsConsistency(x))
|
2024-03-27 20:54:32 +00:00
|
|
|
|
2024-05-27 08:59:54 +00:00
|
|
|
// check if default column was added
|
|
|
|
var defaultColumn project.Column
|
|
|
|
has, err := x.Where("project_id=? AND `default` = ?", 1, true).Get(&defaultColumn)
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, err)
|
2024-03-27 20:54:32 +00:00
|
|
|
assert.True(t, has)
|
2024-05-27 08:59:54 +00:00
|
|
|
assert.Equal(t, int64(1), defaultColumn.ProjectID)
|
|
|
|
assert.True(t, defaultColumn.Default)
|
2024-03-27 20:54:32 +00:00
|
|
|
|
2024-03-28 16:14:30 +00:00
|
|
|
// check if multiple defaults, previous were removed and last will be kept
|
2024-05-27 08:59:54 +00:00
|
|
|
expectDefaultColumn, err := project.GetColumn(db.DefaultContext, 2)
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, err)
|
2024-05-27 08:59:54 +00:00
|
|
|
assert.Equal(t, int64(2), expectDefaultColumn.ProjectID)
|
|
|
|
assert.False(t, expectDefaultColumn.Default)
|
2024-03-27 20:54:32 +00:00
|
|
|
|
2024-05-27 08:59:54 +00:00
|
|
|
expectNonDefaultColumn, err := project.GetColumn(db.DefaultContext, 3)
|
2024-07-30 19:41:10 +00:00
|
|
|
require.NoError(t, err)
|
2024-05-27 08:59:54 +00:00
|
|
|
assert.Equal(t, int64(2), expectNonDefaultColumn.ProjectID)
|
|
|
|
assert.True(t, expectNonDefaultColumn.Default)
|
2024-03-27 20:54:32 +00:00
|
|
|
}
|