1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
package label
import (
"net/http"
"testing"
"github.com/cli/cli/v2/internal/ghrepo"
"github.com/cli/cli/v2/pkg/httpmock"
"github.com/stretchr/testify/assert"
)
func TestLabelList_pagination(t *testing.T) {
reg := &httpmock.Registry{}
client := &http.Client{Transport: reg}
reg.Register(
httpmock.GraphQL(`query LabelList\b`),
httpmock.StringResponse(`
{
"data": {
"repository": {
"labels": {
"totalCount": 2,
"nodes": [
{
"name": "bug",
"color": "d73a4a",
"description": "This is a bug label"
}
],
"pageInfo": {
"hasNextPage": true,
"endCursor": "Y3Vyc29yOnYyOpK5MjAxOS0xMC0xMVQwMTozODowMyswODowMM5f3HZq"
}
}
}
}
}`),
)
reg.Register(
httpmock.GraphQL(`query LabelList\b`),
httpmock.StringResponse(`
{
"data": {
"repository": {
"labels": {
"totalCount": 2,
"nodes": [
{
"name": "docs",
"color": "ffa8da",
"description": "This is a docs label"
}
],
"pageInfo": {
"hasNextPage": false,
"endCursor": "Y3Vyc29yOnYyOpK5MjAyMi0wMS0zMVQxODo1NTo1MiswODowMM7hiAL3"
}
}
}
}
}`),
)
repo := ghrepo.New("OWNER", "REPO")
labels, totalCount, err := listLabels(client, repo, listQueryOptions{Limit: 10})
assert.NoError(t, err)
assert.Equal(t, 2, totalCount)
assert.Equal(t, 2, len(labels))
assert.Equal(t, "bug", labels[0].Name)
assert.Equal(t, "d73a4a", labels[0].Color)
assert.Equal(t, "This is a bug label", labels[0].Description)
assert.Equal(t, "docs", labels[1].Name)
assert.Equal(t, "ffa8da", labels[1].Color)
assert.Equal(t, "This is a docs label", labels[1].Description)
}
|