mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-31 03:14:17 +09:00
Consolidate all Go tests. Coverage is identical to before. Go tests are around 5% faster while being 7% smaller. No non-test code is touched.
50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package repo
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gitea.dev/models/unittest"
|
|
"gitea.dev/services/contexttest"
|
|
"gitea.dev/services/gitdiff"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestDiffViewStyle(t *testing.T) {
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
t.Run("AnonymousUser", func(t *testing.T) {
|
|
ctx, _ := contexttest.MockContext(t, "/any")
|
|
SetDiffViewStyle(ctx)
|
|
assert.Equal(t, gitdiff.DiffStyleUnified, GetDiffViewStyle(ctx))
|
|
|
|
ctx, _ = contexttest.MockContext(t, "/any?style=split")
|
|
SetDiffViewStyle(ctx)
|
|
assert.Equal(t, gitdiff.DiffStyleSplit, GetDiffViewStyle(ctx))
|
|
|
|
ctx, _ = contexttest.MockContext(t, "/any")
|
|
SetDiffViewStyle(ctx)
|
|
assert.Equal(t, gitdiff.DiffStyleUnified, GetDiffViewStyle(ctx)) // at the moment, anonymous users don't have a saved preference
|
|
})
|
|
|
|
t.Run("SignedInUser", func(t *testing.T) {
|
|
for _, testCase := range []struct {
|
|
requestPath, expected string
|
|
}{
|
|
{"/any", gitdiff.DiffStyleUnified},
|
|
{"/any?style=split", gitdiff.DiffStyleSplit},
|
|
{"/any", gitdiff.DiffStyleSplit},
|
|
{"/any?style=unified", gitdiff.DiffStyleUnified},
|
|
{"/any", gitdiff.DiffStyleUnified},
|
|
} {
|
|
ctx, _ := contexttest.MockContext(t, testCase.requestPath)
|
|
contexttest.LoadUser(t, ctx, 2)
|
|
SetDiffViewStyle(ctx)
|
|
assert.Equal(t, testCase.expected, GetDiffViewStyle(ctx))
|
|
}
|
|
})
|
|
}
|