MCPcopy Create free account
hub / github.com/gogs/gogs / TestLoginSource_AfterFind

Function TestLoginSource_AfterFind

internal/database/login_sources_test.go:95–153  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

93}
94
95func TestLoginSource_AfterFind(t *testing.T) {
96 now := time.Now()
97 db := &gorm.DB{
98 Config: &gorm.Config{
99 SkipDefaultTransaction: true,
100 NowFunc: func() time.Time {
101 return now
102 },
103 },
104 }
105
106 tests := []struct {
107 name string
108 authType auth.Type
109 wantType any
110 }{
111 {
112 name: "LDAP",
113 authType: auth.LDAP,
114 wantType: &ldap.Provider{},
115 },
116 {
117 name: "DLDAP",
118 authType: auth.DLDAP,
119 wantType: &ldap.Provider{},
120 },
121 {
122 name: "SMTP",
123 authType: auth.SMTP,
124 wantType: &smtp.Provider{},
125 },
126 {
127 name: "PAM",
128 authType: auth.PAM,
129 wantType: &pam.Provider{},
130 },
131 {
132 name: "GitHub",
133 authType: auth.GitHub,
134 wantType: &github.Provider{},
135 },
136 }
137 for _, test := range tests {
138 t.Run(test.name, func(t *testing.T) {
139 s := LoginSource{
140 Type: test.authType,
141 Config: `{}`,
142 CreatedUnix: now.Unix(),
143 UpdatedUnix: now.Unix(),
144 }
145 err := s.AfterFind(db)
146 require.NoError(t, err)
147
148 assert.Equal(t, s.CreatedUnix, s.Created.Unix())
149 assert.Equal(t, s.UpdatedUnix, s.Updated.Unix())
150 assert.IsType(t, test.wantType, s.Provider)
151 })
152 }

Callers

nothing calls this directly

Calls 1

AfterFindMethod · 0.95

Tested by

no test coverage detected