Skip to content

Commit

Permalink
client: add test case for failed APPEND
Browse files Browse the repository at this point in the history
Updates #133
  • Loading branch information
emersion committed Jun 8, 2019
1 parent e1fe0ad commit c5d9e14
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion client/cmd_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,52 @@ func TestClient_Append(t *testing.T) {
b := make([]byte, 30)
if _, err := io.ReadFull(s, b); err != nil {
t.Fatal(err)
} else if string(b) != msg {
t.Fatal("Bad literal:", string(b))
}

s.WriteString(tag + " OK APPEND completed\r\n")

if err := <-done; err != nil {
t.Fatalf("c.Append() = %v", err)
}
}

if string(b) != msg {
func TestClient_Append_failed(t *testing.T) {
c, s := newTestClient(t)
defer s.Close()

setClientState(c, imap.AuthenticatedState, nil)

// First the server refuses

msg := "First try"
done := make(chan error, 1)
go func() {
done <- c.Append("INBOX", nil, time.Time{}, bytes.NewBufferString(msg))
}()

tag, _ := s.ScanCmd()
s.WriteString(tag + " BAD APPEND failed\r\n")

if err := <-done; err == nil {
t.Fatal("c.Append() = nil, want an error from the server")
}

// Try a second time, the server accepts

msg = "Second try"
go func() {
done <- c.Append("INBOX", nil, time.Time{}, bytes.NewBufferString(msg))
}()

tag, _ = s.ScanCmd()
s.WriteString("+ send literal\r\n")

b := make([]byte, len(msg))
if _, err := io.ReadFull(s, b); err != nil {
t.Fatal(err)
} else if string(b) != msg {
t.Fatal("Bad literal:", string(b))
}

Expand Down

0 comments on commit c5d9e14

Please sign in to comment.