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 869B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. )
  8. func Test_loadMailerFrom(t *testing.T) {
  9. kases := map[string]*Mailer{
  10. "smtp.mydomain.com": {
  11. SMTPAddr: "smtp.mydomain.com",
  12. SMTPPort: "465",
  13. },
  14. "smtp.mydomain.com:123": {
  15. SMTPAddr: "smtp.mydomain.com",
  16. SMTPPort: "123",
  17. },
  18. ":123": {
  19. SMTPAddr: "127.0.0.1",
  20. SMTPPort: "123",
  21. },
  22. }
  23. for host, kase := range kases {
  24. t.Run(host, func(t *testing.T) {
  25. cfg, _ := NewConfigProviderFromData("")
  26. sec := cfg.Section("mailer")
  27. sec.NewKey("ENABLED", "true")
  28. sec.NewKey("HOST", host)
  29. // Check mailer setting
  30. loadMailerFrom(cfg)
  31. assert.EqualValues(t, kase.SMTPAddr, MailService.SMTPAddr)
  32. assert.EqualValues(t, kase.SMTPPort, MailService.SMTPPort)
  33. })
  34. }
  35. }