mirror of
https://github.com/coder/coder.git
synced 2026-10-31 02:43:21 +08:00
refactor: upgrade golangci-lint to v2.0.2 (#28416)
This commit is contained in:
@@ -2283,8 +2283,7 @@ func (q *querier) DeleteExpiredAPIKeys(ctx context.Context, arg database.DeleteE
|
||||
|
||||
func (q *querier) DeleteExternalAuthLink(ctx context.Context, arg database.DeleteExternalAuthLinkParams) error {
|
||||
return fetchAndExec(q.log, q.auth, policy.ActionUpdatePersonal, func(ctx context.Context, arg database.DeleteExternalAuthLinkParams) (database.ExternalAuthLink, error) {
|
||||
//nolint:gosimple
|
||||
return q.db.GetExternalAuthLink(ctx, database.GetExternalAuthLinkParams{UserID: arg.UserID, ProviderID: arg.ProviderID})
|
||||
return q.db.GetExternalAuthLink(ctx, database.GetExternalAuthLinkParams(arg))
|
||||
}, q.db.DeleteExternalAuthLink)(ctx, arg)
|
||||
}
|
||||
|
||||
@@ -9028,7 +9027,7 @@ func (q *querier) UpsertChatTitleGenerationModelOverride(ctx context.Context, va
|
||||
return q.db.UpsertChatTitleGenerationModelOverride(ctx, value)
|
||||
}
|
||||
|
||||
//nolint:revive // Parameter name matches the generated querier interface.
|
||||
//nolint:revive,staticcheck // Parameter name matches the generated querier interface.
|
||||
func (q *querier) UpsertChatWorkspaceTTL(ctx context.Context, workspaceTtl string) error {
|
||||
if err := q.authorizeContext(ctx, policy.ActionUpdate, rbac.ResourceDeploymentConfig); err != nil {
|
||||
return err
|
||||
|
||||
@@ -803,7 +803,7 @@ func WorkspaceAgentScriptTiming(t testing.TB, db database.Store, orig database.W
|
||||
}
|
||||
// Some tests run WorkspaceAgentScriptTiming in a loop and run into
|
||||
// a unique violation - 2 rows get the same started_at value.
|
||||
if (database.IsUniqueViolation(err, database.UniqueWorkspaceAgentScriptTimingsScriptIDStartedAtKey) && orig.StartedAt == time.Time{}) {
|
||||
if (database.IsUniqueViolation(err, database.UniqueWorkspaceAgentScriptTimingsScriptIDStartedAtKey) && orig.StartedAt.Equal(time.Time{})) {
|
||||
// Wait 1 millisecond so dbtime.Now() changes
|
||||
time.Sleep(time.Millisecond * 1)
|
||||
continue
|
||||
@@ -1174,7 +1174,7 @@ func GroupMember(t testing.TB, db database.Store, member database.GroupMemberTab
|
||||
require.NotEqual(t, member.UserID, uuid.Nil, "A user id is required to use 'dbgen.GroupMember', use 'dbgen.User'.")
|
||||
require.NotEqual(t, member.GroupID, uuid.Nil, "A group id is required to use 'dbgen.GroupMember', use 'dbgen.Group'.")
|
||||
|
||||
//nolint:gosimple
|
||||
//nolint:staticcheck
|
||||
err := db.InsertGroupMember(genCtx, database.InsertGroupMemberParams{
|
||||
UserID: member.UserID,
|
||||
GroupID: member.GroupID,
|
||||
|
||||
@@ -197,8 +197,8 @@ func createDatabaseFromTemplate(t TBSubset, connParams ConnectionParams, db *sql
|
||||
// Template database already exists and we successfully created the new database.
|
||||
return nil
|
||||
}
|
||||
tplDbDoesNotExistOccurred := strings.Contains(err.Error(), "template database") && strings.Contains(err.Error(), "does not exist")
|
||||
if (tplDbDoesNotExistOccurred && !emptyTemplateDBName) || !tplDbDoesNotExistOccurred {
|
||||
tplDBDoesNotExistOccurred := strings.Contains(err.Error(), "template database") && strings.Contains(err.Error(), "does not exist")
|
||||
if (tplDBDoesNotExistOccurred && !emptyTemplateDBName) || !tplDBDoesNotExistOccurred {
|
||||
// First and case: user passed a templateDBName that doesn't exist.
|
||||
// Second and case: some other error.
|
||||
return xerrors.Errorf("create db with template: %w", err)
|
||||
@@ -273,26 +273,26 @@ func createAndInitDatabase(t TBSubset, connParams ConnectionParams, db *sql.DB,
|
||||
if _, err := db.Exec("CREATE DATABASE " + tmpDBName); err != nil {
|
||||
return xerrors.Errorf("create tmp db: %w", err)
|
||||
}
|
||||
tmpDbURL := ConnectionParams{
|
||||
tmpDBURL := ConnectionParams{
|
||||
Username: connParams.Username,
|
||||
Password: connParams.Password,
|
||||
Host: connParams.Host,
|
||||
Port: connParams.Port,
|
||||
DBName: tmpDBName,
|
||||
}.DSN()
|
||||
tmpDb, err := sql.Open("postgres", tmpDbURL)
|
||||
tmpDB, err := sql.Open("postgres", tmpDBURL)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("connect to template db: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := tmpDb.Close(); err != nil {
|
||||
if err := tmpDB.Close(); err != nil {
|
||||
t.Logf("failed to close temp db: %s\n", err.Error())
|
||||
}
|
||||
}()
|
||||
if err := initialize(tmpDb); err != nil {
|
||||
if err := initialize(tmpDB); err != nil {
|
||||
return xerrors.Errorf("initialize: %w", err)
|
||||
}
|
||||
if err := tmpDb.Close(); err != nil {
|
||||
if err := tmpDB.Close(); err != nil {
|
||||
return xerrors.Errorf("close template db: %w", err)
|
||||
}
|
||||
if _, err := db.Exec("ALTER DATABASE " + tmpDBName + " RENAME TO " + name); err != nil {
|
||||
|
||||
@@ -58,12 +58,12 @@ func TestOpen_ValidDBFrom(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
templateDBName := "tpl_" + migrations.GetMigrationsHash()[:32]
|
||||
tplDbExistsRes, err := db.Query("SELECT 1 FROM pg_database WHERE datname = $1", templateDBName)
|
||||
tplDBExistsRes, err := db.Query("SELECT 1 FROM pg_database WHERE datname = $1", templateDBName)
|
||||
if err != nil {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
require.True(t, tplDbExistsRes.Next())
|
||||
require.NoError(t, tplDbExistsRes.Close())
|
||||
require.True(t, tplDBExistsRes.Next())
|
||||
require.NoError(t, tplDBExistsRes.Close())
|
||||
|
||||
// now populate the db with some data and use it as a new template db
|
||||
// to verify that dbtestutil.Open respects WithDBFrom
|
||||
@@ -91,13 +91,13 @@ func TestOpen_ValidDBFrom(t *testing.T) {
|
||||
newDsn, err := dbtestutil.Open(t, dbtestutil.WithDBFrom(freshTemplateDBName))
|
||||
require.NoError(t, err)
|
||||
|
||||
newDb, err := sql.Open("postgres", newDsn)
|
||||
newDB, err := sql.Open("postgres", newDsn)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, newDb.Close())
|
||||
require.NoError(t, newDB.Close())
|
||||
})
|
||||
|
||||
rows, err = newDb.Query("SELECT 1 FROM my_wonderful_table WHERE name = 'test'")
|
||||
rows, err = newDB.Query("SELECT 1 FROM my_wonderful_table WHERE name = 'test'")
|
||||
require.NoError(t, err)
|
||||
require.True(t, rows.Next())
|
||||
require.NoError(t, rows.Close())
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
// ChatProvider is the fixture shape accepted by dbgen.ChatProvider.
|
||||
//
|
||||
//nolint:revive
|
||||
//nolint:revive,staticcheck // Field names match the legacy generated database models.
|
||||
type ChatProvider struct {
|
||||
ID uuid.UUID
|
||||
Provider string
|
||||
@@ -29,7 +29,7 @@ type ChatProvider struct {
|
||||
// InsertChatProviderParams is the callback parameter shape accepted by
|
||||
// dbgen.ChatProvider.
|
||||
//
|
||||
//nolint:revive
|
||||
//nolint:revive,staticcheck // Field names match the legacy generated database parameters.
|
||||
type InsertChatProviderParams struct {
|
||||
Provider string
|
||||
DisplayName string
|
||||
|
||||
@@ -3858,7 +3858,7 @@ func TestGetAuthorizedConnectionLogsOffset(t *testing.T) {
|
||||
var allLogs []database.ConnectionLog
|
||||
db, _ := dbtestutil.NewDB(t)
|
||||
authz := rbac.NewAuthorizer(prometheus.NewRegistry())
|
||||
authDb := dbauthz.New(db, authz, slogtest.Make(t, &slogtest.Options{}), coderdtest.AccessControlStorePointer())
|
||||
authDB := dbauthz.New(db, authz, slogtest.Make(t, &slogtest.Options{}), coderdtest.AccessControlStorePointer())
|
||||
|
||||
orgA := dbfake.Organization(t, db).Do()
|
||||
orgB := dbfake.Organization(t, db).Do()
|
||||
@@ -3891,7 +3891,7 @@ func TestGetAuthorizedConnectionLogsOffset(t *testing.T) {
|
||||
}
|
||||
for orgID, ids := range orgConnectionLogs {
|
||||
for _, id := range ids {
|
||||
allLogs = append(allLogs, dbgen.ConnectionLog(t, authDb, database.UpsertConnectionLogParams{
|
||||
allLogs = append(allLogs, dbgen.ConnectionLog(t, authDB, database.UpsertConnectionLogParams{
|
||||
WorkspaceID: wsID,
|
||||
WorkspaceOwnerID: user.ID,
|
||||
ID: id,
|
||||
@@ -3928,12 +3928,12 @@ func TestGetAuthorizedConnectionLogsOffset(t *testing.T) {
|
||||
})
|
||||
|
||||
// When: The user queries for connection logs
|
||||
logs, err := authDb.GetConnectionLogsOffset(memberCtx, database.GetConnectionLogsOffsetParams{})
|
||||
logs, err := authDB.GetConnectionLogsOffset(memberCtx, database.GetConnectionLogsOffsetParams{})
|
||||
require.NoError(t, err)
|
||||
// Then: No logs returned
|
||||
require.Len(t, logs, 0, "no logs should be returned")
|
||||
// And: The count matches the number of logs returned
|
||||
count, err := authDb.CountConnectionLogs(memberCtx, database.CountConnectionLogsParams{})
|
||||
count, err := authDB.CountConnectionLogs(memberCtx, database.CountConnectionLogsParams{})
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, len(logs), count)
|
||||
})
|
||||
@@ -3951,12 +3951,12 @@ func TestGetAuthorizedConnectionLogsOffset(t *testing.T) {
|
||||
})
|
||||
|
||||
// When: the auditor queries for connection logs
|
||||
logs, err := authDb.GetConnectionLogsOffset(siteAuditorCtx, database.GetConnectionLogsOffsetParams{})
|
||||
logs, err := authDB.GetConnectionLogsOffset(siteAuditorCtx, database.GetConnectionLogsOffsetParams{})
|
||||
require.NoError(t, err)
|
||||
// Then: All logs are returned
|
||||
require.ElementsMatch(t, connectionOnlyIDs(allLogs), connectionOnlyIDs(logs))
|
||||
// And: The count matches the number of logs returned
|
||||
count, err := authDb.CountConnectionLogs(siteAuditorCtx, database.CountConnectionLogsParams{})
|
||||
count, err := authDB.CountConnectionLogs(siteAuditorCtx, database.CountConnectionLogsParams{})
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, len(logs), count)
|
||||
})
|
||||
@@ -3975,12 +3975,12 @@ func TestGetAuthorizedConnectionLogsOffset(t *testing.T) {
|
||||
})
|
||||
|
||||
// When: The auditor queries for connection logs
|
||||
logs, err := authDb.GetConnectionLogsOffset(orgAuditCtx, database.GetConnectionLogsOffsetParams{})
|
||||
logs, err := authDB.GetConnectionLogsOffset(orgAuditCtx, database.GetConnectionLogsOffsetParams{})
|
||||
require.NoError(t, err)
|
||||
// Then: Only the logs for the organization are returned
|
||||
require.ElementsMatch(t, orgConnectionLogs[orgID], connectionOnlyIDs(logs))
|
||||
// And: The count matches the number of logs returned
|
||||
count, err := authDb.CountConnectionLogs(orgAuditCtx, database.CountConnectionLogsParams{})
|
||||
count, err := authDB.CountConnectionLogs(orgAuditCtx, database.CountConnectionLogsParams{})
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, len(logs), count)
|
||||
})
|
||||
@@ -4000,12 +4000,12 @@ func TestGetAuthorizedConnectionLogsOffset(t *testing.T) {
|
||||
})
|
||||
|
||||
// When: The user queries for connection logs
|
||||
logs, err := authDb.GetConnectionLogsOffset(multiOrgAuditCtx, database.GetConnectionLogsOffsetParams{})
|
||||
logs, err := authDB.GetConnectionLogsOffset(multiOrgAuditCtx, database.GetConnectionLogsOffsetParams{})
|
||||
require.NoError(t, err)
|
||||
// Then: All logs for both organizations are returned
|
||||
require.ElementsMatch(t, append(orgConnectionLogs[first], orgConnectionLogs[second]...), connectionOnlyIDs(logs))
|
||||
// And: The count matches the number of logs returned
|
||||
count, err := authDb.CountConnectionLogs(multiOrgAuditCtx, database.CountConnectionLogsParams{})
|
||||
count, err := authDB.CountConnectionLogs(multiOrgAuditCtx, database.CountConnectionLogsParams{})
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, len(logs), count)
|
||||
})
|
||||
@@ -4023,12 +4023,12 @@ func TestGetAuthorizedConnectionLogsOffset(t *testing.T) {
|
||||
})
|
||||
|
||||
// When: The user queries for audit logs
|
||||
logs, err := authDb.GetConnectionLogsOffset(userCtx, database.GetConnectionLogsOffsetParams{})
|
||||
logs, err := authDB.GetConnectionLogsOffset(userCtx, database.GetConnectionLogsOffsetParams{})
|
||||
require.NoError(t, err)
|
||||
// Then: No logs are returned
|
||||
require.Len(t, logs, 0, "no logs should be returned")
|
||||
// And: The count matches the number of logs returned
|
||||
count, err := authDb.CountConnectionLogs(userCtx, database.CountConnectionLogsParams{})
|
||||
count, err := authDB.CountConnectionLogs(userCtx, database.CountConnectionLogsParams{})
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, len(logs), count)
|
||||
})
|
||||
@@ -6207,15 +6207,17 @@ func TestGetUserStatusCounts(t *testing.T) {
|
||||
case row.Date.Before(userCreatedAt):
|
||||
require.Equal(t, int64(0), row.Count)
|
||||
case row.Date.Before(firstStatusChange):
|
||||
if row.Status == stc.initialStatus {
|
||||
switch row.Status {
|
||||
case stc.initialStatus:
|
||||
require.Equal(t, int64(1), row.Count)
|
||||
} else if row.Status == stc.targetStatus {
|
||||
case stc.targetStatus:
|
||||
require.Equal(t, int64(0), row.Count)
|
||||
}
|
||||
case !row.Date.After(tc.reportUntil):
|
||||
if row.Status == stc.initialStatus {
|
||||
switch row.Status {
|
||||
case stc.initialStatus:
|
||||
require.Equal(t, int64(0), row.Count)
|
||||
} else if row.Status == stc.targetStatus {
|
||||
case stc.targetStatus:
|
||||
require.Equal(t, int64(1), row.Count)
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -184,7 +184,7 @@ func (t *WorkspaceACL) Scan(src interface{}) error {
|
||||
return xerrors.Errorf("unexpected type %T", src)
|
||||
}
|
||||
|
||||
//nolint:revive
|
||||
//nolint:revive,staticcheck // Receiver name matches the other WorkspaceACL methods in this file.
|
||||
func (w WorkspaceACL) RBACACL() map[string][]policy.Action {
|
||||
// Convert WorkspaceACL to a map of string to []policy.Action.
|
||||
// This is used for RBAC checks.
|
||||
|
||||
Reference in New Issue
Block a user