From 5423e22aeb6a7c9bd100c071a8e738e8876f9572 Mon Sep 17 00:00:00 2001 From: Gusted Date: Fri, 31 Jan 2025 11:44:22 +0100 Subject: [PATCH] chore: Remove `GetSourceByName` - Introduced in 54556053420a8ca37dbd53fbdb6f9251a2db63d9 and removed in the same commit. Usage was purely testing code. --- .deadcode-out | 1 - models/auth/source.go | 11 ----------- tests/integration/integration_test.go | 8 ++------ 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/.deadcode-out b/.deadcode-out index 811b093fe9..e0d158d709 100644 --- a/.deadcode-out +++ b/.deadcode-out @@ -23,7 +23,6 @@ code.gitea.io/gitea/models/actions ScheduleList.LoadRepos code.gitea.io/gitea/models/auth - GetSourceByName WebAuthnCredentials code.gitea.io/gitea/models/db diff --git a/models/auth/source.go b/models/auth/source.go index d03d4975dc..214eb3afa0 100644 --- a/models/auth/source.go +++ b/models/auth/source.go @@ -299,17 +299,6 @@ func GetSourceByID(ctx context.Context, id int64) (*Source, error) { return source, nil } -func GetSourceByName(ctx context.Context, name string) (*Source, error) { - source := &Source{} - has, err := db.GetEngine(ctx).Where("name = ?", name).Get(source) - if err != nil { - return nil, err - } else if !has { - return nil, ErrSourceNotExist{} - } - return source, nil -} - // UpdateSource updates a Source record in DB. func UpdateSource(ctx context.Context, source *Source) error { var originalSource *Source diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 06d2586d1c..7866d297e2 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -298,9 +298,7 @@ func addAuthSource(t *testing.T, payload map[string]string) *auth.Source { payload["_csrf"] = GetCSRF(t, session, "/admin/auths/new") req := NewRequestWithValues(t, "POST", "/admin/auths/new", payload) session.MakeRequest(t, req, http.StatusSeeOther) - source, err := auth.GetSourceByName(context.Background(), payload["name"]) - require.NoError(t, err) - return source + return unittest.AssertExistsAndLoadBean(t, &auth.Source{Name: payload["name"]}) } func authSourcePayloadOAuth2(name string) map[string]string { @@ -358,9 +356,7 @@ func createRemoteAuthSource(t *testing.T, name, url, matchingSource string) *aut MatchingSource: matchingSource, }, })) - source, err := auth.GetSourceByName(context.Background(), name) - require.NoError(t, err) - return source + return unittest.AssertExistsAndLoadBean(t, &auth.Source{Name: name}) } func createUser(ctx context.Context, t testing.TB, user *user_model.User) func() {