-
-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(inbucket): expose POP3 and wait for all ports (#2690)
* fix(inbucket): expose POP3 and wait for all ports Expose the POP3 port and wait for all ports which fixes the race condition in the tests. * chore: use listen port instead of host port Use ForListeningPort instead of NewHostPortStrategy as it's more readable. Co-authored-by: Manuel de la Peña <[email protected]> --------- Co-authored-by: Manuel de la Peña <[email protected]>
- Loading branch information
1 parent
5924b38
commit db119f6
Showing
4 changed files
with
33 additions
and
35 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,65 +6,45 @@ import ( | |
"testing" | ||
|
||
"github.com/inbucket/inbucket/pkg/rest/client" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestInbucket(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
container, err := Run(ctx, "inbucket/inbucket:sha-2d409bb") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
require.NoError(t, err) | ||
|
||
// Clean up the container after the test is complete | ||
t.Cleanup(func() { | ||
if err := container.Terminate(ctx); err != nil { | ||
t.Fatalf("failed to terminate container: %s", err) | ||
} | ||
err := container.Terminate(ctx) | ||
require.NoError(t, err) | ||
}) | ||
|
||
// smtpConnection { | ||
smtpUrl, err := container.SmtpConnection(ctx) | ||
// } | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
require.NoError(t, err) | ||
|
||
// webInterface { | ||
webInterfaceUrl, err := container.WebInterface(ctx) | ||
// } | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
require.NoError(t, err) | ||
restClient, err := client.New(webInterfaceUrl) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
require.NoError(t, err) | ||
|
||
headers, err := restClient.ListMailbox("[email protected]") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if len(headers) != 0 { | ||
t.Fatalf("expected 0 messages, got %d", len(headers)) | ||
} | ||
require.NoError(t, err) | ||
require.Empty(t, headers) | ||
|
||
msg := []byte("To: [email protected]\r\n" + | ||
"Subject: Testcontainers test!\r\n" + | ||
"\r\n" + | ||
"This is a Testcontainers test.\r\n") | ||
if err = smtp.SendMail(smtpUrl, nil, "[email protected]", []string{"[email protected]"}, msg); err != nil { | ||
t.Fatal(err) | ||
} | ||
err = smtp.SendMail(smtpUrl, nil, "[email protected]", []string{"[email protected]"}, msg) | ||
require.NoError(t, err) | ||
|
||
headers, err = restClient.ListMailbox("[email protected]") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if len(headers) != 1 { | ||
t.Fatalf("expected 1 message, got %d", len(headers)) | ||
} | ||
// perform assertions | ||
require.NoError(t, err) | ||
require.Len(t, headers, 1) | ||
} |