mirror of
1
Fork 0

Remove unnecessary code (#24610)

As title, remove unnecessary code.
This commit is contained in:
Lunny Xiao 2023-05-10 12:57:06 +08:00 committed by GitHub
parent 29637b03b2
commit c355728a6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 20 deletions

View File

@ -26,7 +26,7 @@ func TestMain(m *testing.M) {
func TestBleveSearchIssues(t *testing.T) { func TestBleveSearchIssues(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase()) assert.NoError(t, unittest.PrepareTestDatabase())
setting.CfgProvider = setting.NewEmptyConfigProvider() setting.CfgProvider, _ = setting.NewConfigProviderFromData("")
tmpIndexerDir := t.TempDir() tmpIndexerDir := t.TempDir()

View File

@ -28,7 +28,7 @@ func TestMain(m *testing.M) {
func TestRepoStatsIndex(t *testing.T) { func TestRepoStatsIndex(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase()) assert.NoError(t, unittest.PrepareTestDatabase())
setting.CfgProvider = setting.NewEmptyConfigProvider() setting.CfgProvider, _ = setting.NewConfigProviderFromData("")
setting.LoadQueueSettings() setting.LoadQueueSettings()

View File

@ -30,7 +30,6 @@ type ConfigProvider interface {
Section(section string) ConfigSection Section(section string) ConfigSection
NewSection(name string) (ConfigSection, error) NewSection(name string) (ConfigSection, error)
GetSection(name string) (ConfigSection, error) GetSection(name string) (ConfigSection, error)
DeleteSection(name string) error
Save() error Save() error
} }
@ -40,12 +39,6 @@ type iniFileConfigProvider struct {
newFile bool // whether the file has not existed previously 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 // NewConfigProviderFromData this function is only for testing
func NewConfigProviderFromData(configContent string) (ConfigProvider, error) { func NewConfigProviderFromData(configContent string) (ConfigProvider, error) {
var cfg *ini.File var cfg *ini.File
@ -121,11 +114,6 @@ func (p *iniFileConfigProvider) GetSection(name string) (ConfigSection, error) {
return p.File.GetSection(name) return p.File.GetSection(name)
} }
func (p *iniFileConfigProvider) DeleteSection(name string) error {
p.File.DeleteSection(name)
return nil
}
// Save save the content into file // Save save the content into file
func (p *iniFileConfigProvider) Save() error { func (p *iniFileConfigProvider) Save() error {
if p.opts.CustomConf == "" { if p.opts.CustomConf == "" {

View File

@ -10,7 +10,6 @@ import (
) )
func Test_loadMailerFrom(t *testing.T) { func Test_loadMailerFrom(t *testing.T) {
iniFile := NewEmptyConfigProvider()
kases := map[string]*Mailer{ kases := map[string]*Mailer{
"smtp.mydomain.com": { "smtp.mydomain.com": {
SMTPAddr: "smtp.mydomain.com", SMTPAddr: "smtp.mydomain.com",
@ -27,13 +26,13 @@ func Test_loadMailerFrom(t *testing.T) {
} }
for host, kase := range kases { for host, kase := range kases {
t.Run(host, func(t *testing.T) { t.Run(host, func(t *testing.T) {
iniFile.DeleteSection("mailer") cfg, _ := NewConfigProviderFromData("")
sec := iniFile.Section("mailer") sec := cfg.Section("mailer")
sec.NewKey("ENABLED", "true") sec.NewKey("ENABLED", "true")
sec.NewKey("HOST", host) sec.NewKey("HOST", host)
// Check mailer setting // Check mailer setting
loadMailerFrom(iniFile) loadMailerFrom(cfg)
assert.EqualValues(t, kase.SMTPAddr, MailService.SMTPAddr) assert.EqualValues(t, kase.SMTPAddr, MailService.SMTPAddr)
assert.EqualValues(t, kase.SMTPPort, MailService.SMTPPort) assert.EqualValues(t, kase.SMTPPort, MailService.SMTPPort)

View File

@ -7,12 +7,13 @@ import (
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
ini "gopkg.in/ini.v1"
) )
func TestMustBytes(t *testing.T) { func TestMustBytes(t *testing.T) {
test := func(value string) int64 { 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) sec.NewKey("VALUE", value)
return mustBytes(sec, "VALUE") return mustBytes(sec, "VALUE")