package client import ( "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestClient_Login(t *testing.T) { c := &Client{} err := c.Login("user@example.com", "password") assert.NoError(t, err) } func TestClient_Logout(t *testing.T) { c := &Client{} err := c.Logout() assert.NoError(t, err) } func TestClient_Select(t *testing.T) { c := &Client{} mbox, err := c.Select("INBOX", true) require.NoError(t, err) // stub returns nil mailbox assert.Nil(t, mbox) mbox2, err := c.Select("Sent", false) require.NoError(t, err) assert.Nil(t, mbox2) } func TestClient_List(t *testing.T) { c := &Client{} ch := make(chan interface{}, 10) err := c.List("", "*", ch) assert.NoError(t, err) } func TestClient_Search(t *testing.T) { c := &Client{} uids, err := c.Search(nil) require.NoError(t, err) assert.Nil(t, uids) } func TestClient_Fetch(t *testing.T) { c := &Client{} ch := make(chan interface{}, 10) err := c.Fetch(nil, nil, ch) assert.NoError(t, err) } func TestDial(t *testing.T) { c, err := Dial("imap.example.com:993") require.NoError(t, err) require.NotNil(t, c) assert.NotNil(t, c) } func TestDialTLS(t *testing.T) { c, err := DialTLS("imap.example.com:993", nil) require.NoError(t, err) require.NotNil(t, c) } func TestNewClient(t *testing.T) { c, err := NewClient(nil) require.NoError(t, err) require.NotNil(t, c) } func TestClient_AllMethods_NoError(t *testing.T) { c := &Client{ State: "authenticated", Mailboxes: []interface{}{"INBOX", "Sent"}, Updates: make(chan interface{}, 1), ServerName: "test.example.com", } // Exercise all methods on a populated client require.NoError(t, c.Login("user", "pass")) require.NoError(t, c.Logout()) mbox, err := c.Select("INBOX", true) require.NoError(t, err) assert.Nil(t, mbox) ch := make(chan interface{}, 5) require.NoError(t, c.List("", "*", ch)) uids, err := c.Search(nil) require.NoError(t, err) assert.Nil(t, uids) require.NoError(t, c.Fetch(nil, nil, ch)) }