code.gitea.io/gitea@v1.21.7/models/migrations/v1_18/v230_test.go (about) 1 // Copyright 2022 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package v1_18 //nolint 5 6 import ( 7 "testing" 8 9 "code.gitea.io/gitea/models/migrations/base" 10 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func Test_AddConfidentialClientColumnToOAuth2ApplicationTable(t *testing.T) { 15 // premigration 16 type OAuth2Application struct { 17 ID int64 18 } 19 20 // Prepare and load the testing database 21 x, deferable := base.PrepareTestEnv(t, 0, new(OAuth2Application)) 22 defer deferable() 23 if x == nil || t.Failed() { 24 return 25 } 26 27 if err := AddConfidentialClientColumnToOAuth2ApplicationTable(x); err != nil { 28 assert.NoError(t, err) 29 return 30 } 31 32 // postmigration 33 type ExpectedOAuth2Application struct { 34 ID int64 35 ConfidentialClient bool 36 } 37 38 got := []ExpectedOAuth2Application{} 39 if err := x.Table("o_auth2_application").Select("id, confidential_client").Find(&got); !assert.NoError(t, err) { 40 return 41 } 42 43 assert.NotEmpty(t, got) 44 for _, e := range got { 45 assert.True(t, e.ConfidentialClient) 46 } 47 }