mirror of
https://gitlab.com/commento/commento.git
synced 2025-06-29 22:56:37 -04:00
api: Add go files
I know this is a huge commit, but I can't be bothered to check this in part by part.
This commit is contained in:
63
api/smtp_configure_test.go
Normal file
63
api/smtp_configure_test.go
Normal file
@ -0,0 +1,63 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func cleanSmtpVars() {
|
||||
for _, env := range []string{"SMTP_USERNAME", "SMTP_PASSWORD", "SMTP_HOST", "SMTP_FROM_ADDRESS"} {
|
||||
os.Setenv(env, "")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSmtpConfigureBasics(t *testing.T) {
|
||||
failTestOnError(t, setupTestEnv())
|
||||
|
||||
os.Setenv("SMTP_USERNAME", "test@example.com")
|
||||
os.Setenv("SMTP_PASSWORD", "hunter2")
|
||||
os.Setenv("SMTP_HOST", "smtp.commento.io")
|
||||
os.Setenv("SMTP_FROM_ADDRESS", "no-reply@commento.io")
|
||||
|
||||
if err := smtpConfigure(); err != nil {
|
||||
t.Errorf("unexpected error when configuring SMTP: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
cleanSmtpVars()
|
||||
}
|
||||
|
||||
func TestSmtpConfigureEmptyHost(t *testing.T) {
|
||||
failTestOnError(t, setupTestEnv())
|
||||
|
||||
os.Setenv("SMTP_USERNAME", "test@example.com")
|
||||
os.Setenv("SMTP_PASSWORD", "hunter2")
|
||||
os.Setenv("SMTP_FROM_ADDRESS", "no-reply@commento.io")
|
||||
|
||||
if err := smtpConfigure(); err != nil {
|
||||
t.Errorf("unexpected error when configuring SMTP: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if smtpConfigured {
|
||||
t.Errorf("SMTP configured when it should not be due to empty SMTP_HOST")
|
||||
return
|
||||
}
|
||||
|
||||
cleanSmtpVars()
|
||||
}
|
||||
|
||||
func TestSmtpConfigureEmptyAddress(t *testing.T) {
|
||||
failTestOnError(t, setupTestEnv())
|
||||
|
||||
os.Setenv("SMTP_USERNAME", "test@example.com")
|
||||
os.Setenv("SMTP_PASSWORD", "hunter2")
|
||||
os.Setenv("SMTP_HOST", "smtp.commento.io")
|
||||
|
||||
if err := smtpConfigure(); err == nil {
|
||||
t.Errorf("expected error not found; SMTP should not be configured when SMTP_FROM_ADDRESS is empty")
|
||||
return
|
||||
}
|
||||
|
||||
cleanSmtpVars()
|
||||
}
|
Reference in New Issue
Block a user