Skip to content

Commit

Permalink
tests added for dele and rset cmds
Browse files Browse the repository at this point in the history
* dele and rset examples added
  • Loading branch information
gozeloglu committed Sep 17, 2021
1 parent 05a4eb3 commit 4d57272
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
6 changes: 6 additions & 0 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,10 @@ func main() {

r, _ := pop.Retr("1") // RETR 1 command
fmt.Println(r) // array of lines. Starts with "+OK" if there is mail

d, _ := pop.Dele("1") // DELE 1 command
fmt.Println(d) // response message starts with "+OK" if successful

rs, _ := pop.Rset() //RSET command
fmt.Println(rs) // response message starts with "+OK" if successful
}
117 changes: 117 additions & 0 deletions pop3/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,120 @@ func TestRetrFail(t *testing.T) {
t.Errorf("expected prefix: %s, got %s message", ok, r[0])
}
}

func TestDele(t *testing.T) {
pop, err := Connect(gmailTLSAddr, nil, true)
if err != nil {
t.Errorf(err.Error())
}

username := os.Getenv(userKey)
u, err := pop.User(username)
if err != nil {
t.Errorf(err.Error())
}

if !strings.HasPrefix(u, ok) {
t.Errorf("expected: %s, got: %s", ok, u)
}

password := os.Getenv(passwordKey)
p, err := pop.Pass(password)
if err != nil {
t.Errorf(err.Error())
}

if !strings.HasPrefix(p, ok) {
t.Errorf("expected: %s, got: %s", ok, p)
}

d, err := pop.Dele("1")
if err != nil {
t.Errorf(err.Error())
}

if !strings.HasPrefix(d, ok) {
t.Errorf("expected prefix: %s, got: %s", ok, d)
}
}

func TestDeleFail(t *testing.T) {
pop, err := Connect(gmailTLSAddr, nil, true)
if err != nil {
t.Errorf(err.Error())
}

username := os.Getenv(userKey)
u, err := pop.User(username)
if err != nil {
t.Errorf(err.Error())
}

if !strings.HasPrefix(u, ok) {
t.Errorf("expected: %s, got: %s", ok, u)
}

password := os.Getenv(passwordKey)
p, err := pop.Pass(password)
if err != nil {
t.Errorf(err.Error())
}

if !strings.HasPrefix(p, ok) {
t.Errorf("expected: %s, got: %s", ok, p)
}

d, err := pop.Dele(strconv.Itoa(math.MaxInt64 - 1))
if err != nil {
t.Errorf(err.Error())
}

if !strings.HasPrefix(d, e) {
t.Errorf("expected prefix: %s, got: %s", e, d)
}
}

func TestRset(t *testing.T) {
pop, err := Connect(gmailTLSAddr, nil, true)
if err != nil {
t.Errorf(err.Error())
}

username := os.Getenv(userKey)
u, err := pop.User(username)
if err != nil {
t.Errorf(err.Error())
}

if !strings.HasPrefix(u, ok) {
t.Errorf("expected: %s, got: %s", ok, u)
}

password := os.Getenv(passwordKey)
p, err := pop.Pass(password)
if err != nil {
t.Errorf(err.Error())
}

if !strings.HasPrefix(p, ok) {
t.Errorf("expected: %s, got: %s", ok, p)
}

d, err := pop.Dele("1")
if err != nil {
t.Errorf(err.Error())
}

if !strings.HasPrefix(d, ok) {
t.Errorf("expected prefix: %s, got: %s", ok, d)
}

r, err := pop.Rset()
if err != nil {
t.Errorf(err.Error())
}

if !strings.HasPrefix(r, ok) {
t.Errorf("expected prefix: %s, got: %s", ok, r)
}
}

0 comments on commit 4d57272

Please sign in to comment.