authelia/internal/suites/action_mail.go
Amir Zarrinkafsh 1600e0f7da
[CI] Add wsl linter (#980)
* [CI] Add wsl linter

* Implement wsl recommendations

Co-authored-by: Clément Michaud <clement.michaud34@gmail.com>
2020-05-05 21:35:32 +02:00

34 lines
758 B
Go

package suites
import (
"encoding/json"
"fmt"
"regexp"
"testing"
"github.com/stretchr/testify/assert"
)
type message struct {
ID int `json:"id"`
}
func doGetLinkFromLastMail(t *testing.T) string {
res := doHTTPGetQuery(t, fmt.Sprintf("%s/messages", MailBaseURL))
messages := make([]message, 0)
err := json.Unmarshal(res, &messages)
assert.NoError(t, err)
assert.Greater(t, len(messages), 0)
messageID := messages[len(messages)-1].ID
res = doHTTPGetQuery(t, fmt.Sprintf("%s/messages/%d.html", MailBaseURL, messageID))
re := regexp.MustCompile(`<a href="(.+)" class="button">.*<\/a>`)
matches := re.FindStringSubmatch(string(res))
assert.Len(t, matches, 2, "Number of match for link in email is not equal to one")
return matches[1]
}