2023-08-14 23:14:30 +08:00
|
|
|
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2025-03-27 20:13:05 +00:00
|
|
|
"forgejo.org/models/perm"
|
|
|
|
"forgejo.org/modules/setting"
|
|
|
|
"forgejo.org/modules/test"
|
2023-12-20 21:44:55 +01:00
|
|
|
|
2023-08-14 23:14:30 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestActionsConfig(t *testing.T) {
|
|
|
|
cfg := &ActionsConfig{}
|
|
|
|
cfg.DisableWorkflow("test1.yaml")
|
|
|
|
assert.EqualValues(t, []string{"test1.yaml"}, cfg.DisabledWorkflows)
|
|
|
|
|
|
|
|
cfg.DisableWorkflow("test1.yaml")
|
|
|
|
assert.EqualValues(t, []string{"test1.yaml"}, cfg.DisabledWorkflows)
|
|
|
|
|
|
|
|
cfg.EnableWorkflow("test1.yaml")
|
|
|
|
assert.EqualValues(t, []string{}, cfg.DisabledWorkflows)
|
|
|
|
|
|
|
|
cfg.EnableWorkflow("test1.yaml")
|
|
|
|
assert.EqualValues(t, []string{}, cfg.DisabledWorkflows)
|
|
|
|
|
|
|
|
cfg.DisableWorkflow("test1.yaml")
|
|
|
|
cfg.DisableWorkflow("test2.yaml")
|
|
|
|
cfg.DisableWorkflow("test3.yaml")
|
|
|
|
assert.EqualValues(t, "test1.yaml,test2.yaml,test3.yaml", cfg.ToString())
|
|
|
|
}
|
2023-12-20 21:44:55 +01:00
|
|
|
|
|
|
|
func TestRepoUnitAccessMode(t *testing.T) {
|
[v11.0/forgejo] fix: corrupted wiki unit default permission (#8234 follow-up) (#8258) (#8445)
**Backport of** https://codeberg.org/forgejo/forgejo/pulls/8258, cherry picked from commit cee2aae4cacd9caab98a4cbb273aab1cf0d0137b
Manual adjustments:
- rename the migration file from `v36` to `v29`
- added the `//nolint:revive`
---
Closes #8119, follow-up of #8234 (**backported in #8237**)
## Testing
- go to a commit before #8234 (e.g.
285f66b782491d05e35aa81a6e1a0fede85069b4)
- create 3 repositories
- save the wiki settings of the second, without any change
- set the wiki of the third to be globally writable
- verify the `default_permissions` column in the database, of the unit
`5`: 0, 2, 3
- stop Forgejo, switch to this PR and start Forgejo
- verify that the logs writes `Migration[35]: Fix wiki unit default
permission`
- verify the `default_permissions` column in the database, of the unit
`5`: 0, 0, 3
Before:

After:

- [x] I did not document these changes and I do not expect someone else
to do it.
- [x] I do not want this change to show in the release notes.
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8445
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Co-authored-by: oliverpool <git@olivier.pfad.fr>
Co-committed-by: oliverpool <git@olivier.pfad.fr>
2025-07-08 18:52:59 +02:00
|
|
|
// assert.Equal(t, perm.AccessModeNone, UnitAccessModeNone.ToAccessMode(perm.AccessModeAdmin))
|
|
|
|
// assert.Equal(t, perm.AccessModeRead, UnitAccessModeRead.ToAccessMode(perm.AccessModeAdmin))
|
2024-07-30 19:41:10 +00:00
|
|
|
assert.Equal(t, perm.AccessModeWrite, UnitAccessModeWrite.ToAccessMode(perm.AccessModeAdmin))
|
|
|
|
assert.Equal(t, perm.AccessModeRead, UnitAccessModeUnset.ToAccessMode(perm.AccessModeRead))
|
2023-12-20 21:44:55 +01:00
|
|
|
}
|
2024-12-14 10:12:04 +03:00
|
|
|
|
|
|
|
func TestRepoPRIsUpdateStyleAllowed(t *testing.T) {
|
|
|
|
var cfg PullRequestsConfig
|
|
|
|
cfg = PullRequestsConfig{
|
|
|
|
AllowRebaseUpdate: true,
|
|
|
|
}
|
|
|
|
assert.True(t, cfg.IsUpdateStyleAllowed(UpdateStyleMerge))
|
|
|
|
assert.True(t, cfg.IsUpdateStyleAllowed(UpdateStyleRebase))
|
|
|
|
|
|
|
|
cfg = PullRequestsConfig{
|
|
|
|
AllowRebaseUpdate: false,
|
|
|
|
}
|
|
|
|
assert.True(t, cfg.IsUpdateStyleAllowed(UpdateStyleMerge))
|
|
|
|
assert.False(t, cfg.IsUpdateStyleAllowed(UpdateStyleRebase))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRepoPRGetDefaultUpdateStyle(t *testing.T) {
|
|
|
|
defer test.MockVariableValue(&setting.Repository.PullRequest.DefaultUpdateStyle, "merge")()
|
|
|
|
|
|
|
|
var cfg PullRequestsConfig
|
|
|
|
cfg = PullRequestsConfig{
|
|
|
|
DefaultUpdateStyle: "",
|
|
|
|
}
|
|
|
|
assert.Equal(t, UpdateStyleMerge, cfg.GetDefaultUpdateStyle())
|
|
|
|
cfg = PullRequestsConfig{
|
|
|
|
DefaultUpdateStyle: "rebase",
|
|
|
|
}
|
|
|
|
assert.Equal(t, UpdateStyleRebase, cfg.GetDefaultUpdateStyle())
|
|
|
|
cfg = PullRequestsConfig{
|
|
|
|
DefaultUpdateStyle: "merge",
|
|
|
|
}
|
|
|
|
assert.Equal(t, UpdateStyleMerge, cfg.GetDefaultUpdateStyle())
|
|
|
|
|
|
|
|
setting.Repository.PullRequest.DefaultUpdateStyle = "rebase"
|
|
|
|
cfg = PullRequestsConfig{
|
|
|
|
DefaultUpdateStyle: "",
|
|
|
|
}
|
|
|
|
assert.Equal(t, UpdateStyleRebase, cfg.GetDefaultUpdateStyle())
|
|
|
|
cfg = PullRequestsConfig{
|
|
|
|
DefaultUpdateStyle: "rebase",
|
|
|
|
}
|
|
|
|
assert.Equal(t, UpdateStyleRebase, cfg.GetDefaultUpdateStyle())
|
|
|
|
cfg = PullRequestsConfig{
|
|
|
|
DefaultUpdateStyle: "merge",
|
|
|
|
}
|
|
|
|
assert.Equal(t, UpdateStyleMerge, cfg.GetDefaultUpdateStyle())
|
|
|
|
}
|