diff options
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | api4/system.go | 6 | ||||
-rw-r--r-- | api4/team_test.go | 13 | ||||
-rw-r--r-- | api4/user_test.go | 10 | ||||
-rw-r--r-- | app/admin.go | 3 | ||||
-rw-r--r-- | app/email.go | 3 | ||||
-rw-r--r-- | app/file.go | 5 | ||||
-rw-r--r-- | cmd/mattermost/commands/server.go | 3 | ||||
-rwxr-xr-x | scripts/license-check.sh | 2 | ||||
-rw-r--r-- | services/filesstore/filesstore.go (renamed from utils/file_backend.go) | 2 | ||||
-rw-r--r-- | services/filesstore/filesstore_test.go (renamed from utils/file_backend_test.go) | 5 | ||||
-rw-r--r-- | services/filesstore/localstore.go (renamed from utils/file_backend_local.go) | 5 | ||||
-rw-r--r-- | services/filesstore/mocks/FileBackend.go | 215 | ||||
-rw-r--r-- | services/filesstore/s3store.go (renamed from utils/file_backend_s3.go) | 2 | ||||
-rw-r--r-- | services/filesstore/s3store_test.go (renamed from utils/file_backend_s3_test.go) | 2 | ||||
-rw-r--r-- | services/mailservice/inbucket.go (renamed from utils/inbucket.go) | 2 | ||||
-rw-r--r-- | services/mailservice/mail.go (renamed from utils/mail.go) | 14 | ||||
-rw-r--r-- | services/mailservice/mail_test.go (renamed from utils/mail_test.go) | 20 |
18 files changed, 273 insertions, 43 deletions
@@ -287,6 +287,10 @@ store-mocks: ## Creates mock files. go get -u github.com/vektra/mockery/... $(GOPATH)/bin/mockery -dir store -all -output store/storetest/mocks -note 'Regenerate this file using `make store-mocks`.' +filesstore-mocks: ## Creates mock files. + go get -u github.com/vektra/mockery/... + $(GOPATH)/bin/mockery -dir services/filesstore -all -output services/filesstore/mocks -note 'Regenerate this file using `make filesstore-mocks`.' + ldap-mocks: ## Creates mock files for ldap. go get -u github.com/vektra/mockery/... $(GOPATH)/bin/mockery -dir enterprise/ldap -all -output enterprise/ldap/mocks -note 'Regenerate this file using `make ldap-mocks`.' diff --git a/api4/system.go b/api4/system.go index 65d3b424b..2f6e53ab8 100644 --- a/api4/system.go +++ b/api4/system.go @@ -12,7 +12,7 @@ import ( "github.com/mattermost/mattermost-server/mlog" "github.com/mattermost/mattermost-server/model" - "github.com/mattermost/mattermost-server/utils" + "github.com/mattermost/mattermost-server/services/filesstore" ) func (api *API) InitSystem() { @@ -427,7 +427,7 @@ func testS3(c *Context, w http.ResponseWriter, r *http.Request) { return } - err := utils.CheckMandatoryS3Fields(&cfg.FileSettings) + err := filesstore.CheckMandatoryS3Fields(&cfg.FileSettings) if err != nil { c.Err = err return @@ -438,7 +438,7 @@ func testS3(c *Context, w http.ResponseWriter, r *http.Request) { } license := c.App.License() - backend, appErr := utils.NewFileBackend(&cfg.FileSettings, license != nil && *license.Features.Compliance) + backend, appErr := filesstore.NewFileBackend(&cfg.FileSettings, license != nil && *license.Features.Compliance) if appErr == nil { appErr = backend.TestConnection() } diff --git a/api4/team_test.go b/api4/team_test.go index 547b8d4a9..8f1027cc5 100644 --- a/api4/team_test.go +++ b/api4/team_test.go @@ -15,6 +15,7 @@ import ( "github.com/mattermost/mattermost-server/app" "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/services/mailservice" "github.com/mattermost/mattermost-server/utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -1894,8 +1895,8 @@ func TestInviteUsersToTeam(t *testing.T) { emailList := []string{user1, user2} //Delete all the messages before check the sample email - utils.DeleteMailBox(user1) - utils.DeleteMailBox(user2) + mailservice.DeleteMailBox(user1) + mailservice.DeleteMailBox(user2) enableEmailInvitations := *th.App.Config().ServiceSettings.EnableEmailInvitations restrictCreationToDomains := th.App.Config().TeamSettings.RestrictCreationToDomains @@ -1925,10 +1926,10 @@ func TestInviteUsersToTeam(t *testing.T) { //Check if the email was send to the rigth email address for _, email := range emailList { - var resultsMailbox utils.JSONMessageHeaderInbucket - err := utils.RetryInbucket(5, func() error { + var resultsMailbox mailservice.JSONMessageHeaderInbucket + err := mailservice.RetryInbucket(5, func() error { var err error - resultsMailbox, err = utils.GetMailBox(email) + resultsMailbox, err = mailservice.GetMailBox(email) return err }) if err != nil { @@ -1939,7 +1940,7 @@ func TestInviteUsersToTeam(t *testing.T) { if !strings.ContainsAny(resultsMailbox[len(resultsMailbox)-1].To[0], email) { t.Fatal("Wrong To recipient") } else { - if resultsEmail, err := utils.GetMessageFromMailbox(email, resultsMailbox[len(resultsMailbox)-1].ID); err == nil { + if resultsEmail, err := mailservice.GetMessageFromMailbox(email, resultsMailbox[len(resultsMailbox)-1].ID); err == nil { if resultsEmail.Subject != expectedSubject { t.Log(resultsEmail.Subject) t.Log(expectedSubject) diff --git a/api4/user_test.go b/api4/user_test.go index e624d747d..fd60a40ee 100644 --- a/api4/user_test.go +++ b/api4/user_test.go @@ -1919,7 +1919,7 @@ func TestUpdateUserPassword(t *testing.T) { Client.Logout() user := th.BasicUser // Delete all the messages before check the reset password - utils.DeleteMailBox(user.Email) + mailservice.DeleteMailBox(user.Email) success, resp := Client.SendPasswordResetEmail(user.Email) CheckNoError(t, resp) if !success { @@ -1934,10 +1934,10 @@ func TestUpdateUserPassword(t *testing.T) { t.Fatal("should have succeeded") } // Check if the email was send to the right email address and the recovery key match - var resultsMailbox utils.JSONMessageHeaderInbucket - err := utils.RetryInbucket(5, func() error { + var resultsMailbox mailservice.JSONMessageHeaderInbucket + err := mailservice.RetryInbucket(5, func() error { var err error - resultsMailbox, err = utils.GetMailBox(user.Email) + resultsMailbox, err = mailservice.GetMailBox(user.Email) return err }) if err != nil { @@ -1949,7 +1949,7 @@ func TestUpdateUserPassword(t *testing.T) { if !strings.ContainsAny(resultsMailbox[0].To[0], user.Email) { t.Fatal("Wrong To recipient") } else { - if resultsEmail, err := utils.GetMessageFromMailbox(user.Email, resultsMailbox[0].ID); err == nil { + if resultsEmail, err := mailservice.GetMessageFromMailbox(user.Email, resultsMailbox[0].ID); err == nil { loc := strings.Index(resultsEmail.Body.Text, "token=") if loc == -1 { t.Log(resultsEmail.Body.Text) diff --git a/app/admin.go b/app/admin.go index 892e2d16b..940d85410 100644 --- a/app/admin.go +++ b/app/admin.go @@ -15,6 +15,7 @@ import ( "github.com/mattermost/mattermost-server/mlog" "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/services/mailservice" "github.com/mattermost/mattermost-server/utils" ) @@ -242,7 +243,7 @@ func (a *App) TestEmail(userId string, cfg *model.Config) *model.AppError { } else { T := utils.GetUserTranslations(user.Locale) license := a.License() - if err := utils.SendMailUsingConfig(user.Email, T("api.admin.test_email.subject"), T("api.admin.test_email.body"), cfg, license != nil && *license.Features.Compliance); err != nil { + if err := mailservice.SendMailUsingConfig(user.Email, T("api.admin.test_email.subject"), T("api.admin.test_email.body"), cfg, license != nil && *license.Features.Compliance); err != nil { return model.NewAppError("testEmail", "app.admin.test_email.failure", map[string]interface{}{"Error": err.Error()}, "", http.StatusInternalServerError) } } diff --git a/app/email.go b/app/email.go index 8d6535e2b..eefe83a81 100644 --- a/app/email.go +++ b/app/email.go @@ -16,6 +16,7 @@ import ( "github.com/mattermost/mattermost-server/mlog" "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/services/mailservice" "github.com/mattermost/mattermost-server/utils" ) @@ -402,5 +403,5 @@ func (a *App) SendDeactivateAccountEmail(email string, locale, siteURL string) * func (a *App) SendMail(to, subject, htmlBody string) *model.AppError { license := a.License() - return utils.SendMailUsingConfig(to, subject, htmlBody, a.Config(), license != nil && *license.Features.Compliance) + return mailservice.SendMailUsingConfig(to, subject, htmlBody, a.Config(), license != nil && *license.Features.Compliance) } diff --git a/app/file.go b/app/file.go index 278990b49..5dfc23bd8 100644 --- a/app/file.go +++ b/app/file.go @@ -29,6 +29,7 @@ import ( "github.com/mattermost/mattermost-server/mlog" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/plugin" + "github.com/mattermost/mattermost-server/services/filesstore" "github.com/mattermost/mattermost-server/utils" ) @@ -58,9 +59,9 @@ const ( IMAGE_PREVIEW_PIXEL_WIDTH = 1920 ) -func (a *App) FileBackend() (utils.FileBackend, *model.AppError) { +func (a *App) FileBackend() (filesstore.FileBackend, *model.AppError) { license := a.License() - return utils.NewFileBackend(&a.Config().FileSettings, license != nil && *license.Features.Compliance) + return filesstore.NewFileBackend(&a.Config().FileSettings, license != nil && *license.Features.Compliance) } func (a *App) ReadFile(path string) ([]byte, *model.AppError) { diff --git a/cmd/mattermost/commands/server.go b/cmd/mattermost/commands/server.go index 95dc2f1c7..e996e6a2e 100644 --- a/cmd/mattermost/commands/server.go +++ b/cmd/mattermost/commands/server.go @@ -17,6 +17,7 @@ import ( "github.com/mattermost/mattermost-server/manualtesting" "github.com/mattermost/mattermost-server/mlog" "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/services/mailservice" "github.com/mattermost/mattermost-server/utils" "github.com/mattermost/mattermost-server/web" "github.com/mattermost/mattermost-server/wsapi" @@ -67,7 +68,7 @@ func runServer(configFileLocation string, disableConfigWatch bool, usedPlatform } defer a.Shutdown() - utils.TestConnection(a.Config()) + mailservice.TestConnection(a.Config()) pwd, _ := os.Getwd() if usedPlatform { diff --git a/scripts/license-check.sh b/scripts/license-check.sh index a6187829d..c9c60e081 100755 --- a/scripts/license-check.sh +++ b/scripts/license-check.sh @@ -5,7 +5,7 @@ count=0 for fileType in GoFiles; do for file in `go list -f $'{{range .GoFiles}}{{$.Dir}}/{{.}}\n{{end}}' "$@"`; do case $file in - */utils/lru.go|*/store/storetest/mocks/*|*/app/plugin/jira/plugin_*|*/plugin/plugintest/*|*/app/plugin/zoom/plugin_*) + */utils/lru.go|*/store/storetest/mocks/*|*/services/*/mocks/*|*/app/plugin/jira/plugin_*|*/plugin/plugintest/*|*/app/plugin/zoom/plugin_*) # Third-party, doesn't require a header. ;; *) diff --git a/utils/file_backend.go b/services/filesstore/filesstore.go index 368e1ba28..59b3121ff 100644 --- a/utils/file_backend.go +++ b/services/filesstore/filesstore.go @@ -1,7 +1,7 @@ // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -package utils +package filesstore import ( "io" diff --git a/utils/file_backend_test.go b/services/filesstore/filesstore_test.go index f7ce7ca61..270f6e9f9 100644 --- a/utils/file_backend_test.go +++ b/services/filesstore/filesstore_test.go @@ -1,7 +1,7 @@ // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -package utils +package filesstore import ( "bytes" @@ -15,6 +15,7 @@ import ( "github.com/mattermost/mattermost-server/mlog" "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/utils" ) type FileBackendTestSuite struct { @@ -81,7 +82,7 @@ func runBackendTest(t *testing.T, encrypt bool) { } func (s *FileBackendTestSuite) SetupTest() { - TranslationsPreInit() + utils.TranslationsPreInit() backend, err := NewFileBackend(&s.settings, true) require.Nil(s.T(), err) diff --git a/utils/file_backend_local.go b/services/filesstore/localstore.go index 681ab9234..8d79a982e 100644 --- a/utils/file_backend_local.go +++ b/services/filesstore/localstore.go @@ -1,7 +1,7 @@ // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -package utils +package filesstore import ( "bytes" @@ -13,6 +13,7 @@ import ( "github.com/mattermost/mattermost-server/mlog" "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/utils" ) const ( @@ -62,7 +63,7 @@ func (b *LocalFileBackend) FileExists(path string) (bool, *model.AppError) { } func (b *LocalFileBackend) CopyFile(oldPath, newPath string) *model.AppError { - if err := CopyFile(filepath.Join(b.directory, oldPath), filepath.Join(b.directory, newPath)); err != nil { + if err := utils.CopyFile(filepath.Join(b.directory, oldPath), filepath.Join(b.directory, newPath)); err != nil { return model.NewAppError("copyFile", "api.file.move_file.rename.app_error", nil, err.Error(), http.StatusInternalServerError) } return nil diff --git a/services/filesstore/mocks/FileBackend.go b/services/filesstore/mocks/FileBackend.go new file mode 100644 index 000000000..5d75ae5d1 --- /dev/null +++ b/services/filesstore/mocks/FileBackend.go @@ -0,0 +1,215 @@ +// Code generated by mockery v1.0.0. DO NOT EDIT. + +// Regenerate this file using `make files-store-mocks`. + +package mocks + +import io "io" +import mock "github.com/stretchr/testify/mock" +import model "github.com/mattermost/mattermost-server/model" + +// FileBackend is an autogenerated mock type for the FileBackend type +type FileBackend struct { + mock.Mock +} + +// CopyFile provides a mock function with given fields: oldPath, newPath +func (_m *FileBackend) CopyFile(oldPath string, newPath string) *model.AppError { + ret := _m.Called(oldPath, newPath) + + var r0 *model.AppError + if rf, ok := ret.Get(0).(func(string, string) *model.AppError); ok { + r0 = rf(oldPath, newPath) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.AppError) + } + } + + return r0 +} + +// FileExists provides a mock function with given fields: path +func (_m *FileBackend) FileExists(path string) (bool, *model.AppError) { + ret := _m.Called(path) + + var r0 bool + if rf, ok := ret.Get(0).(func(string) bool); ok { + r0 = rf(path) + } else { + r0 = ret.Get(0).(bool) + } + + var r1 *model.AppError + if rf, ok := ret.Get(1).(func(string) *model.AppError); ok { + r1 = rf(path) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*model.AppError) + } + } + + return r0, r1 +} + +// ListDirectory provides a mock function with given fields: path +func (_m *FileBackend) ListDirectory(path string) (*[]string, *model.AppError) { + ret := _m.Called(path) + + var r0 *[]string + if rf, ok := ret.Get(0).(func(string) *[]string); ok { + r0 = rf(path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*[]string) + } + } + + var r1 *model.AppError + if rf, ok := ret.Get(1).(func(string) *model.AppError); ok { + r1 = rf(path) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*model.AppError) + } + } + + return r0, r1 +} + +// MoveFile provides a mock function with given fields: oldPath, newPath +func (_m *FileBackend) MoveFile(oldPath string, newPath string) *model.AppError { + ret := _m.Called(oldPath, newPath) + + var r0 *model.AppError + if rf, ok := ret.Get(0).(func(string, string) *model.AppError); ok { + r0 = rf(oldPath, newPath) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.AppError) + } + } + + return r0 +} + +// ReadFile provides a mock function with given fields: path +func (_m *FileBackend) ReadFile(path string) ([]byte, *model.AppError) { + ret := _m.Called(path) + + var r0 []byte + if rf, ok := ret.Get(0).(func(string) []byte); ok { + r0 = rf(path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + + var r1 *model.AppError + if rf, ok := ret.Get(1).(func(string) *model.AppError); ok { + r1 = rf(path) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*model.AppError) + } + } + + return r0, r1 +} + +// Reader provides a mock function with given fields: path +func (_m *FileBackend) Reader(path string) (io.ReadCloser, *model.AppError) { + ret := _m.Called(path) + + var r0 io.ReadCloser + if rf, ok := ret.Get(0).(func(string) io.ReadCloser); ok { + r0 = rf(path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(io.ReadCloser) + } + } + + var r1 *model.AppError + if rf, ok := ret.Get(1).(func(string) *model.AppError); ok { + r1 = rf(path) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*model.AppError) + } + } + + return r0, r1 +} + +// RemoveDirectory provides a mock function with given fields: path +func (_m *FileBackend) RemoveDirectory(path string) *model.AppError { + ret := _m.Called(path) + + var r0 *model.AppError + if rf, ok := ret.Get(0).(func(string) *model.AppError); ok { + r0 = rf(path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.AppError) + } + } + + return r0 +} + +// RemoveFile provides a mock function with given fields: path +func (_m *FileBackend) RemoveFile(path string) *model.AppError { + ret := _m.Called(path) + + var r0 *model.AppError + if rf, ok := ret.Get(0).(func(string) *model.AppError); ok { + r0 = rf(path) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.AppError) + } + } + + return r0 +} + +// TestConnection provides a mock function with given fields: +func (_m *FileBackend) TestConnection() *model.AppError { + ret := _m.Called() + + var r0 *model.AppError + if rf, ok := ret.Get(0).(func() *model.AppError); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.AppError) + } + } + + return r0 +} + +// WriteFile provides a mock function with given fields: fr, path +func (_m *FileBackend) WriteFile(fr io.Reader, path string) (int64, *model.AppError) { + ret := _m.Called(fr, path) + + var r0 int64 + if rf, ok := ret.Get(0).(func(io.Reader, string) int64); ok { + r0 = rf(fr, path) + } else { + r0 = ret.Get(0).(int64) + } + + var r1 *model.AppError + if rf, ok := ret.Get(1).(func(io.Reader, string) *model.AppError); ok { + r1 = rf(fr, path) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*model.AppError) + } + } + + return r0, r1 +} diff --git a/utils/file_backend_s3.go b/services/filesstore/s3store.go index f5f96f878..0a0f057ea 100644 --- a/utils/file_backend_s3.go +++ b/services/filesstore/s3store.go @@ -1,7 +1,7 @@ // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -package utils +package filesstore import ( "bytes" diff --git a/utils/file_backend_s3_test.go b/services/filesstore/s3store_test.go index a8834f226..a958a1f3f 100644 --- a/utils/file_backend_s3_test.go +++ b/services/filesstore/s3store_test.go @@ -1,7 +1,7 @@ // Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -package utils +package filesstore import ( "testing" diff --git a/utils/inbucket.go b/services/mailservice/inbucket.go index 5c40d5757..28922d660 100644 --- a/utils/inbucket.go +++ b/services/mailservice/inbucket.go @@ -1,7 +1,7 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -package utils +package mailservice import ( "bytes" diff --git a/utils/mail.go b/services/mailservice/mail.go index 750cb64fe..e9b689f20 100644 --- a/utils/mail.go +++ b/services/mailservice/mail.go @@ -1,7 +1,7 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -package utils +package mailservice import ( "crypto/tls" @@ -21,6 +21,8 @@ import ( "github.com/jaytaylor/html2text" "github.com/mattermost/mattermost-server/mlog" "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/services/filesstore" + "github.com/mattermost/mattermost-server/utils" ) func encodeRFC2047Word(s string) string { @@ -160,7 +162,7 @@ func NewSMTPClientAdvanced(conn net.Conn, hostname string, connectionInfo *SmtpC func NewSMTPClient(conn net.Conn, config *model.Config) (*smtp.Client, *model.AppError) { return NewSMTPClientAdvanced( conn, - GetHostnameFromSiteURL(*config.ServiceSettings.SiteURL), + utils.GetHostnameFromSiteURL(*config.ServiceSettings.SiteURL), &SmtpConnectionInfo{ ConnectionSecurity: config.EmailSettings.ConnectionSecurity, SkipCertVerification: *config.EmailSettings.SkipServerCertificateVerification, @@ -181,14 +183,14 @@ func TestConnection(config *model.Config) { conn, err1 := ConnectToSMTPServer(config) if err1 != nil { - mlog.Error(fmt.Sprintf("SMTP server settings do not appear to be configured properly err=%v details=%v", T(err1.Message), err1.DetailedError)) + mlog.Error(fmt.Sprintf("SMTP server settings do not appear to be configured properly err=%v details=%v", utils.T(err1.Message), err1.DetailedError)) return } defer conn.Close() c, err2 := NewSMTPClient(conn, config) if err2 != nil { - mlog.Error(fmt.Sprintf("SMTP server settings do not appear to be configured properly err=%v details=%v", T(err2.Message), err2.DetailedError)) + mlog.Error(fmt.Sprintf("SMTP server settings do not appear to be configured properly err=%v details=%v", utils.T(err2.Message), err2.DetailedError)) return } defer c.Quit() @@ -220,7 +222,7 @@ func SendMailUsingConfigAdvanced(mimeTo, smtpTo string, from mail.Address, subje defer c.Quit() defer c.Close() - fileBackend, err := NewFileBackend(&config.FileSettings, enableComplianceFeatures) + fileBackend, err := filesstore.NewFileBackend(&config.FileSettings, enableComplianceFeatures) if err != nil { return err } @@ -228,7 +230,7 @@ func SendMailUsingConfigAdvanced(mimeTo, smtpTo string, from mail.Address, subje return SendMail(c, mimeTo, smtpTo, from, subject, htmlBody, attachments, mimeHeaders, fileBackend, time.Now()) } -func SendMail(c *smtp.Client, mimeTo, smtpTo string, from mail.Address, subject, htmlBody string, attachments []*model.FileInfo, mimeHeaders map[string]string, fileBackend FileBackend, date time.Time) *model.AppError { +func SendMail(c *smtp.Client, mimeTo, smtpTo string, from mail.Address, subject, htmlBody string, attachments []*model.FileInfo, mimeHeaders map[string]string, fileBackend filesstore.FileBackend, date time.Time) *model.AppError { mlog.Debug(fmt.Sprintf("sending mail to %v with subject of '%v'", smtpTo, subject)) htmlMessage := "\r\n<html><body>" + htmlBody + "</body></html>" diff --git a/utils/mail_test.go b/services/mailservice/mail_test.go index 4cb2d7594..9ad48c703 100644 --- a/utils/mail_test.go +++ b/services/mailservice/mail_test.go @@ -1,7 +1,7 @@ // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -package utils +package mailservice import ( "bytes" @@ -13,12 +13,14 @@ import ( "net/smtp" "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/services/filesstore" + "github.com/mattermost/mattermost-server/utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestMailConnectionFromConfig(t *testing.T) { - cfg, _, _, err := LoadConfig("config.json") + cfg, _, _, err := utils.LoadConfig("config.json") require.Nil(t, err) if conn, err := ConnectToSMTPServer(cfg); err != nil { @@ -41,7 +43,7 @@ func TestMailConnectionFromConfig(t *testing.T) { } func TestMailConnectionAdvanced(t *testing.T) { - cfg, _, _, err := LoadConfig("config.json") + cfg, _, _, err := utils.LoadConfig("config.json") require.Nil(t, err) if conn, err := ConnectToSMTPServerAdvanced( @@ -58,7 +60,7 @@ func TestMailConnectionAdvanced(t *testing.T) { } else { if _, err1 := NewSMTPClientAdvanced( conn, - GetHostnameFromSiteURL(*cfg.ServiceSettings.SiteURL), + utils.GetHostnameFromSiteURL(*cfg.ServiceSettings.SiteURL), &SmtpConnectionInfo{ ConnectionSecurity: cfg.EmailSettings.ConnectionSecurity, SkipCertVerification: *cfg.EmailSettings.SkipServerCertificateVerification, @@ -91,9 +93,9 @@ func TestMailConnectionAdvanced(t *testing.T) { } func TestSendMailUsingConfig(t *testing.T) { - cfg, _, _, err := LoadConfig("config.json") + cfg, _, _, err := utils.LoadConfig("config.json") require.Nil(t, err) - T = GetUserTranslations("en") + utils.T = utils.GetUserTranslations("en") var emailTo = "test@example.com" var emailSubject = "Testing this email" @@ -133,9 +135,9 @@ func TestSendMailUsingConfig(t *testing.T) { } func TestSendMailUsingConfigAdvanced(t *testing.T) { - cfg, _, _, err := LoadConfig("config.json") + cfg, _, _, err := utils.LoadConfig("config.json") require.Nil(t, err) - T = GetUserTranslations("en") + utils.T = utils.GetUserTranslations("en") var mimeTo = "test@example.com" var smtpTo = "test2@example.com" @@ -146,7 +148,7 @@ func TestSendMailUsingConfigAdvanced(t *testing.T) { //Delete all the messages before check the sample email DeleteMailBox(smtpTo) - fileBackend, err := NewFileBackend(&cfg.FileSettings, true) + fileBackend, err := filesstore.NewFileBackend(&cfg.FileSettings, true) assert.Nil(t, err) // create two files with the same name that will both be attached to the email |