summaryrefslogtreecommitdiffstats
path: root/models/migrations/v1_18/v230_test.go
blob: 0af13a1b9ee5ff07d4e35be38b25669c72aa6ee2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package v1_18 //nolint

import (
	"testing"

	"code.gitea.io/gitea/models/migrations/base"

	"github.com/stretchr/testify/assert"
)

func Test_AddConfidentialClientColumnToOAuth2ApplicationTable(t *testing.T) {
	// premigration
	type OAuth2Application struct {
		ID int64
	}

	// Prepare and load the testing database
	x, deferable := base.PrepareTestEnv(t, 0, new(OAuth2Application))
	defer deferable()
	if x == nil || t.Failed() {
		return
	}

	if err := AddConfidentialClientColumnToOAuth2ApplicationTable(x); err != nil {
		assert.NoError(t, err)
		return
	}

	// postmigration
	type ExpectedOAuth2Application struct {
		ID                 int64
		ConfidentialClient bool
	}

	got := []ExpectedOAuth2Application{}
	if err := x.Table("o_auth2_application").Select("id, confidential_client").Find(&got); !assert.NoError(t, err) {
		return
	}

	assert.NotEmpty(t, got)
	for _, e := range got {
		assert.True(t, e.ConfidentialClient)
	}
}