MCPcopy Create free account
hub / github.com/cli/cli / Test_processResponse_template

Function Test_processResponse_template

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

Source from the content-addressed store, hash-verified

1728}
1729
1730func Test_processResponse_template(t *testing.T) {
1731 ios, _, stdout, stderr := iostreams.Test()
1732
1733 resp := http.Response{
1734 StatusCode: 200,
1735 Header: map[string][]string{
1736 "Content-Type": {"application/json"},
1737 },
1738 Body: io.NopCloser(strings.NewReader(`[
1739 {
1740 "title": "First title",
1741 "labels": [{"name":"bug"}, {"name":"help wanted"}]
1742 },
1743 {
1744 "title": "Second but not last"
1745 },
1746 {
1747 "title": "Alas, tis' the end",
1748 "labels": [{}, {"name":"feature"}]
1749 }
1750 ]`)),
1751 }
1752
1753 opts := ApiOptions{
1754 IO: ios,
1755 Template: `{{range .}}{{.title}} ({{.labels | pluck "name" | join ", " }}){{"\n"}}{{end}}`,
1756 }
1757
1758 tmpl := template.New(ios.Out, ios.TerminalWidth(), ios.ColorEnabled())
1759 err := tmpl.Parse(opts.Template)
1760 require.NoError(t, err)
1761 _, err = processResponse(&resp, &opts, ios.Out, io.Discard, tmpl, true, true)
1762 require.NoError(t, err)
1763 err = tmpl.Flush()
1764 require.NoError(t, err)
1765
1766 assert.Equal(t, heredoc.Doc(`
1767 First title (bug, help wanted)
1768 Second but not last ()
1769 Alas, tis' the end (, feature)
1770 `), stdout.String())
1771 assert.Equal(t, "", stderr.String())
1772}
1773
1774func Test_parseErrorResponse(t *testing.T) {
1775 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.65

Tested by

no test coverage detected