diff --git a/modules/indexer/issues/indexer_test.go b/modules/indexer/issues/indexer_test.go index c7c7cea90..a2d1794f4 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 be9c6659f..2d9844f8c 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 24825a620..ce9ef7224 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 f65dbaf8f..fbabf1137 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 04d6e5583..d9f6e1052 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")