Skip to content

Commit c355728

Browse files
authored
Remove unnecessary code (#24610)
As title, remove unnecessary code.
1 parent 29637b0 commit c355728

File tree

5 files changed

+8
-20
lines changed

5 files changed

+8
-20
lines changed

modules/indexer/issues/indexer_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestMain(m *testing.M) {
2626

2727
func TestBleveSearchIssues(t *testing.T) {
2828
assert.NoError(t, unittest.PrepareTestDatabase())
29-
setting.CfgProvider = setting.NewEmptyConfigProvider()
29+
setting.CfgProvider, _ = setting.NewConfigProviderFromData("")
3030

3131
tmpIndexerDir := t.TempDir()
3232

modules/indexer/stats/indexer_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestMain(m *testing.M) {
2828

2929
func TestRepoStatsIndex(t *testing.T) {
3030
assert.NoError(t, unittest.PrepareTestDatabase())
31-
setting.CfgProvider = setting.NewEmptyConfigProvider()
31+
setting.CfgProvider, _ = setting.NewConfigProviderFromData("")
3232

3333
setting.LoadQueueSettings()
3434

modules/setting/config_provider.go

-12
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ type ConfigProvider interface {
3030
Section(section string) ConfigSection
3131
NewSection(name string) (ConfigSection, error)
3232
GetSection(name string) (ConfigSection, error)
33-
DeleteSection(name string) error
3433
Save() error
3534
}
3635

@@ -40,12 +39,6 @@ type iniFileConfigProvider struct {
4039
newFile bool // whether the file has not existed previously
4140
}
4241

43-
// NewEmptyConfigProvider create a new empty config provider
44-
func NewEmptyConfigProvider() ConfigProvider {
45-
cp, _ := NewConfigProviderFromData("")
46-
return cp
47-
}
48-
4942
// NewConfigProviderFromData this function is only for testing
5043
func NewConfigProviderFromData(configContent string) (ConfigProvider, error) {
5144
var cfg *ini.File
@@ -121,11 +114,6 @@ func (p *iniFileConfigProvider) GetSection(name string) (ConfigSection, error) {
121114
return p.File.GetSection(name)
122115
}
123116

124-
func (p *iniFileConfigProvider) DeleteSection(name string) error {
125-
p.File.DeleteSection(name)
126-
return nil
127-
}
128-
129117
// Save save the content into file
130118
func (p *iniFileConfigProvider) Save() error {
131119
if p.opts.CustomConf == "" {

modules/setting/mailer_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
)
1111

1212
func Test_loadMailerFrom(t *testing.T) {
13-
iniFile := NewEmptyConfigProvider()
1413
kases := map[string]*Mailer{
1514
"smtp.mydomain.com": {
1615
SMTPAddr: "smtp.mydomain.com",
@@ -27,13 +26,13 @@ func Test_loadMailerFrom(t *testing.T) {
2726
}
2827
for host, kase := range kases {
2928
t.Run(host, func(t *testing.T) {
30-
iniFile.DeleteSection("mailer")
31-
sec := iniFile.Section("mailer")
29+
cfg, _ := NewConfigProviderFromData("")
30+
sec := cfg.Section("mailer")
3231
sec.NewKey("ENABLED", "true")
3332
sec.NewKey("HOST", host)
3433

3534
// Check mailer setting
36-
loadMailerFrom(iniFile)
35+
loadMailerFrom(cfg)
3736

3837
assert.EqualValues(t, kase.SMTPAddr, MailService.SMTPAddr)
3938
assert.EqualValues(t, kase.SMTPPort, MailService.SMTPPort)

modules/setting/packages_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import (
77
"testing"
88

99
"github.com/stretchr/testify/assert"
10-
ini "gopkg.in/ini.v1"
1110
)
1211

1312
func TestMustBytes(t *testing.T) {
1413
test := func(value string) int64 {
15-
sec, _ := ini.Empty().NewSection("test")
14+
cfg, err := NewConfigProviderFromData("[test]")
15+
assert.NoError(t, err)
16+
sec := cfg.Section("test")
1617
sec.NewKey("VALUE", value)
1718

1819
return mustBytes(sec, "VALUE")

0 commit comments

Comments
 (0)