From 3bcd3e4697fc77a0e553c5a390ef9de2ffa45772 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Fri, 27 Aug 2021 20:07:10 +0100 Subject: [PATCH] Add test to ensure that dumping of login sources remains correct (#16847) #16831 has occurred because of a missed regression. This PR adds a simple test to try to prevent this occuring again. Signed-off-by: Andrew Thornton --- models/models_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/models/models_test.go b/models/models_test.go index 9793394e0b6f..626856df7d87 100644 --- a/models/models_test.go +++ b/models/models_test.go @@ -8,9 +8,12 @@ import ( "io/ioutil" "os" "path/filepath" + "strings" "testing" + "code.gitea.io/gitea/modules/auth/oauth2" "code.gitea.io/gitea/modules/setting" + "xorm.io/xorm/schemas" "github.com/stretchr/testify/assert" ) @@ -32,3 +35,26 @@ func TestDumpDatabase(t *testing.T) { assert.NoError(t, DumpDatabase(filepath.Join(dir, dbType+".sql"), dbType)) } } + +func TestDumpLoginSource(t *testing.T) { + assert.NoError(t, PrepareTestDatabase()) + + loginSourceSchema, err := x.TableInfo(new(LoginSource)) + assert.NoError(t, err) + + CreateLoginSource(&LoginSource{ + Type: LoginOAuth2, + Name: "TestSource", + IsActived: false, + Cfg: &OAuth2Config{ + Provider: "TestSourceProvider", + CustomURLMapping: &oauth2.CustomURLMapping{}, + }, + }) + + sb := new(strings.Builder) + + x.DumpTables([]*schemas.Table{loginSourceSchema}, sb) + + assert.Contains(t, sb.String(), `"Provider":"TestSourceProvider"`) +}