code.gitea.io/gitea@v1.19.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  	ini "gopkg.in/ini.v1"
    11  )
    12  
    13  func Test_loadMailerFrom(t *testing.T) {
    14  	iniFile := ini.Empty()
    15  	kases := map[string]*Mailer{
    16  		"smtp.mydomain.com": {
    17  			SMTPAddr: "smtp.mydomain.com",
    18  			SMTPPort: "465",
    19  		},
    20  		"smtp.mydomain.com:123": {
    21  			SMTPAddr: "smtp.mydomain.com",
    22  			SMTPPort: "123",
    23  		},
    24  		":123": {
    25  			SMTPAddr: "127.0.0.1",
    26  			SMTPPort: "123",
    27  		},
    28  	}
    29  	for host, kase := range kases {
    30  		t.Run(host, func(t *testing.T) {
    31  			iniFile.DeleteSection("mailer")
    32  			sec := iniFile.Section("mailer")
    33  			sec.NewKey("ENABLED", "true")
    34  			sec.NewKey("HOST", host)
    35  
    36  			// Check mailer setting
    37  			loadMailerFrom(iniFile)
    38  
    39  			assert.EqualValues(t, kase.SMTPAddr, MailService.SMTPAddr)
    40  			assert.EqualValues(t, kase.SMTPPort, MailService.SMTPPort)
    41  		})
    42  	}
    43  }