mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-16 15:02:43 +00:00
Consolidate boilerplate in integration tests (#1979)
This commit is contained in:
parent
a3868ef536
commit
ce9b86082c
16 changed files with 147 additions and 166 deletions
|
@ -6,21 +6,20 @@ package integrations
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type HtmlDoc struct {
|
||||
doc *goquery.Document
|
||||
}
|
||||
|
||||
func NewHtmlParser(content []byte) (*HtmlDoc, error) {
|
||||
func NewHtmlParser(t *testing.T, content []byte) *HtmlDoc {
|
||||
doc, err := goquery.NewDocumentFromReader(bytes.NewReader(content))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &HtmlDoc{doc: doc}, nil
|
||||
assert.NoError(t, err)
|
||||
return &HtmlDoc{doc: doc}
|
||||
}
|
||||
|
||||
func (doc *HtmlDoc) GetInputValueById(id string) string {
|
||||
|
@ -32,3 +31,7 @@ func (doc *HtmlDoc) GetInputValueByName(name string) string {
|
|||
text, _ := doc.doc.Find("input[name=\"" + name + "\"]").Attr("value")
|
||||
return text
|
||||
}
|
||||
|
||||
func (doc *HtmlDoc) GetCSRF() string {
|
||||
return doc.GetInputValueByName("_csrf")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue