mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-25 14:35:40 +00:00
parent
29637b03b2
commit
c355728a6f
|
@ -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()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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 == "" {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in a new issue