test: enable passing username/password through env vars to smtp_test.v

pull/5820/head
Delyan Angelov 2020-07-13 18:22:36 +03:00
parent ee46c8075f
commit 97d01a5487
2 changed files with 16 additions and 15 deletions

View File

@ -139,6 +139,9 @@ fn (c Client) send_ehlo() ? {
[inline]
fn (c Client) send_auth() ? {
if c.username.len == 0 {
return
}
mut sb := strings.new_builder(100)
sb.write_b(0)
sb.write(c.username)

View File

@ -1,3 +1,4 @@
import os
import smtp
import time
@ -18,6 +19,8 @@ fn test_smtp() {
client_cfg := smtp.Client{
server: 'smtp.mailtrap.io'
from: 'dev@vlang.io'
username: os.getenv('VSMTP_TEST_USER')
password: os.getenv('VSMTP_TEST_PASS')
}
send_cfg := smtp.Mail{
@ -30,24 +33,19 @@ fn test_smtp() {
// `break`. There's an `assert false` after the loop, which will only be called if this loop
// is broken from.
for {
mut client := smtp.new_client(client_cfg) or { break }
client.send(send_cfg) or { break }
mut client := smtp.new_client(client_cfg) or { assert false break }
client.send(send_cfg) or { assert false break }
// client.send({ send_cfg | body_type: .html, body: '<html><h1>HTML V email!</h1></html>' }) or { break }
client.send({ send_cfg | from: 'alexander@vlang.io' }) or { break }
client.send({ send_cfg | cc: 'alexander@vlang.io,joe@vlang.io', bcc: 'spytheman@vlang.io' }) or { break }
client.send({ send_cfg | date: time.now().add_days(1000) }) or { break }
client.quit() or { break }
client.send({ send_cfg | from: 'alexander@vlang.io' }) or { assert false break }
client.send({ send_cfg | cc: 'alexander@vlang.io,joe@vlang.io', bcc: 'spytheman@vlang.io' }) or { assert false break }
client.send({ send_cfg | date: time.now().add_days(1000) }) or { assert false break }
client.quit() or { assert false break }
// This call should return an error, since the connection is closed
if !fn_errors(client, send_cfg) { break }
client.reconnect() or { break }
client.send(send_cfg) or { break }
if !fn_errors(client, send_cfg) { assert false break }
client.reconnect() or { assert false break }
client.send(send_cfg) or { assert false break }
assert true
return
}
assert false
}