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) } } func TestConnectHonorsCancelledContext(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) cancel() _, err := Connect(ctx, Endpoint{Host: "10.255.255.1", Port: 993, TLSMode: "ssl"}) if err == nil { t.Fatal("expected error for cancelled context") } }