5
5
package models
6
6
7
7
import (
8
+ "encoding/json"
8
9
"io/ioutil"
9
10
"os"
10
11
"path/filepath"
12
+ "strings"
11
13
"testing"
12
14
13
15
"code.gitea.io/gitea/modules/setting"
16
+ "xorm.io/xorm/schemas"
14
17
15
18
"github.com/stretchr/testify/assert"
16
19
)
@@ -32,3 +35,46 @@ func TestDumpDatabase(t *testing.T) {
32
35
assert .NoError (t , DumpDatabase (filepath .Join (dir , dbType + ".sql" ), dbType ))
33
36
}
34
37
}
38
+
39
+ type TestSource struct {
40
+ Provider string
41
+ ClientID string
42
+ ClientSecret string
43
+ OpenIDConnectAutoDiscoveryURL string
44
+ IconURL string
45
+ }
46
+
47
+ // FromDB fills up a LDAPConfig from serialized format.
48
+ func (source * TestSource ) FromDB (bs []byte ) error {
49
+ return json .Unmarshal (bs , & source )
50
+ }
51
+
52
+ // ToDB exports a LDAPConfig to a serialized format.
53
+ func (source * TestSource ) ToDB () ([]byte , error ) {
54
+ return json .Marshal (source )
55
+ }
56
+
57
+ func TestDumpLoginSource (t * testing.T ) {
58
+ assert .NoError (t , PrepareTestDatabase ())
59
+
60
+ loginSourceSchema , err := x .TableInfo (new (LoginSource ))
61
+ assert .NoError (t , err )
62
+
63
+ RegisterLoginTypeConfig (LoginOAuth2 , new (TestSource ))
64
+
65
+ CreateLoginSource (& LoginSource {
66
+ Type : LoginOAuth2 ,
67
+ Name : "TestSource" ,
68
+ IsActive : false ,
69
+ Cfg : & TestSource {
70
+ Provider : "ConvertibleSourceName" ,
71
+ ClientID : "42" ,
72
+ },
73
+ })
74
+
75
+ sb := new (strings.Builder )
76
+
77
+ x .DumpTables ([]* schemas.Table {loginSourceSchema }, sb )
78
+
79
+ assert .Contains (t , sb .String (), `"Provider":"ConvertibleSourceName"` )
80
+ }
0 commit comments