shad-go/lectures/04-testing/mocks/mocks.go

30 lines
588 B
Go
Raw Normal View History

2020-03-19 13:06:26 +00:00
import (
"fmt"
"log"
"net/smtp"
)
var notifyUser = doNotifyUser
func doNotifyUser(username, msg string) {
auth := smtp.PlainAuth("", sender, password, hostname)
err := smtp.SendMail(hostname+":587", auth, sender,
[]string{username}, []byte(msg))
if err != nil {
log.Printf("smtp.SendEmail(%s) failed: %s", username, err)
}
}
func CheckQuota(username string) {
used := bytesInUse(username)
const quota = 1000000000 // 1GB
percent := 100 * used / quota
if percent < 90 {
return // OK
}
msg := fmt.Sprintf(template, used, percent)
notifyUser(username, msg)
}
// OMIT