From c355728a6fdfb35bc53e283d4447da098f39e3a2 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 10 May 2023 12:57:06 +0800 Subject: [PATCH] Remove unnecessary code (#24610) As title, remove unnecessary code. --- modules/indexer/issues/indexer_test.go | 2 +- modules/indexer/stats/indexer_test.go | 2 +- modules/setting/config_provider.go | 12 ------------ modules/setting/mailer_test.go | 7 +++---- modules/setting/packages_test.go | 5 +++-- 5 files changed, 8 insertions(+), 20 deletions(-) diff --git a/modules/indexer/issues/indexer_test.go b/modules/indexer/issues/indexer_test.go index c7c7cea90f0..a2d1794f4b6 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 be9c6659f14..2d9844f8c94 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 24825a62050..ce9ef72248a 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 f65dbaf8f57..fbabf113786 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 04d6e558346..d9f6e105287 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")