From e68b9d00a6e05b3a941f63ffb696f91e554ac5ec Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 18 Oct 2024 20:33:49 +0200 Subject: Adding upstream version 9.0.3. Signed-off-by: Daniel Baumann --- models/migrations/v1_22/v293_test.go | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 models/migrations/v1_22/v293_test.go (limited to 'models/migrations/v1_22/v293_test.go') diff --git a/models/migrations/v1_22/v293_test.go b/models/migrations/v1_22/v293_test.go new file mode 100644 index 0000000..85bb464 --- /dev/null +++ b/models/migrations/v1_22/v293_test.go @@ -0,0 +1,45 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_22 //nolint + +import ( + "testing" + + "code.gitea.io/gitea/models/db" + migration_tests "code.gitea.io/gitea/models/migrations/test" + "code.gitea.io/gitea/models/project" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func Test_CheckProjectColumnsConsistency(t *testing.T) { + // Prepare and load the testing database + x, deferable := migration_tests.PrepareTestEnv(t, 0, new(project.Project), new(project.Column)) + defer deferable() + if x == nil || t.Failed() { + return + } + + require.NoError(t, CheckProjectColumnsConsistency(x)) + + // check if default column was added + var defaultColumn project.Column + has, err := x.Where("project_id=? AND `default` = ?", 1, true).Get(&defaultColumn) + require.NoError(t, err) + assert.True(t, has) + assert.Equal(t, int64(1), defaultColumn.ProjectID) + assert.True(t, defaultColumn.Default) + + // check if multiple defaults, previous were removed and last will be kept + expectDefaultColumn, err := project.GetColumn(db.DefaultContext, 2) + require.NoError(t, err) + assert.Equal(t, int64(2), expectDefaultColumn.ProjectID) + assert.False(t, expectDefaultColumn.Default) + + expectNonDefaultColumn, err := project.GetColumn(db.DefaultContext, 3) + require.NoError(t, err) + assert.Equal(t, int64(2), expectNonDefaultColumn.ProjectID) + assert.True(t, expectNonDefaultColumn.Default) +} -- cgit v1.2.3