You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mailer_test.go 916B

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