feat(imapx): connect, endpoint test, login test with folder listing
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package imapx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func testEP(t *testing.T) Endpoint {
|
||||
host := os.Getenv("TEST_IMAP_HOST")
|
||||
if host == "" {
|
||||
t.Skip("TEST_IMAP_HOST not set")
|
||||
}
|
||||
port, _ := strconv.Atoi(os.Getenv("TEST_IMAP_PORT"))
|
||||
return Endpoint{Host: host, Port: port, TLSMode: "plain"}
|
||||
}
|
||||
|
||||
func TestTestEndpointOK(t *testing.T) {
|
||||
ep := testEP(t)
|
||||
if err := TestEndpoint(context.Background(), ep); err != nil {
|
||||
t.Fatalf("TestEndpoint: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTestLoginListsFolders(t *testing.T) {
|
||||
ep := testEP(t)
|
||||
// greenmail auto-creates users on first login
|
||||
folders, err := TestLogin(context.Background(), ep, "user1@localhost", "pass1")
|
||||
if err != nil {
|
||||
t.Fatalf("TestLogin: %v", err)
|
||||
}
|
||||
found := false
|
||||
for _, f := range folders {
|
||||
if f == "INBOX" {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("INBOX not in folders: %v", folders)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user