mirror of https://github.com/ory/kratos
fix: don't reuse ports in courier/SMTP tests (#3156)
This commit is contained in:
parent
cca36f8259
commit
e260fcf061
|
|
@ -7,11 +7,9 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/ory/kratos/x"
|
||||
dhelper "github.com/ory/x/sqlcon/dockertest"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
atexit := dhelper.NewOnExit()
|
||||
atexit.Add(x.CleanUpTestSMTP)
|
||||
atexit.Exit(m.Run())
|
||||
m.Run()
|
||||
x.CleanUpTestSMTP()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ func TestQueueEmail(t *testing.T) {
|
|||
}
|
||||
|
||||
if total := gjson.GetBytes(body, "total").Int(); total != 3 {
|
||||
return errors.Errorf("expected to have delivered at least 3 messages but got count %d with body: %s", total, body)
|
||||
return errors.Errorf("expected to have delivered exactly 3 messages but got count %d with body: %s", total, body)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
19
x/mailhog.go
19
x/mailhog.go
|
|
@ -11,9 +11,11 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/cenkalti/backoff"
|
||||
"github.com/phayes/freeport"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/ory/dockertest/v3"
|
||||
"github.com/ory/dockertest/v3/docker"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -41,6 +43,15 @@ func RunTestSMTP() (smtp, api string, err error) {
|
|||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
if err := pool.Client.Ping(); err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
ports, err := freeport.GetFreePorts(2)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
smtpPort, apiPort := ports[0], ports[1]
|
||||
|
||||
resource, err := pool.
|
||||
RunWithOptions(&dockertest.RunOptions{
|
||||
|
|
@ -56,6 +67,10 @@ func RunTestSMTP() (smtp, api string, err error) {
|
|||
"-jim-linkspeed-min=1250",
|
||||
"-jim-linkspeed-max=12500",
|
||||
},
|
||||
PortBindings: map[docker.Port][]docker.PortBinding{
|
||||
"8025/tcp": {{HostPort: fmt.Sprintf("%d/tcp", apiPort)}},
|
||||
"1025/tcp": {{HostPort: fmt.Sprintf("%d/tcp", smtpPort)}},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
|
|
@ -64,8 +79,8 @@ func RunTestSMTP() (smtp, api string, err error) {
|
|||
resources = append(resources, resource)
|
||||
resourceMux.Unlock()
|
||||
|
||||
smtp = fmt.Sprintf("smtp://test:test@127.0.0.1:%s/?disable_starttls=true", resource.GetPort("1025/tcp"))
|
||||
api = fmt.Sprintf("http://127.0.0.1:%s", resource.GetPort("8025/tcp"))
|
||||
smtp = fmt.Sprintf("smtp://test:test@127.0.0.1:%d/?disable_starttls=true", smtpPort)
|
||||
api = fmt.Sprintf("http://127.0.0.1:%d", apiPort)
|
||||
if err := backoff.Retry(func() error {
|
||||
res, err := http.Get(api + "/api/v2/messages")
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue