-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
The design is very flexible, but not implemented correctly. This commit fixes several issues: * Costom storage type stated in https://docs.gitea.io/en-us/config-cheat-sheet/#storage-storage not working * [storage.attachments], [storage.minio] section not respected Signed-off-by: 胡玮文 <huww98@outlook.com> Co-authored-by: 胡玮文 <huww98@outlook.com>
- Loading branch information
Showing
2 changed files
with
177 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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 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,164 @@ | ||
// Copyright 2020 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
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, _ = ini.Load([]byte(iniStr)) | ||
|
||
sec := Cfg.Section("attachment") | ||
storageType := sec.Key("STORAGE_TYPE").MustString("") | ||
storage := getStorage("attachments", storageType, sec) | ||
|
||
assert.EqualValues(t, "minio", storage.Type) | ||
assert.EqualValues(t, "my_minio:9000", storage.Section.Key("MINIO_ENDPOINT").String()) | ||
assert.EqualValues(t, "gitea-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, _ = ini.Load([]byte(iniStr)) | ||
|
||
sec := Cfg.Section("attachment") | ||
storageType := sec.Key("STORAGE_TYPE").MustString("") | ||
storage := getStorage("attachments", storageType, sec) | ||
|
||
assert.EqualValues(t, "minio", storage.Type) | ||
assert.EqualValues(t, "gitea-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, _ = ini.Load([]byte(iniStr)) | ||
|
||
sec := Cfg.Section("attachment") | ||
storageType := sec.Key("STORAGE_TYPE").MustString("") | ||
storage := getStorage("attachments", storageType, sec) | ||
|
||
assert.EqualValues(t, "minio", storage.Type) | ||
assert.EqualValues(t, "gitea-minio", storage.Section.Key("MINIO_BUCKET").String()) | ||
} | ||
|
||
func Test_getStorageSpecificOverridesStorage(t *testing.T) { | ||
iniStr := ` | ||
[attachment] | ||
MINIO_BUCKET = gitea-attachment | ||
[storage.attachments] | ||
MINIO_BUCKET = gitea | ||
` | ||
Cfg, _ = ini.Load([]byte(iniStr)) | ||
|
||
sec := Cfg.Section("attachment") | ||
storageType := sec.Key("STORAGE_TYPE").MustString("") | ||
storage := getStorage("attachments", storageType, sec) | ||
|
||
assert.EqualValues(t, "gitea-attachment", storage.Section.Key("MINIO_BUCKET").String()) | ||
} | ||
|
||
func Test_getStorageGetDefaults(t *testing.T) { | ||
Cfg, _ = ini.Load([]byte("")) | ||
|
||
sec := Cfg.Section("attachment") | ||
storageType := sec.Key("STORAGE_TYPE").MustString("") | ||
storage := getStorage("attachments", storageType, sec) | ||
|
||
assert.EqualValues(t, "gitea", storage.Section.Key("MINIO_BUCKET").String()) | ||
} | ||
|
||
func Test_getStorageMultipleName(t *testing.T) { | ||
iniStr := ` | ||
[lfs] | ||
MINIO_BUCKET = gitea-lfs | ||
[attachment] | ||
MINIO_BUCKET = gitea-attachment | ||
[storage] | ||
MINIO_BUCKET = gitea-storage | ||
` | ||
Cfg, _ = ini.Load([]byte(iniStr)) | ||
|
||
{ | ||
sec := Cfg.Section("attachment") | ||
storageType := sec.Key("STORAGE_TYPE").MustString("") | ||
storage := getStorage("attachments", storageType, sec) | ||
|
||
assert.EqualValues(t, "gitea-attachment", storage.Section.Key("MINIO_BUCKET").String()) | ||
} | ||
{ | ||
sec := Cfg.Section("lfs") | ||
storageType := sec.Key("STORAGE_TYPE").MustString("") | ||
storage := getStorage("lfs", storageType, sec) | ||
|
||
assert.EqualValues(t, "gitea-lfs", storage.Section.Key("MINIO_BUCKET").String()) | ||
} | ||
{ | ||
sec := Cfg.Section("avatar") | ||
storageType := sec.Key("STORAGE_TYPE").MustString("") | ||
storage := getStorage("avatars", storageType, sec) | ||
|
||
assert.EqualValues(t, "gitea-storage", storage.Section.Key("MINIO_BUCKET").String()) | ||
} | ||
} | ||
|
||
func Test_getStorageUseOtherNameAsType(t *testing.T) { | ||
iniStr := ` | ||
[attachment] | ||
STORAGE_TYPE = lfs | ||
[storage.lfs] | ||
MINIO_BUCKET = gitea-storage | ||
` | ||
Cfg, _ = ini.Load([]byte(iniStr)) | ||
|
||
{ | ||
sec := Cfg.Section("attachment") | ||
storageType := sec.Key("STORAGE_TYPE").MustString("") | ||
storage := getStorage("attachments", storageType, sec) | ||
|
||
assert.EqualValues(t, "gitea-storage", storage.Section.Key("MINIO_BUCKET").String()) | ||
} | ||
{ | ||
sec := Cfg.Section("lfs") | ||
storageType := sec.Key("STORAGE_TYPE").MustString("") | ||
storage := getStorage("lfs", storageType, sec) | ||
|
||
assert.EqualValues(t, "gitea-storage", storage.Section.Key("MINIO_BUCKET").String()) | ||
} | ||
} |