aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2023-05-10 12:57:06 +0800
committerGitHub <noreply@github.com>2023-05-10 04:57:06 +0000
commitc355728a6fdfb35bc53e283d4447da098f39e3a2 (patch)
tree3e13e4741deba4475efc42c9ad496b171e8f93d0
parent29637b03b2976580613550aef878cc31139c3abf (diff)
downloadgitea-c355728a6fdfb35bc53e283d4447da098f39e3a2.tar.gz
gitea-c355728a6fdfb35bc53e283d4447da098f39e3a2.zip
Remove unnecessary code (#24610)
As title, remove unnecessary code.
-rw-r--r--modules/indexer/issues/indexer_test.go2
-rw-r--r--modules/indexer/stats/indexer_test.go2
-rw-r--r--modules/setting/config_provider.go12
-rw-r--r--modules/setting/mailer_test.go7
-rw-r--r--modules/setting/packages_test.go5
5 files changed, 8 insertions, 20 deletions
diff --git a/modules/indexer/issues/indexer_test.go b/modules/indexer/issues/indexer_test.go
index c7c7cea90f..a2d1794f4b 100644
--- a/modules/indexer/issues/indexer_test.go
+++ b/modules/indexer/issues/indexer_test.go
@@ -26,7 +26,7 @@ func TestMain(m *testing.M) {
func TestBleveSearchIssues(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- setting.CfgProvider = setting.NewEmptyConfigProvider()
+ setting.CfgProvider, _ = setting.NewConfigProviderFromData("")
tmpIndexerDir := t.TempDir()
diff --git a/modules/indexer/stats/indexer_test.go b/modules/indexer/stats/indexer_test.go
index be9c6659f1..2d9844f8c9 100644
--- a/modules/indexer/stats/indexer_test.go
+++ b/modules/indexer/stats/indexer_test.go
@@ -28,7 +28,7 @@ func TestMain(m *testing.M) {
func TestRepoStatsIndex(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- setting.CfgProvider = setting.NewEmptyConfigProvider()
+ setting.CfgProvider, _ = setting.NewConfigProviderFromData("")
setting.LoadQueueSettings()
diff --git a/modules/setting/config_provider.go b/modules/setting/config_provider.go
index 24825a6205..ce9ef72248 100644
--- a/modules/setting/config_provider.go
+++ b/modules/setting/config_provider.go
@@ -30,7 +30,6 @@ type ConfigProvider interface {
Section(section string) ConfigSection
NewSection(name string) (ConfigSection, error)
GetSection(name string) (ConfigSection, error)
- DeleteSection(name string) error
Save() error
}
@@ -40,12 +39,6 @@ type iniFileConfigProvider struct {
newFile bool // whether the file has not existed previously
}
-// NewEmptyConfigProvider create a new empty config provider
-func NewEmptyConfigProvider() ConfigProvider {
- cp, _ := NewConfigProviderFromData("")
- return cp
-}
-
// NewConfigProviderFromData this function is only for testing
func NewConfigProviderFromData(configContent string) (ConfigProvider, error) {
var cfg *ini.File
@@ -121,11 +114,6 @@ func (p *iniFileConfigProvider) GetSection(name string) (ConfigSection, error) {
return p.File.GetSection(name)
}
-func (p *iniFileConfigProvider) DeleteSection(name string) error {
- p.File.DeleteSection(name)
- return nil
-}
-
// Save save the content into file
func (p *iniFileConfigProvider) Save() error {
if p.opts.CustomConf == "" {
diff --git a/modules/setting/mailer_test.go b/modules/setting/mailer_test.go
index f65dbaf8f5..fbabf11378 100644
--- a/modules/setting/mailer_test.go
+++ b/modules/setting/mailer_test.go
@@ -10,7 +10,6 @@ import (
)
func Test_loadMailerFrom(t *testing.T) {
- iniFile := NewEmptyConfigProvider()
kases := map[string]*Mailer{
"smtp.mydomain.com": {
SMTPAddr: "smtp.mydomain.com",
@@ -27,13 +26,13 @@ func Test_loadMailerFrom(t *testing.T) {
}
for host, kase := range kases {
t.Run(host, func(t *testing.T) {
- iniFile.DeleteSection("mailer")
- sec := iniFile.Section("mailer")
+ cfg, _ := NewConfigProviderFromData("")
+ sec := cfg.Section("mailer")
sec.NewKey("ENABLED", "true")
sec.NewKey("HOST", host)
// Check mailer setting
- loadMailerFrom(iniFile)
+ loadMailerFrom(cfg)
assert.EqualValues(t, kase.SMTPAddr, MailService.SMTPAddr)
assert.EqualValues(t, kase.SMTPPort, MailService.SMTPPort)
diff --git a/modules/setting/packages_test.go b/modules/setting/packages_test.go
index 04d6e55834..d9f6e10528 100644
--- a/modules/setting/packages_test.go
+++ b/modules/setting/packages_test.go
@@ -7,12 +7,13 @@ import (
"testing"
"github.com/stretchr/testify/assert"
- ini "gopkg.in/ini.v1"
)
func TestMustBytes(t *testing.T) {
test := func(value string) int64 {
- sec, _ := ini.Empty().NewSection("test")
+ cfg, err := NewConfigProviderFromData("[test]")
+ assert.NoError(t, err)
+ sec := cfg.Section("test")
sec.NewKey("VALUE", value)
return mustBytes(sec, "VALUE")