1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-07-24 20:19:39 +02:00

chore: add tests for admin auth subcommands (#8433)

This PR is adds almost all tests in `cmd/admin_auth_oauth_test.go` with a bit of refactoring beforehand to make the tests easier to write. These should be legitimate refactors where the implementation changes but the public API/behavior does not change. All of the changes in this PR are done to align with how tests are written in `cmd/admin_auth_ldap_test.go`. Since `cmd/admin_auth_ldap.go` is a sibling file to `cmd/admin_auth_oauth.go`, it seems like their test files should also be aligned.

There are some tests added that show the current behavior as not ideal. E.g. not being able to update certain fields, or being able to set fields that are ultimately ignored. These are added so that the behavior is at least shown a bit more visibly. There should likely be a follow-up to fix some of these issues. But that will almost certainly be a breaking change that I'd rather avoid in this PR.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8433
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Co-authored-by: joneshf <jones3.hardy@gmail.com>
Co-committed-by: joneshf <jones3.hardy@gmail.com>
This commit is contained in:
joneshf 2025-07-09 20:55:10 +02:00 committed by Gusted
parent 32e8610b20
commit 48035bbd4e
4 changed files with 732 additions and 28 deletions

View file

@ -17,6 +17,15 @@ import (
"github.com/urfave/cli/v3"
)
type (
authService struct {
initDB func(ctx context.Context) error
createAuthSource func(context.Context, *auth_model.Source) error
updateAuthSource func(context.Context, *auth_model.Source) error
getAuthSourceByID func(ctx context.Context, id int64) (*auth_model.Source, error)
}
)
func microcmdAuthDelete() *cli.Command {
return &cli.Command{
Name: "delete",
@ -60,6 +69,16 @@ func microcmdAuthList() *cli.Command {
}
}
// newAuthService creates a service with default functions.
func newAuthService() *authService {
return &authService{
initDB: initDB,
createAuthSource: auth_model.CreateSource,
updateAuthSource: auth_model.UpdateSource,
getAuthSourceByID: auth_model.GetSourceByID,
}
}
func runListAuth(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals(ctx)
defer cancel()