mirror of
https://github.com/usememos/memos.git
synced 2026-11-19 10:29:11 +01:00
chore(go): modernize source and enforce go fix in CI
This commit is contained in:
@@ -9,6 +9,8 @@ on:
|
||||
- "go.mod"
|
||||
- "go.sum"
|
||||
- "**.go"
|
||||
- ".golangci.yaml"
|
||||
- ".github/workflows/backend-tests.yml"
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
@@ -37,6 +39,9 @@ jobs:
|
||||
go mod tidy -go=${{ env.GO_VERSION }}
|
||||
git diff --exit-code
|
||||
|
||||
- name: Verify go fix
|
||||
run: go fix -diff ./...
|
||||
|
||||
- name: Run golangci-lint
|
||||
uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
|
||||
@@ -42,6 +42,8 @@ go test -v -race ./server/... # Server tests with race detector
|
||||
go test -v -race ./internal/... # Internal package tests with race detector
|
||||
go test -v -run TestFoo ./core/... # Run matching Go tests in one tree
|
||||
go mod tidy -go=1.27.0 # Match CI tidy check
|
||||
go fix ./... # Apply Go modernization fixes
|
||||
go fix -diff ./... # Match CI modernization check
|
||||
golangci-lint run # Go lint, config: .golangci.yaml (includes depguard layering rules)
|
||||
golangci-lint run --fix # Auto-fix lint, including goimports
|
||||
|
||||
@@ -148,8 +150,8 @@ Black-box service tests live in `server/api/test/`, unit tests next to the code.
|
||||
- Docker excludes `.git`; pass `--build-arg VERSION="$(bash scripts/release_version.sh development-version)"` and
|
||||
`--build-arg COMMIT="$(git rev-parse HEAD)"` when building locally (build frontend assets first).
|
||||
|
||||
- Backend CI: Go 1.27.0, `go mod tidy -go=1.27.0`, golangci-lint v2.13.1, test groups `store`, `server`, `internal`, `other`
|
||||
(`cmd`, `core`, `markdown`, `filter`, `provider`, `proto`).
|
||||
- Backend CI: Go 1.27.0, `go mod tidy -go=1.27.0`, `go fix -diff ./...`, golangci-lint v2.13.1 (including goimports), test groups
|
||||
`store`, `server`, `internal`, `other` (`cmd`, `core`, `markdown`, `filter`, `provider`, `proto`).
|
||||
- Frontend CI: Node 24, pnpm 11.0.1, `pnpm lint`, `pnpm test`, `pnpm build`.
|
||||
- Proto CI: `buf lint` and `buf format` check.
|
||||
- Docker: `scripts/Dockerfile`, Alpine 3.21 runtime, non-root user, port 5230, multi-arch amd64/arm64/arm/v7.
|
||||
|
||||
+1
-1
@@ -121,7 +121,7 @@ func (*FieldRef) isValueExpr() {}
|
||||
|
||||
// LiteralValue holds a literal scalar.
|
||||
type LiteralValue struct {
|
||||
Value interface{}
|
||||
Value any
|
||||
}
|
||||
|
||||
func (*LiteralValue) isValueExpr() {}
|
||||
|
||||
+1
-1
@@ -462,7 +462,7 @@ func getIdentName(expr *exprv1.Expr) (string, error) {
|
||||
return "", errors.New("expression is not an identifier")
|
||||
}
|
||||
|
||||
func getConstValue(expr *exprv1.Expr) (interface{}, error) {
|
||||
func getConstValue(expr *exprv1.Expr) (any, error) {
|
||||
v, ok := expr.ExprKind.(*exprv1.Expr_ConstExpr)
|
||||
if !ok {
|
||||
return nil, errors.New("expression is not a literal")
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/labstack/echo/v5"
|
||||
@@ -119,8 +120,8 @@ func (r *Resolver) Resolve(remoteAddr string, header http.Header) string {
|
||||
}
|
||||
}
|
||||
}
|
||||
for i := len(entries) - 1; i >= 0; i-- {
|
||||
candidate, ok := parseAddr(entries[i])
|
||||
for _, entry := range slices.Backward(entries) {
|
||||
candidate, ok := parseAddr(entry)
|
||||
if !ok {
|
||||
// A malformed entry ends the walk; nothing to its left can be trusted.
|
||||
break
|
||||
|
||||
@@ -128,7 +128,7 @@ func TestSendAsyncConcurrent(t *testing.T) {
|
||||
g := errgroup.Group{}
|
||||
count := 5
|
||||
|
||||
for i := 0; i < count; i++ {
|
||||
for range count {
|
||||
g.Go(func() error {
|
||||
message := &Message{
|
||||
To: []string{"recipient@example.com"},
|
||||
|
||||
@@ -156,7 +156,7 @@ func TestMessageFormatSanitizesHeaderValues(t *testing.T) {
|
||||
}
|
||||
|
||||
formatted := msg.Format("sender@example.com\r\nX-Injected-From: bad", "Sender\r\nX-Injected-Name: bad")
|
||||
headers := strings.SplitN(formatted, "\r\n\r\n", 2)[0]
|
||||
headers, _, _ := strings.Cut(formatted, "\r\n\r\n")
|
||||
|
||||
if strings.Contains(headers, "\r\nX-Injected") {
|
||||
t.Fatalf("header value injection was not sanitized:\n%s", headers)
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"mime"
|
||||
"net/url"
|
||||
"slices"
|
||||
"strings"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
@@ -409,12 +410,7 @@ func isPotentialHTTPURL(value string) bool {
|
||||
}
|
||||
|
||||
func containsString(values []string, expected string) bool {
|
||||
for _, value := range values {
|
||||
if value == expected {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(values, expected)
|
||||
}
|
||||
|
||||
func isJSONOEmbedMediaType(value string) bool {
|
||||
|
||||
@@ -432,15 +432,13 @@ func TestHTMLMetaFetcherCoalescesRequests(t *testing.T) {
|
||||
var waitGroup sync.WaitGroup
|
||||
errorsChannel := make(chan error, requestCount)
|
||||
for range requestCount {
|
||||
waitGroup.Add(1)
|
||||
go func() {
|
||||
defer waitGroup.Done()
|
||||
waitGroup.Go(func() {
|
||||
meta, err := fetcher.Get(context.Background(), "http://93.184.216.34/shared")
|
||||
if err == nil && meta.Title != "Shared title" {
|
||||
err = errors.New("unexpected metadata")
|
||||
}
|
||||
errorsChannel <- err
|
||||
}()
|
||||
})
|
||||
}
|
||||
<-started
|
||||
close(release)
|
||||
@@ -474,11 +472,9 @@ func TestHTMLMetaFetcherLimitsConcurrency(t *testing.T) {
|
||||
const requestCount = 12
|
||||
var waitGroup sync.WaitGroup
|
||||
for index := range requestCount {
|
||||
waitGroup.Add(1)
|
||||
go func() {
|
||||
defer waitGroup.Done()
|
||||
waitGroup.Go(func() {
|
||||
_, _ = fetcher.Get(context.Background(), "http://93.184.216.34/page?id="+string(rune('a'+index)))
|
||||
}()
|
||||
})
|
||||
}
|
||||
for range maxConcurrentFetches {
|
||||
<-entered
|
||||
|
||||
@@ -20,7 +20,7 @@ var alphabet = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU
|
||||
func String(n int) (string, error) {
|
||||
var sb strings.Builder
|
||||
sb.Grow(n)
|
||||
for i := 0; i < n; i++ {
|
||||
for range n {
|
||||
index, err := rand.Int(rand.Reader, big.NewInt(int64(len(alphabet))))
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
@@ -89,8 +89,8 @@ func TestStripImageExif(t *testing.T) {
|
||||
// Create a simple test image
|
||||
img := image.NewRGBA(image.Rect(0, 0, 100, 100))
|
||||
// Fill with red color
|
||||
for y := 0; y < 100; y++ {
|
||||
for x := 0; x < 100; x++ {
|
||||
for y := range 100 {
|
||||
for x := range 100 {
|
||||
img.Set(x, y, color.RGBA{R: 255, G: 0, B: 0, A: 255})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,21 +23,21 @@ func TestValidateClientMediaMetadata(t *testing.T) {
|
||||
Details: &apipb.MediaMetadata_Photo{Photo: &apipb.PhotoMetadata{
|
||||
CaptureTime: &apipb.MediaCaptureTime{
|
||||
LocalDateTime: "2026-08-10T14:32:18.123",
|
||||
UtcOffset: proto.String("+08:00"),
|
||||
UtcOffset: new("+08:00"),
|
||||
},
|
||||
Location: &apipb.MediaLocation{
|
||||
Latitude: proto.Float64(1.3521),
|
||||
Longitude: proto.Float64(103.8198),
|
||||
AltitudeMeters: proto.Float64(18.4),
|
||||
Latitude: new(1.3521),
|
||||
Longitude: new(103.8198),
|
||||
AltitudeMeters: new(18.4),
|
||||
},
|
||||
SourceExifOrientation: proto.Int32(6),
|
||||
CameraMake: "Apple",
|
||||
CameraModel: "iPhone",
|
||||
LensModel: "Main Camera",
|
||||
FNumber: proto.Float64(1.78),
|
||||
ExposureTimeSeconds: proto.Float64(1.0 / 120.0),
|
||||
FNumber: new(1.78),
|
||||
ExposureTimeSeconds: new(1.0 / 120.0),
|
||||
Iso: proto.Int32(64),
|
||||
FocalLengthMm: proto.Float64(6.86),
|
||||
FocalLengthMm: new(6.86),
|
||||
}},
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func TestValidateClientMediaMetadata(t *testing.T) {
|
||||
|
||||
t.Run("accepts video metadata", func(t *testing.T) {
|
||||
metadata, err := validateClientMediaMetadata(&apipb.MediaMetadata{
|
||||
Details: &apipb.MediaMetadata_Video{Video: &apipb.VideoMetadata{DurationSeconds: proto.Float64(12.5)}},
|
||||
Details: &apipb.MediaMetadata_Video{Video: &apipb.VideoMetadata{DurationSeconds: new(12.5)}},
|
||||
}, "video/mp4")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 12.5, metadata.GetVideo().GetDurationSeconds())
|
||||
@@ -73,7 +73,7 @@ func TestValidateClientMediaMetadata(t *testing.T) {
|
||||
|
||||
t.Run("accepts Z UTC offset", func(t *testing.T) {
|
||||
metadata, err := validateClientMediaMetadata(photoOnly(&apipb.PhotoMetadata{
|
||||
CaptureTime: &apipb.MediaCaptureTime{LocalDateTime: "2026-08-10T14:32:18", UtcOffset: proto.String("Z")},
|
||||
CaptureTime: &apipb.MediaCaptureTime{LocalDateTime: "2026-08-10T14:32:18", UtcOffset: new("Z")},
|
||||
}), "image/jpeg")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "Z", metadata.GetPhoto().GetCaptureTime().GetUtcOffset())
|
||||
@@ -97,15 +97,15 @@ func TestValidateClientMediaMetadata(t *testing.T) {
|
||||
{name: "control character in camera make", mimeType: "image/jpeg", metadata: photoOnly(&apipb.PhotoMetadata{CameraMake: "Apple\nCo"})},
|
||||
{name: "null byte in lens model", mimeType: "image/jpeg", metadata: photoOnly(&apipb.PhotoMetadata{LensModel: "Main\x00Camera"})},
|
||||
{name: "long camera model", mimeType: "image/jpeg", metadata: photoOnly(&apipb.PhotoMetadata{CameraModel: strings.Repeat("x", maxMediaMetadataStringBytes+1)})},
|
||||
{name: "non-finite aperture", mimeType: "image/jpeg", metadata: photoOnly(&apipb.PhotoMetadata{FNumber: proto.Float64(math.NaN())})},
|
||||
{name: "non-finite aperture", mimeType: "image/jpeg", metadata: photoOnly(&apipb.PhotoMetadata{FNumber: new(math.NaN())})},
|
||||
{name: "zero exposure", mimeType: "image/jpeg", metadata: photoOnly(&apipb.PhotoMetadata{ExposureTimeSeconds: proto.Float64(0)})},
|
||||
{name: "zero ISO", mimeType: "image/jpeg", metadata: photoOnly(&apipb.PhotoMetadata{Iso: proto.Int32(0)})},
|
||||
{name: "invalid capture format", mimeType: "image/jpeg", metadata: photoOnly(&apipb.PhotoMetadata{CaptureTime: &apipb.MediaCaptureTime{LocalDateTime: "2026:08:10 14:32:18"}})},
|
||||
{name: "invalid calendar date", mimeType: "image/jpeg", metadata: photoOnly(&apipb.PhotoMetadata{CaptureTime: &apipb.MediaCaptureTime{LocalDateTime: "2026-02-30T14:32:18"}})},
|
||||
{name: "invalid offset", mimeType: "image/jpeg", metadata: photoOnly(&apipb.PhotoMetadata{CaptureTime: &apipb.MediaCaptureTime{LocalDateTime: "2026-08-10T14:32:18", UtcOffset: proto.String("+14:30")}})},
|
||||
{name: "invalid offset", mimeType: "image/jpeg", metadata: photoOnly(&apipb.PhotoMetadata{CaptureTime: &apipb.MediaCaptureTime{LocalDateTime: "2026-08-10T14:32:18", UtcOffset: new("+14:30")}})},
|
||||
{name: "missing longitude", mimeType: "image/jpeg", metadata: photoOnly(&apipb.PhotoMetadata{Location: &apipb.MediaLocation{Latitude: proto.Float64(1)}})},
|
||||
{name: "latitude out of range", mimeType: "image/jpeg", metadata: photoOnly(&apipb.PhotoMetadata{Location: &apipb.MediaLocation{Latitude: proto.Float64(91), Longitude: proto.Float64(1)}})},
|
||||
{name: "non-finite altitude", mimeType: "image/jpeg", metadata: photoOnly(&apipb.PhotoMetadata{Location: &apipb.MediaLocation{Latitude: proto.Float64(1), Longitude: proto.Float64(1), AltitudeMeters: proto.Float64(math.Inf(1))}})},
|
||||
{name: "non-finite altitude", mimeType: "image/jpeg", metadata: photoOnly(&apipb.PhotoMetadata{Location: &apipb.MediaLocation{Latitude: proto.Float64(1), Longitude: proto.Float64(1), AltitudeMeters: new(math.Inf(1))}})},
|
||||
{name: "negative duration", mimeType: "video/mp4", metadata: &apipb.MediaMetadata{Details: &apipb.MediaMetadata_Video{Video: &apipb.VideoMetadata{DurationSeconds: proto.Float64(-1)}}}},
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -226,11 +227,8 @@ func hasSameManagedStorageObject(left, right *store.Attachment) bool {
|
||||
func (s *APIService) cleanupDeletedAttachmentStorage(ctx context.Context, attachments []*store.Attachment) error {
|
||||
var instanceStorageSetting *storepb.InstanceStorageSetting
|
||||
var instanceStorageSettingErr error
|
||||
for _, attachment := range attachments {
|
||||
if store.AttachmentNeedsInstanceStorageSetting(attachment) {
|
||||
instanceStorageSetting, instanceStorageSettingErr = s.Store.GetInstanceStorageSetting(ctx)
|
||||
break
|
||||
}
|
||||
if slices.ContainsFunc(attachments, store.AttachmentNeedsInstanceStorageSetting) {
|
||||
instanceStorageSetting, instanceStorageSettingErr = s.Store.GetInstanceStorageSetting(ctx)
|
||||
}
|
||||
|
||||
var firstErr error
|
||||
|
||||
@@ -95,10 +95,8 @@ func collectSpaceFilterNames(condition filterpkg.Condition, negated bool, names
|
||||
if valueReferencesSpace(condition.Left) {
|
||||
return errors.New("space does not support the in operator")
|
||||
}
|
||||
for _, value := range condition.Values {
|
||||
if valueReferencesSpace(value) {
|
||||
return errors.New("space does not support the in operator")
|
||||
}
|
||||
if slices.ContainsFunc(condition.Values, valueReferencesSpace) {
|
||||
return errors.New("space does not support the in operator")
|
||||
}
|
||||
case *filterpkg.ElementInCondition:
|
||||
if condition.Field == "space" || valueReferencesSpace(condition.Element) {
|
||||
@@ -131,10 +129,8 @@ func valueReferencesSpace(value filterpkg.ValueExpr) bool {
|
||||
case *filterpkg.FieldRef:
|
||||
return value.Name == "space"
|
||||
case *filterpkg.FunctionValue:
|
||||
for _, argument := range value.Args {
|
||||
if valueReferencesSpace(argument) {
|
||||
return true
|
||||
}
|
||||
if slices.ContainsFunc(value.Args, valueReferencesSpace) {
|
||||
return true
|
||||
}
|
||||
case *filterpkg.FieldAccessorValue:
|
||||
return value.Field == "space"
|
||||
|
||||
@@ -47,7 +47,7 @@ func TestGatewayMarshalerKeepsMediaMetadataFieldNames(t *testing.T) {
|
||||
Width: proto.Int32(1920),
|
||||
Height: proto.Int32(1080),
|
||||
Details: &apipb.MediaMetadata_Video{Video: &apipb.VideoMetadata{
|
||||
DurationSeconds: proto.Float64(12.5),
|
||||
DurationSeconds: new(12.5),
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -45,10 +45,7 @@ const (
|
||||
// RESOURCE_EXHAUSTED with an ErrorInfo naming the reason and scope and a RetryInfo
|
||||
// carrying the delay, so an AIP-194 client knows this recovers in seconds.
|
||||
func newRateLimitError(scope ratelimit.Scope, decision ratelimit.Decision) error {
|
||||
retryAfter := int(math.Ceil(decision.RetryAfter.Seconds()))
|
||||
if retryAfter < 1 {
|
||||
retryAfter = 1
|
||||
}
|
||||
retryAfter := max(int(math.Ceil(decision.RetryAfter.Seconds())), 1)
|
||||
st := status.New(codes.ResourceExhausted, rateLimitMessage)
|
||||
detailed, err := st.WithDetails(
|
||||
&errdetails.ErrorInfo{
|
||||
|
||||
@@ -714,21 +714,21 @@ func TestCreateAttachmentMediaMetadata(t *testing.T) {
|
||||
Details: &apipb.MediaMetadata_Photo{Photo: &apipb.PhotoMetadata{
|
||||
CaptureTime: &apipb.MediaCaptureTime{
|
||||
LocalDateTime: "2026-08-10T14:32:18.123",
|
||||
UtcOffset: proto.String("+08:00"),
|
||||
UtcOffset: new("+08:00"),
|
||||
},
|
||||
Location: &apipb.MediaLocation{
|
||||
Latitude: proto.Float64(1.3521),
|
||||
Longitude: proto.Float64(103.8198),
|
||||
AltitudeMeters: proto.Float64(18.4),
|
||||
Latitude: new(1.3521),
|
||||
Longitude: new(103.8198),
|
||||
AltitudeMeters: new(18.4),
|
||||
},
|
||||
SourceExifOrientation: proto.Int32(6),
|
||||
CameraMake: "Apple",
|
||||
CameraModel: "iPhone",
|
||||
LensModel: "Main Camera",
|
||||
FNumber: proto.Float64(1.78),
|
||||
ExposureTimeSeconds: proto.Float64(1.0 / 120.0),
|
||||
FNumber: new(1.78),
|
||||
ExposureTimeSeconds: new(1.0 / 120.0),
|
||||
Iso: proto.Int32(64),
|
||||
FocalLengthMm: proto.Float64(6.86),
|
||||
FocalLengthMm: new(6.86),
|
||||
}},
|
||||
}
|
||||
|
||||
@@ -785,7 +785,7 @@ func TestCreateAttachmentMediaMetadata(t *testing.T) {
|
||||
Width: proto.Int32(1920),
|
||||
Height: proto.Int32(1080),
|
||||
Details: &apipb.MediaMetadata_Video{Video: &apipb.VideoMetadata{
|
||||
DurationSeconds: proto.Float64(12.5),
|
||||
DurationSeconds: new(12.5),
|
||||
}},
|
||||
},
|
||||
},
|
||||
@@ -995,7 +995,7 @@ func TestDeleteMotionMediaGroupChecksBeyondDefaultAttachmentPage(t *testing.T) {
|
||||
}},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
for i := 0; i < 100; i++ {
|
||||
for i := range 100 {
|
||||
attachment, err := ts.Store.CreateAttachment(ctx, &store.Attachment{
|
||||
UID: shortuuid.New(), CreatorID: user.ID, Filename: "filler.txt", Type: "text/plain",
|
||||
})
|
||||
|
||||
@@ -205,7 +205,7 @@ func TestSSOSignInScopesSameIdentifierByProvider(t *testing.T) {
|
||||
users, err := ts.Store.ListUsers(ctx, &store.FindUser{})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, users, 2)
|
||||
identities, err := ts.Store.ListUserIdentities(ctx, &store.FindUserIdentity{ExternUID: ptr("alice")})
|
||||
identities, err := ts.Store.ListUserIdentities(ctx, &store.FindUserIdentity{ExternUID: new("alice")})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, identities, 2)
|
||||
}
|
||||
@@ -228,14 +228,12 @@ func TestConcurrentSSOFirstSignInConvergesOnOneUser(t *testing.T) {
|
||||
errs := make(chan error, signInCount)
|
||||
var waitGroup sync.WaitGroup
|
||||
for range signInCount {
|
||||
waitGroup.Add(1)
|
||||
go func() {
|
||||
defer waitGroup.Done()
|
||||
waitGroup.Go(func() {
|
||||
<-start
|
||||
response, err := signInWithTestingSSO(ctx, ts, idpName, "concurrent-code")
|
||||
results <- response
|
||||
errs <- err
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
close(start)
|
||||
@@ -375,7 +373,3 @@ func assertSingleSSOLink(ctx context.Context, t *testing.T, ts *TestService, pro
|
||||
require.NoError(t, err)
|
||||
require.Len(t, identities, 1)
|
||||
}
|
||||
|
||||
func ptr[T any](value T) *T {
|
||||
return &value
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func TestInstanceAdminRetrieval(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Multiple calls should return consistent admin user (from cache)
|
||||
for i := 0; i < 5; i++ {
|
||||
for range 5 {
|
||||
profile, err := ts.Service.GetInstanceProfile(ctx, &apipb.GetInstanceProfileRequest{})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, profile.Admin)
|
||||
|
||||
@@ -113,7 +113,7 @@ func TestGetInstanceProfile_Concurrency(t *testing.T) {
|
||||
results := make(chan *apipb.InstanceProfile, numGoroutines)
|
||||
errors := make(chan error, numGoroutines)
|
||||
|
||||
for i := 0; i < numGoroutines; i++ {
|
||||
for range numGoroutines {
|
||||
go func() {
|
||||
req := &apipb.GetInstanceProfileRequest{}
|
||||
resp, err := ts.Service.GetInstanceProfile(ctx, req)
|
||||
@@ -126,7 +126,7 @@ func TestGetInstanceProfile_Concurrency(t *testing.T) {
|
||||
}
|
||||
|
||||
// Collect all results
|
||||
for i := 0; i < numGoroutines; i++ {
|
||||
for range numGoroutines {
|
||||
select {
|
||||
case err := <-errors:
|
||||
t.Fatalf("Goroutine returned error: %v", err)
|
||||
|
||||
@@ -169,7 +169,7 @@ func TestMemoManagedAttachmentImages(t *testing.T) {
|
||||
UID: shortuuid.New(), CreatorID: user.ID, Filename: "referenced.png", Type: "image/png", MemoID: &memoID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
for i := 0; i < 100; i++ {
|
||||
for i := range 100 {
|
||||
attachment, err := ts.Store.CreateAttachment(ctx, &store.Attachment{
|
||||
UID: shortuuid.New(), CreatorID: user.ID, Filename: fmt.Sprintf("extra-%03d.png", i), Type: "image/png", MemoID: &memoID,
|
||||
})
|
||||
|
||||
@@ -109,7 +109,7 @@ func seedListMemosBenchmarkData(ctx context.Context, stores *store.Store, hostUs
|
||||
topLevelMemos := make([]*store.Memo, 0, benchmarkTopLevelMemoCount)
|
||||
commentParentName := ""
|
||||
|
||||
for i := 0; i < benchmarkTopLevelMemoCount; i++ {
|
||||
for i := range benchmarkTopLevelMemoCount {
|
||||
visibility := store.Private
|
||||
if i%4 == 0 {
|
||||
visibility = store.Public
|
||||
|
||||
@@ -76,7 +76,7 @@ func TestInstanceAdminIsSuperuserForNamedMemoOperations(t *testing.T) {
|
||||
spaceMemo, err := ts.Service.CreateMemo(ownerCtx, &apipb.CreateMemoRequest{Memo: &apipb.Memo{
|
||||
Content: "members only",
|
||||
Visibility: apipb.Visibility_SPACE,
|
||||
Space: ptr("spaces/" + space.UID),
|
||||
Space: new("spaces/" + space.UID),
|
||||
}})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -119,12 +119,12 @@ func TestInstanceAdminIsSuperuserForNamedMemoOperations(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
_, err = ts.Service.UpdateMemo(adminCtx, &apipb.UpdateMemoRequest{
|
||||
Memo: &apipb.Memo{Name: private.Name, Visibility: apipb.Visibility_SPACE, Space: ptr("spaces/" + space.UID)},
|
||||
Memo: &apipb.Memo{Name: private.Name, Visibility: apipb.Visibility_SPACE, Space: new("spaces/" + space.UID)},
|
||||
UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"visibility", "space"}},
|
||||
})
|
||||
require.NoError(t, err, "an administrator places memos in a Space they are not a member of")
|
||||
_, err = ts.Service.UpdateMemo(adminCtx, &apipb.UpdateMemoRequest{
|
||||
Memo: &apipb.Memo{Name: private.Name, Space: ptr("spaces/does-not-exist")},
|
||||
Memo: &apipb.Memo{Name: private.Name, Space: new("spaces/does-not-exist")},
|
||||
UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"space"}},
|
||||
})
|
||||
require.Equal(t, codes.NotFound, status.Code(err), "structural validity still applies")
|
||||
@@ -971,7 +971,7 @@ func TestListMemoCommentsPaginates(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
for i := range 3 {
|
||||
_, err = ts.Service.CreateMemoComment(ownerCtx, &apipb.CreateMemoCommentRequest{
|
||||
Parent: memo.Name,
|
||||
Comment: &apipb.Memo{
|
||||
@@ -1008,7 +1008,7 @@ func TestListMemoCommentsFiltersArchivedBeforePagination(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
comments := make([]*apipb.Memo, 0, 5)
|
||||
for i := 0; i < 5; i++ {
|
||||
for i := range 5 {
|
||||
comment, err := ts.Service.CreateMemoComment(ownerCtx, &apipb.CreateMemoCommentRequest{
|
||||
Parent: memo.Name,
|
||||
Comment: &apipb.Memo{Content: fmt.Sprintf("comment %d", i)},
|
||||
@@ -1197,7 +1197,7 @@ func TestAssignedMemoCommentListingUsesMemoLocalReadAccess(t *testing.T) {
|
||||
contextMemo, err := ts.Service.CreateMemo(ownerCtx, &apipb.CreateMemoRequest{Memo: &apipb.Memo{
|
||||
Content: "assigned public comment context",
|
||||
Visibility: apipb.Visibility_PUBLIC,
|
||||
Space: ptr("spaces/" + space.UID),
|
||||
Space: new("spaces/" + space.UID),
|
||||
}})
|
||||
require.NoError(t, err)
|
||||
comment, err := ts.Service.CreateMemoComment(memberCtx, &apipb.CreateMemoCommentRequest{
|
||||
|
||||
@@ -83,7 +83,7 @@ func TestDeleteMemoShare_RevalidatesSpaceWriteAuthority(t *testing.T) {
|
||||
}, owner.ID)
|
||||
require.NoError(t, err)
|
||||
memo, err := ts.Service.CreateMemo(ownerCtx, &apipb.CreateMemoRequest{Memo: &apipb.Memo{
|
||||
Content: "assigned share", Visibility: apipb.Visibility_PUBLIC, Space: ptr("spaces/" + space.UID),
|
||||
Content: "assigned share", Visibility: apipb.Visibility_PUBLIC, Space: new("spaces/" + space.UID),
|
||||
}})
|
||||
require.NoError(t, err)
|
||||
share, err := ts.Service.CreateMemoShare(ownerCtx, &apipb.CreateMemoShareRequest{Parent: memo.Name, MemoShare: &apipb.MemoShare{}})
|
||||
@@ -140,7 +140,7 @@ func TestDeleteMemoShare_OwnerCanRevokeLegacyAdminShare(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
share, err := ts.Store.GetMemoShare(ctx, &store.FindMemoShare{UID: ptr(shareToken)})
|
||||
share, err := ts.Store.GetMemoShare(ctx, &store.FindMemoShare{UID: new(shareToken)})
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, share)
|
||||
_, err = ts.Service.GetSharedMemo(ctx, &apipb.GetSharedMemoRequest{ShareToken: shareToken})
|
||||
|
||||
@@ -202,7 +202,7 @@ func TestAssignedMemoReactionsFollowMemoReadAccess(t *testing.T) {
|
||||
memo, err := ts.Service.CreateMemo(ownerCtx, &apipb.CreateMemoRequest{Memo: &apipb.Memo{
|
||||
Content: "assigned public memo with reactions",
|
||||
Visibility: apipb.Visibility_PUBLIC,
|
||||
Space: ptr("spaces/" + space.UID),
|
||||
Space: new("spaces/" + space.UID),
|
||||
}})
|
||||
require.NoError(t, err)
|
||||
_, err = ts.Service.UpsertMemoReaction(ownerCtx, &apipb.UpsertMemoReactionRequest{
|
||||
|
||||
@@ -150,7 +150,7 @@ func TestAssignedPublicMemoCommentNotifiesReadableRemovedAuthor(t *testing.T) {
|
||||
memo, err := ts.Service.CreateMemo(ownerCtx, &apipb.CreateMemoRequest{Memo: &apipb.Memo{
|
||||
Content: "assigned public memo",
|
||||
Visibility: apipb.Visibility_PUBLIC,
|
||||
Space: ptr("spaces/" + space.UID),
|
||||
Space: new("spaces/" + space.UID),
|
||||
}})
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, ts.Store.DeleteSpaceMember(ctx, &store.DeleteSpaceMember{SpaceID: space.ID, UserID: owner.ID}, owner.ID))
|
||||
|
||||
@@ -42,7 +42,7 @@ func TestListUsersPagination(t *testing.T) {
|
||||
|
||||
// Admin + 5 members = 6 users total.
|
||||
expected := map[string]struct{}{"admin": {}}
|
||||
for i := 0; i < 5; i++ {
|
||||
for i := range 5 {
|
||||
name := fmt.Sprintf("member-%d", i)
|
||||
_, err := ts.CreateRegularUser(ctx, name)
|
||||
require.NoError(t, err)
|
||||
@@ -74,7 +74,7 @@ func TestListUsersDefaultPageSizeReturnsAllWhenSmall(t *testing.T) {
|
||||
admin, err := ts.CreateHostUser(ctx, "admin")
|
||||
require.NoError(t, err)
|
||||
adminCtx := ts.CreateUserContext(ctx, admin.ID)
|
||||
for i := 0; i < 3; i++ {
|
||||
for i := range 3 {
|
||||
_, err := ts.CreateRegularUser(ctx, fmt.Sprintf("member-%d", i))
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -161,12 +161,12 @@ func pathPlaceholderNames(path string) []string {
|
||||
// segments match the other arguments. Bare IDs pass through unchanged.
|
||||
func trimResourceNamePrefix(path, parameterName, value string, resolved map[string]string) string {
|
||||
placeholder := "/{" + parameterName + "}"
|
||||
index := strings.Index(path, placeholder)
|
||||
if index < 0 {
|
||||
before, _, found := strings.Cut(path, placeholder)
|
||||
if !found {
|
||||
return value
|
||||
}
|
||||
|
||||
prefix, ok := resolvedResourceNamePrefix(path[:index], resolved)
|
||||
prefix, ok := resolvedResourceNamePrefix(before, resolved)
|
||||
if !ok || prefix == "" {
|
||||
return value
|
||||
}
|
||||
|
||||
@@ -269,9 +269,7 @@ func inputSchemaForOperation(operation *openAPIOperation) jsonSchema {
|
||||
|
||||
if operation.RequestBody != nil {
|
||||
bodySchema := requestBodySchema(operation)
|
||||
for name, definition := range extractSchemaDefs(bodySchema) {
|
||||
defs[name] = definition
|
||||
}
|
||||
maps.Copy(defs, extractSchemaDefs(bodySchema))
|
||||
properties["body"] = bodySchema
|
||||
if requestBodyRequired(operation) {
|
||||
required = append(required, "body")
|
||||
@@ -331,9 +329,7 @@ func outputSchemaForOperation(operation *openAPIOperation) jsonSchema {
|
||||
|
||||
func cloneSchema(schema jsonSchema) jsonSchema {
|
||||
clone := jsonSchema{}
|
||||
for key, value := range schema {
|
||||
clone[key] = value
|
||||
}
|
||||
maps.Copy(clone, schema)
|
||||
return clone
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ func (s *Store) applyAuthenticationConfigMutation(ctx context.Context, mutation
|
||||
defer s.authConfigMu.Unlock()
|
||||
|
||||
var err error
|
||||
for attempt := 0; attempt < authenticationMutationMaxAttempts; attempt++ {
|
||||
for attempt := range authenticationMutationMaxAttempts {
|
||||
err = s.driver.ApplyAuthenticationConfigMutation(ctx, mutation)
|
||||
if err == nil || !s.driver.IsRetryableAuthenticationMutationError(err) {
|
||||
return err
|
||||
|
||||
Vendored
+9
-9
@@ -66,13 +66,13 @@ func TestCacheEviction(t *testing.T) {
|
||||
defer cache.Close()
|
||||
|
||||
// Add 5 items (max capacity)
|
||||
for i := 0; i < 5; i++ {
|
||||
for i := range 5 {
|
||||
key := fmt.Sprintf("key%d", i)
|
||||
cache.Set(ctx, key, i)
|
||||
}
|
||||
|
||||
// Verify all 5 items are in the cache
|
||||
for i := 0; i < 5; i++ {
|
||||
for i := range 5 {
|
||||
key := fmt.Sprintf("key%d", i)
|
||||
if _, ok := cache.Get(ctx, key); !ok {
|
||||
t.Errorf("Key '%s' should be in the cache", key)
|
||||
@@ -90,7 +90,7 @@ func TestCacheEviction(t *testing.T) {
|
||||
|
||||
// Some of the original keys should have been evicted
|
||||
evictedCount := 0
|
||||
for i := 0; i < 5; i++ {
|
||||
for i := range 5 {
|
||||
key := fmt.Sprintf("key%d", i)
|
||||
if _, ok := cache.Get(ctx, key); !ok {
|
||||
evictedCount++
|
||||
@@ -121,21 +121,21 @@ func TestCacheConcurrency(t *testing.T) {
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(goroutines)
|
||||
|
||||
for i := 0; i < goroutines; i++ {
|
||||
for i := range goroutines {
|
||||
go func(id int) {
|
||||
defer wg.Done()
|
||||
|
||||
baseKey := fmt.Sprintf("worker%d-", id)
|
||||
|
||||
// Set operations
|
||||
for j := 0; j < operationsPerGoroutine; j++ {
|
||||
for j := range operationsPerGoroutine {
|
||||
key := fmt.Sprintf("%skey%d", baseKey, j)
|
||||
value := fmt.Sprintf("value%d-%d", id, j)
|
||||
cache.Set(ctx, key, value)
|
||||
}
|
||||
|
||||
// Get operations
|
||||
for j := 0; j < operationsPerGoroutine; j++ {
|
||||
for j := range operationsPerGoroutine {
|
||||
key := fmt.Sprintf("%skey%d", baseKey, j)
|
||||
val, ok := cache.Get(ctx, key)
|
||||
if !ok {
|
||||
@@ -149,7 +149,7 @@ func TestCacheConcurrency(t *testing.T) {
|
||||
}
|
||||
|
||||
// Delete half the keys
|
||||
for j := 0; j < operationsPerGoroutine/2; j++ {
|
||||
for j := range operationsPerGoroutine / 2 {
|
||||
key := fmt.Sprintf("%skey%d", baseKey, j)
|
||||
cache.Delete(ctx, key)
|
||||
}
|
||||
@@ -167,13 +167,13 @@ func TestCacheConcurrency(t *testing.T) {
|
||||
|
||||
func TestEvictionCallback(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
evicted := make(map[string]interface{})
|
||||
evicted := make(map[string]any)
|
||||
evictedMu := sync.Mutex{}
|
||||
|
||||
config := DefaultConfig()
|
||||
config.DefaultTTL = 50 * time.Millisecond
|
||||
config.CleanupInterval = 25 * time.Millisecond
|
||||
config.OnEviction = func(key string, value interface{}) {
|
||||
config.OnEviction = func(key string, value any) {
|
||||
evictedMu.Lock()
|
||||
evicted[key] = value
|
||||
evictedMu.Unlock()
|
||||
|
||||
@@ -19,7 +19,7 @@ func validateLucideIcon(name string) error {
|
||||
if len(name) == 0 || len(name) > 128 {
|
||||
return errors.New("icon name must contain 1 to 128 bytes")
|
||||
}
|
||||
for _, part := range strings.Split(name, "-") {
|
||||
for part := range strings.SplitSeq(name, "-") {
|
||||
if part == "" {
|
||||
return errors.New("icon name must use lowercase kebab-case")
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func placeholder(n int) string {
|
||||
|
||||
func placeholders(n int) string {
|
||||
list := []string{}
|
||||
for i := 0; i < n; i++ {
|
||||
for i := range n {
|
||||
list = append(list, placeholder(i+1))
|
||||
}
|
||||
return strings.Join(list, ", ")
|
||||
|
||||
@@ -43,7 +43,7 @@ func TestDemoSeedUsesDeploymentAuthenticationPolicy(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.True(t, generalSetting.DisallowPasswordAuth)
|
||||
require.False(t, generalSetting.DisallowUserRegistration, "SSO first-login provisioning must remain enabled")
|
||||
provider, err := stores.GetIdentityProvider(ctx, &store.FindIdentityProvider{UID: ptr("primary-sso")})
|
||||
provider, err := stores.GetIdentityProvider(ctx, &store.FindIdentityProvider{UID: new("primary-sso")})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, provider)
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ func TestLoadDeploymentConfigurationPublishesRuntimeOnlyIdentityProvider(t *test
|
||||
|
||||
require.NoError(t, stores.LoadDeploymentConfigurationDir(ctx, dir))
|
||||
|
||||
effective, err := stores.GetIdentityProvider(ctx, &store.FindIdentityProvider{UID: ptr("primary-sso")})
|
||||
effective, err := stores.GetIdentityProvider(ctx, &store.FindIdentityProvider{UID: new("primary-sso")})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, effective)
|
||||
assert.Zero(t, effective.Id)
|
||||
@@ -35,7 +35,7 @@ func TestLoadDeploymentConfigurationPublishesRuntimeOnlyIdentityProvider(t *test
|
||||
assert.Equal(t, "file-secret", effective.Config.GetOauth2Config().ClientSecret)
|
||||
assert.True(t, stores.IsIdentityProviderDeploymentConfigured("primary-sso"))
|
||||
|
||||
stored, err := stores.GetStoredIdentityProvider(ctx, &store.FindIdentityProvider{UID: ptr("primary-sso")})
|
||||
stored, err := stores.GetStoredIdentityProvider(ctx, &store.FindIdentityProvider{UID: new("primary-sso")})
|
||||
require.NoError(t, err)
|
||||
assert.Nil(t, stored)
|
||||
}
|
||||
@@ -59,10 +59,10 @@ func TestLoadDeploymentConfigurationShadowsWithoutChangingStoredResources(t *tes
|
||||
writeDeploymentGeneralSetting(t, filepath.Join(dir, "memos-instance-setting-general.json"), 4, true)
|
||||
require.NoError(t, stores.LoadDeploymentConfigurationDir(ctx, dir))
|
||||
|
||||
effectiveProvider, err := stores.GetIdentityProvider(ctx, &store.FindIdentityProvider{UID: ptr("primary-sso")})
|
||||
effectiveProvider, err := stores.GetIdentityProvider(ctx, &store.FindIdentityProvider{UID: new("primary-sso")})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "File SSO", effectiveProvider.Name)
|
||||
storedProvider, err := stores.GetStoredIdentityProvider(ctx, &store.FindIdentityProvider{UID: ptr("primary-sso")})
|
||||
storedProvider, err := stores.GetStoredIdentityProvider(ctx, &store.FindIdentityProvider{UID: new("primary-sso")})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, storedID, storedProvider.Id)
|
||||
assert.Equal(t, "Stored SSO", storedProvider.Name)
|
||||
@@ -85,11 +85,11 @@ func TestLoadDeploymentConfigurationReturnsDefensiveClones(t *testing.T) {
|
||||
writeDeploymentGeneralSetting(t, filepath.Join(dir, "memos-instance-setting-general.json"), 2, false)
|
||||
require.NoError(t, stores.LoadDeploymentConfigurationDir(ctx, dir))
|
||||
|
||||
provider, err := stores.GetIdentityProvider(ctx, &store.FindIdentityProvider{UID: ptr("primary-sso")})
|
||||
provider, err := stores.GetIdentityProvider(ctx, &store.FindIdentityProvider{UID: new("primary-sso")})
|
||||
require.NoError(t, err)
|
||||
provider.Name = "Mutated"
|
||||
provider.Config.GetOauth2Config().ClientSecret = "mutated-secret"
|
||||
providerAgain, err := stores.GetIdentityProvider(ctx, &store.FindIdentityProvider{UID: ptr("primary-sso")})
|
||||
providerAgain, err := stores.GetIdentityProvider(ctx, &store.FindIdentityProvider{UID: new("primary-sso")})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "File SSO", providerAgain.Name)
|
||||
assert.Equal(t, "file-secret", providerAgain.Config.GetOauth2Config().ClientSecret)
|
||||
@@ -116,7 +116,7 @@ func TestLoadDeploymentConfigurationPublishesAtomically(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
assert.ErrorContains(t, err, `unknown field "unknown"`)
|
||||
|
||||
provider, getErr := stores.GetIdentityProvider(ctx, &store.FindIdentityProvider{UID: ptr("primary-sso")})
|
||||
provider, getErr := stores.GetIdentityProvider(ctx, &store.FindIdentityProvider{UID: new("primary-sso")})
|
||||
require.NoError(t, getErr)
|
||||
assert.Equal(t, "File SSO", provider.Name)
|
||||
}
|
||||
@@ -502,7 +502,3 @@ func assertBool(value bool) string {
|
||||
}
|
||||
return "false"
|
||||
}
|
||||
|
||||
func ptr[T any](value T) *T {
|
||||
return &value
|
||||
}
|
||||
|
||||
+1
-1
@@ -376,7 +376,7 @@ func getSchemaVersionOfMigrateScript(filePath string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
series := elements[len(elements)-2]
|
||||
rawSequence := strings.Split(elements[len(elements)-1], MigrateFileNameSplit)[0]
|
||||
rawSequence, _, _ := strings.Cut(elements[len(elements)-1], MigrateFileNameSplit)
|
||||
sequence, err := strconv.Atoi(rawSequence)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "failed to convert migration sequence to int: %s", rawSequence)
|
||||
|
||||
@@ -562,7 +562,7 @@ func TestAttachmentListWithPagination(t *testing.T) {
|
||||
ts := NewTestingStore(ctx, t)
|
||||
|
||||
// Create 5 attachments
|
||||
for i := 0; i < 5; i++ {
|
||||
for i := range 5 {
|
||||
_, err := ts.CreateAttachment(ctx, &store.Attachment{
|
||||
UID: shortuuid.New(),
|
||||
CreatorID: 101,
|
||||
@@ -642,7 +642,7 @@ func TestMemoMutationConcurrentUpdatesNoSQLiteBusy(t *testing.T) {
|
||||
errs := make([]error, workers)
|
||||
var wg sync.WaitGroup
|
||||
content := "updated"
|
||||
for i := 0; i < workers; i++ {
|
||||
for i := range workers {
|
||||
wg.Go(func() {
|
||||
<-start
|
||||
errs[i] = ts.ApplyMemoMutation(ctx, &store.MemoMutation{
|
||||
@@ -681,7 +681,7 @@ func TestMemoMutationConcurrentUpdatesSameMemoNoSQLiteBusy(t *testing.T) {
|
||||
errs := make([]error, workers)
|
||||
var wg sync.WaitGroup
|
||||
content := "updated"
|
||||
for i := 0; i < workers; i++ {
|
||||
for i := range workers {
|
||||
wg.Go(func() {
|
||||
<-start
|
||||
errs[i] = ts.ApplyMemoMutation(ctx, &store.MemoMutation{
|
||||
|
||||
@@ -28,14 +28,6 @@ func formatInt(n int) string {
|
||||
return strconv.Itoa(n)
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Pointer Helpers
|
||||
// =============================================================================
|
||||
|
||||
func boolPtr(b bool) *bool {
|
||||
return &b
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Test Fixture Builders
|
||||
// =============================================================================
|
||||
@@ -173,7 +165,7 @@ func (tc *MemoFilterTestContext) CreateMemo(b *MemoBuilder) *store.Memo {
|
||||
func (tc *MemoFilterTestContext) PinMemo(memoID int32) {
|
||||
err := tc.Store.UpdateMemo(tc.Ctx, &store.UpdateMemo{
|
||||
ID: memoID,
|
||||
Pinned: boolPtr(true),
|
||||
Pinned: new(true),
|
||||
})
|
||||
require.NoError(tc.T, err)
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ func TestInboxListPagination(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create 5 inboxes
|
||||
for i := 0; i < 5; i++ {
|
||||
for range 5 {
|
||||
_, err = ts.CreateInbox(ctx, &store.Inbox{
|
||||
SenderID: 0,
|
||||
ReceiverID: user.ID,
|
||||
@@ -520,7 +520,7 @@ func TestInboxMessageTypeFilterWithStatusAndPagination(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create multiple inboxes with various combinations
|
||||
for i := 0; i < 5; i++ {
|
||||
for range 5 {
|
||||
_, err = ts.CreateInbox(ctx, &store.Inbox{
|
||||
SenderID: 0,
|
||||
ReceiverID: user.ID,
|
||||
@@ -533,7 +533,7 @@ func TestInboxMessageTypeFilterWithStatusAndPagination(t *testing.T) {
|
||||
// Archive 2 of them
|
||||
allInboxes, err := ts.ListInboxes(ctx, &store.FindInbox{ReceiverID: &user.ID})
|
||||
require.NoError(t, err)
|
||||
for i := 0; i < 2; i++ {
|
||||
for i := range 2 {
|
||||
_, err = ts.UpdateInbox(ctx, &store.UpdateInbox{ID: allInboxes[i].ID, Status: store.ARCHIVED})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ func TestCreateInstanceSettingIfNotExistsIsFirstWriterWins(t *testing.T) {
|
||||
}
|
||||
start := make(chan struct{})
|
||||
results := make(chan result, candidateCount)
|
||||
for i := 0; i < candidateCount; i++ {
|
||||
for i := range candidateCount {
|
||||
value := fmt.Sprintf("candidate-%02d", i)
|
||||
go func() {
|
||||
<-start
|
||||
|
||||
@@ -252,7 +252,7 @@ func TestMemoListWithPagination(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create 10 memos
|
||||
for i := 0; i < 10; i++ {
|
||||
for i := range 10 {
|
||||
_, err := ts.CreateMemo(ctx, &store.Memo{
|
||||
UID: fmt.Sprintf("memo-%d", i),
|
||||
CreatorID: user.ID,
|
||||
|
||||
@@ -158,7 +158,7 @@ func TestMigrationMultipleReRuns(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Run migration multiple times
|
||||
for i := 0; i < 3; i++ {
|
||||
for i := range 3 {
|
||||
err = ts.Migrate(ctx)
|
||||
require.NoError(t, err, "migration run %d should not fail", i+1)
|
||||
}
|
||||
|
||||
@@ -745,7 +745,7 @@ func TestUserSettingGetUserByPATHashLargeTokenCount(t *testing.T) {
|
||||
// Create many PATs for the same user
|
||||
tokenCount := 10
|
||||
hashes := make([]string, tokenCount)
|
||||
for i := 0; i < tokenCount; i++ {
|
||||
for i := range tokenCount {
|
||||
hashes[i] = "pat-hash-" + string(rune('A'+i)) + "-large-test"
|
||||
err = ts.AddUserPersonalAccessToken(ctx, user.ID, &storepb.PersonalAccessTokensUserSetting_PersonalAccessToken{
|
||||
TokenId: "pat-large-" + string(rune('A'+i)),
|
||||
|
||||
@@ -48,7 +48,7 @@ func TestUserListByIDList(t *testing.T) {
|
||||
|
||||
// Create 5 users
|
||||
var userIDs []int32
|
||||
for i := 0; i < 5; i++ {
|
||||
for i := range 5 {
|
||||
user, err := createTestingUserWithRole(ctx, ts, fmt.Sprintf("user_list_%d", i), store.RoleUser)
|
||||
require.NoError(t, err)
|
||||
userIDs = append(userIDs, user.ID)
|
||||
@@ -266,7 +266,7 @@ func TestUserListWithLimit(t *testing.T) {
|
||||
ts := NewTestingStore(ctx, t)
|
||||
|
||||
// Create 5 users
|
||||
for i := 0; i < 5; i++ {
|
||||
for i := range 5 {
|
||||
role := store.RoleUser
|
||||
if i == 0 {
|
||||
role = store.RoleAdmin
|
||||
|
||||
@@ -43,11 +43,11 @@ func classifyUserUniqueViolation(err error) error {
|
||||
}
|
||||
message := err.Error()
|
||||
for _, marker := range uniqueViolationMarkers {
|
||||
index := strings.Index(message, marker)
|
||||
if index < 0 {
|
||||
_, after, ok := strings.Cut(message, marker)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
target := message[index+len(marker):]
|
||||
target := after
|
||||
switch {
|
||||
case strings.Contains(target, "user_identity"):
|
||||
return errors.Wrap(ErrUserIdentityTaken, message)
|
||||
|
||||
Reference in New Issue
Block a user