-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Fix all possible setting error related storages and added some tests #23911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
02747fe
Fix all possible setting error related storages and added some tests
lunny ae66d8f
Fix copyright year and some documentations
lunny c98d78f
Merge branch 'main' into lunny/storage_bug_fix
lunny f70d4c6
Fix lint
lunny b8bbccf
Merge branch 'main' into lunny/storage_bug_fix
lunny 40407b5
add some comments for getStorage
lunny d45b3af
Merge branch 'main' into lunny/storage_bug_fix
lunny 35f2a41
Merge branch 'main' into lunny/storage_bug_fix
lunny 7d16902
Fix bug
lunny 7cdd5f8
Merge branch 'main' into lunny/storage_bug_fix
lunny f7b93f3
Merge branch 'main' into lunny/storage_bug_fix
6543 0e173c2
Merge branch 'main' into lunny/storage_bug_fix
6543 31300e7
Merge branch 'main' into lunny/storage_bug_fix
6543 e85e9fb
Update modules/setting/storage.go
lunny 36d49ff
merge main branch
lunny 7f61c62
merge
lunny fb1ed84
Merge branch 'main' into lunny/storage_bug_fix
6543 d08c714
merge main branch
lunny 751d639
Merge branch 'lunny/storage_bug_fix' of github.com:lunny/gitea into l…
lunny 48113e1
Remove support for [actions] storage type because actions may have ma…
lunny 49ed138
Fix lint
lunny 531eadb
Merge branch 'main' into lunny/storage_bug_fix
lunny a781649
Fix read storage configuration from actions
lunny a4bd69c
Merge branch 'main' into lunny/storage_bug_fix
lunny 93714fd
refactor getStorage function
lunny 163d086
Fix comment
lunny d9ab5a0
Merge branch 'main' into lunny/storage_bug_fix
lunny fa85e06
Fix storage override sequence
lunny f4db800
Merge branch 'main' into lunny/storage_bug_fix
lunny e3aa03e
Improve getStorage
lunny 3e641b9
Merge branch 'main' into lunny/storage_bug_fix
lunny 7f6369a
Fix override
lunny f139b8c
Fix storage
lunny 2e28ce3
merge main branch
lunny e9853b1
Use explicit storage
lunny 40f21cf
Merge branch 'main' into lunny/storage_bug_fix
lunny 910bb3c
merge main branch
lunny a73e619
revert getstorage change
lunny f23e15e
merge main branch
lunny 1309698
Merge branch 'main' into lunny/storage_bug_fix
lunny eb1368a
Merge branch 'main' into lunny/storage_bug_fix
lunny 26e3aef
Fix all tests
lunny 9ecc419
Merge branch 'main' into lunny/storage_bug_fix
lunny 793936d
Fix lint
lunny 82b4ec2
Remove unused interface
lunny a055e53
improve code
lunny a4fe93f
Fix test
lunny 9bee6b8
Merge branch 'main' into lunny/storage_bug_fix
lunny c113c60
shadow possible token leak
lunny 10169b9
Merge branch 'main' into lunny/storage_bug_fix
lunny 1a7a50b
Follow wxiaoguang's suggestion
lunny 9461c21
fix
lunny a772b6c
update storage configuration documents
lunny 0f85d05
Merge branch 'main' into lunny/storage_bug_fix
lunny e47fb07
Follow wxiaoguang's suggestion
lunny 2d5726b
Follow wxiaoguang's suggestion
lunny 47e7b1b
Merge branch 'main' into lunny/storage_bug_fix
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package setting | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
ini "gopkg.in/ini.v1" | ||
) | ||
|
||
func Test_getStorageInheritNameSectionTypeForActions(t *testing.T) { | ||
iniStr := ` | ||
[storage] | ||
STORAGE_TYPE = minio | ||
` | ||
cfg, err := ini.Load([]byte(iniStr)) | ||
assert.NoError(t, err) | ||
assert.NoError(t, loadActionsFrom(cfg)) | ||
|
||
assert.EqualValues(t, "minio", Actions.Storage.Type) | ||
assert.EqualValues(t, "actions_log/", cfg.Section("actions").Key("MINIO_BASE_PATH").MustString("")) | ||
|
||
iniStr = ` | ||
[storage.actions_log] | ||
STORAGE_TYPE = minio | ||
` | ||
cfg, err = ini.Load([]byte(iniStr)) | ||
assert.NoError(t, err) | ||
assert.NoError(t, loadActionsFrom(cfg)) | ||
|
||
assert.EqualValues(t, "minio", Actions.Storage.Type) | ||
assert.EqualValues(t, "actions_log/", cfg.Section("actions").Key("MINIO_BASE_PATH").MustString("")) | ||
|
||
iniStr = ` | ||
[actions] | ||
STORAGE_TYPE = my_minio | ||
|
||
[storage.my_minio] | ||
STORAGE_TYPE = minio | ||
` | ||
cfg, err = ini.Load([]byte(iniStr)) | ||
assert.NoError(t, err) | ||
assert.NoError(t, loadActionsFrom(cfg)) | ||
|
||
assert.EqualValues(t, "minio", Actions.Storage.Type) | ||
assert.EqualValues(t, "actions_log/", cfg.Section("actions").Key("MINIO_BASE_PATH").MustString("")) | ||
|
||
iniStr = ` | ||
[actions] | ||
STORAGE_TYPE = my_minio | ||
MINIO_BASE_PATH = my_actions_log/ | ||
|
||
[storage.my_minio] | ||
STORAGE_TYPE = minio | ||
` | ||
cfg, err = ini.Load([]byte(iniStr)) | ||
assert.NoError(t, err) | ||
assert.NoError(t, loadActionsFrom(cfg)) | ||
|
||
assert.EqualValues(t, "minio", Actions.Storage.Type) | ||
assert.EqualValues(t, "my_actions_log/", cfg.Section("actions").Key("MINIO_BASE_PATH").MustString("")) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package setting | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
ini "gopkg.in/ini.v1" | ||
) | ||
|
||
func Test_getStorageCustomType(t *testing.T) { | ||
iniStr := ` | ||
[attachment] | ||
STORAGE_TYPE = my_minio | ||
MINIO_BUCKET = gitea-attachment | ||
|
||
[storage.my_minio] | ||
STORAGE_TYPE = minio | ||
MINIO_ENDPOINT = my_minio:9000 | ||
` | ||
cfg, err := ini.Load([]byte(iniStr)) | ||
assert.NoError(t, err) | ||
|
||
assert.NoError(t, loadAttachmentFrom(cfg)) | ||
|
||
assert.EqualValues(t, "minio", Attachment.Storage.Type) | ||
assert.EqualValues(t, "my_minio:9000", Attachment.Storage.Section.Key("MINIO_ENDPOINT").String()) | ||
assert.EqualValues(t, "gitea-attachment", Attachment.Storage.Section.Key("MINIO_BUCKET").String()) | ||
} | ||
|
||
func Test_getStorageNameSectionOverridesTypeSection(t *testing.T) { | ||
iniStr := ` | ||
[attachment] | ||
STORAGE_TYPE = minio | ||
|
||
[storage.attachments] | ||
MINIO_BUCKET = gitea-attachment | ||
|
||
[storage.minio] | ||
MINIO_BUCKET = gitea | ||
` | ||
cfg, err := ini.Load([]byte(iniStr)) | ||
assert.NoError(t, err) | ||
|
||
assert.NoError(t, loadAttachmentFrom(cfg)) | ||
|
||
assert.EqualValues(t, "minio", Attachment.Storage.Type) | ||
assert.EqualValues(t, "gitea-attachment", Attachment.Storage.Section.Key("MINIO_BUCKET").String()) | ||
} | ||
|
||
func Test_getStorageTypeSectionOverridesStorageSection(t *testing.T) { | ||
iniStr := ` | ||
[attachment] | ||
STORAGE_TYPE = minio | ||
|
||
[storage.minio] | ||
MINIO_BUCKET = gitea-minio | ||
|
||
[storage] | ||
MINIO_BUCKET = gitea | ||
` | ||
cfg, err := ini.Load([]byte(iniStr)) | ||
assert.NoError(t, err) | ||
|
||
assert.NoError(t, loadAttachmentFrom(cfg)) | ||
|
||
assert.EqualValues(t, "minio", Attachment.Storage.Type) | ||
assert.EqualValues(t, "gitea-minio", Attachment.Storage.Section.Key("MINIO_BUCKET").String()) | ||
} | ||
|
||
func Test_getStorageSpecificOverridesStorage(t *testing.T) { | ||
iniStr := ` | ||
[attachment] | ||
STORAGE_TYPE = minio | ||
MINIO_BUCKET = gitea-attachment | ||
|
||
[storage.attachments] | ||
MINIO_BUCKET = gitea | ||
|
||
[storage] | ||
STORAGE_TYPE = local | ||
` | ||
cfg, err := ini.Load([]byte(iniStr)) | ||
assert.NoError(t, err) | ||
|
||
assert.NoError(t, loadAttachmentFrom(cfg)) | ||
|
||
assert.EqualValues(t, "minio", Attachment.Storage.Type) | ||
assert.EqualValues(t, "gitea-attachment", Attachment.Storage.Section.Key("MINIO_BUCKET").String()) | ||
} | ||
|
||
func Test_getStorageGetDefaults(t *testing.T) { | ||
cfg, err := ini.Load([]byte("")) | ||
assert.NoError(t, err) | ||
|
||
assert.NoError(t, loadAttachmentFrom(cfg)) | ||
|
||
assert.EqualValues(t, "gitea", Attachment.Storage.Section.Key("MINIO_BUCKET").String()) | ||
} | ||
|
||
func Test_getStorageInheritNameSectionType(t *testing.T) { | ||
iniStr := ` | ||
[storage.attachments] | ||
STORAGE_TYPE = minio | ||
` | ||
cfg, err := ini.Load([]byte(iniStr)) | ||
assert.NoError(t, err) | ||
|
||
assert.NoError(t, loadAttachmentFrom(cfg)) | ||
|
||
assert.EqualValues(t, "minio", Attachment.Storage.Type) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.