This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
err = pool.Retry(func() error { | |
SMTP_PORT = resource.GetPort("1025/tcp") | |
HTTP_PORT = resource.GetPort("8025/tcp") | |
// ping to ensure that the server is up and running | |
_, err := net.Dial("tcp", net.JoinHostPort("localhost", SMTP_PORT)) | |
return err | |
}) | |
if err != nil { | |
log.Fatalf("Could not connect to database: %s", err) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
code := m.Run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if err := pool.Purge(resource); err != nil { | |
log.Fatalf("Could not purge resource: %s", err) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
os.Exit(code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestMain(m *testing.M) { | |
// uses a sensible default on windows (tcp/http) and linux/osx (socket) | |
pool, err := dockertest.NewPool("") | |
if err != nil { | |
log.Fatalf("Could not connect to docker: %s", err) | |
} | |
// we will use a dockerfile to build the image for testing | |
resource, err := pool.BuildAndRun("mailhog-test-server", "./Dockerfile", []string{}) | |
if err != nil { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mail := Mail{ | |
host: SMTP_HOST, | |
port: SMTP_PORT, | |
from: "from@example.com", | |
password: "", | |
username: "", | |
} | |
err := mail.Send([]string{"to@example.com"}, "Test Subject", "Sending an automated test email") | |
assert.Nil(t, err) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resp, err := http.Get(fmt.Sprintf("http://localhost:%s/api/v2/messages", HTTP_PORT)) | |
assert.Nil(t, err) | |
defer resp.Body.Close() | |
assert.Equal(t, 200, resp.StatusCode) | |
body, err := ioutil.ReadAll(resp.Body) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// hard kill the container in 3 minutes (180 Seconds) | |
resource.Expire(180) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
viper.SetConfigFile("./path/to/config-file.yaml") | |
viper.SetConfigFile("./path/to/config-file-2.json") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
viper.AddConfigPath(".") | |
viper.AddConfigPath("$HOME/.looped") |