MCPcopy
hub / github.com/cli/cli / Test_processResponse_template

Function Test_processResponse_template

pkg/cmd/api/api_test.go:1650–1692  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1648}
1649
1650func Test_processResponse_template(t *testing.T) {
1651 ios, _, stdout, stderr := iostreams.Test()
1652
1653 resp := http.Response{
1654 StatusCode: 200,
1655 Header: map[string][]string{
1656 "Content-Type": {"application/json"},
1657 },
1658 Body: io.NopCloser(strings.NewReader(`[
1659 {
1660 "title": "First title",
1661 "labels": [{"name":"bug"}, {"name":"help wanted"}]
1662 },
1663 {
1664 "title": "Second but not last"
1665 },
1666 {
1667 "title": "Alas, tis' the end",
1668 "labels": [{}, {"name":"feature"}]
1669 }
1670 ]`)),
1671 }
1672
1673 opts := ApiOptions{
1674 IO: ios,
1675 Template: `{{range .}}{{.title}} ({{.labels | pluck "name" | join ", " }}){{"\n"}}{{end}}`,
1676 }
1677
1678 tmpl := template.New(ios.Out, ios.TerminalWidth(), ios.ColorEnabled())
1679 err := tmpl.Parse(opts.Template)
1680 require.NoError(t, err)
1681 _, err = processResponse(&resp, &opts, ios.Out, io.Discard, tmpl, true, true)
1682 require.NoError(t, err)
1683 err = tmpl.Flush()
1684 require.NoError(t, err)
1685
1686 assert.Equal(t, heredoc.Doc(`
1687 First title (bug, help wanted)
1688 Second but not last ()
1689 Alas, tis' the end (, feature)
1690 `), stdout.String())
1691 assert.Equal(t, "", stderr.String())
1692}
1693
1694func Test_parseErrorResponse(t *testing.T) {
1695 type args struct {

Callers

nothing calls this directly

Calls 7

TestFunction · 0.92
processResponseFunction · 0.85
TerminalWidthMethod · 0.80
ColorEnabledMethod · 0.80
EqualMethod · 0.80
FlushMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected