code.gitea.io/gitea@v1.22.3/modules/setting/mailer_test.go (about) 1 // Copyright 2022 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package setting 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func Test_loadMailerFrom(t *testing.T) { 13 kases := map[string]*Mailer{ 14 "smtp.mydomain.com": { 15 SMTPAddr: "smtp.mydomain.com", 16 SMTPPort: "465", 17 }, 18 "smtp.mydomain.com:123": { 19 SMTPAddr: "smtp.mydomain.com", 20 SMTPPort: "123", 21 }, 22 ":123": { 23 SMTPAddr: "127.0.0.1", 24 SMTPPort: "123", 25 }, 26 } 27 for host, kase := range kases { 28 t.Run(host, func(t *testing.T) { 29 cfg, _ := NewConfigProviderFromData("") 30 sec := cfg.Section("mailer") 31 sec.NewKey("ENABLED", "true") 32 sec.NewKey("HOST", host) 33 34 // Check mailer setting 35 loadMailerFrom(cfg) 36 37 assert.EqualValues(t, kase.SMTPAddr, MailService.SMTPAddr) 38 assert.EqualValues(t, kase.SMTPPort, MailService.SMTPPort) 39 }) 40 } 41 }