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

Function Test_processResponse_template

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

Source from the content-addressed store, hash-verified

1760}
1761
1762func Test_processResponse_template(t *testing.T) {
1763 ios, _, stdout, stderr := iostreams.Test()
1764
1765 resp := http.Response{
1766 StatusCode: 200,
1767 Header: map[string][]string{
1768 "Content-Type": {"application/json"},
1769 },
1770 Body: io.NopCloser(strings.NewReader(`[
1771 {
1772 "title": "First title",
1773 "labels": [{"name":"bug"}, {"name":"help wanted"}]
1774 },
1775 {
1776 "title": "Second but not last"
1777 },
1778 {
1779 "title": "Alas, tis' the end",
1780 "labels": [{}, {"name":"feature"}]
1781 }
1782 ]`)),
1783 }
1784
1785 opts := ApiOptions{
1786 IO: ios,
1787 Template: `{{range .}}{{.title}} ({{.labels | pluck "name" | join ", " }}){{"\n"}}{{end}}`,
1788 }
1789
1790 tmpl := template.New(ios.Out, ios.TerminalWidth(), ios.ColorEnabled())
1791 err := tmpl.Parse(opts.Template)
1792 require.NoError(t, err)
1793 _, err = processResponse(&resp, &opts, ios.Out, io.Discard, tmpl, true, true)
1794 require.NoError(t, err)
1795 err = tmpl.Flush()
1796 require.NoError(t, err)
1797
1798 assert.Equal(t, heredoc.Doc(`
1799 First title (bug, help wanted)
1800 Second but not last ()
1801 Alas, tis' the end (, feature)
1802 `), stdout.String())
1803 assert.Equal(t, "", stderr.String())
1804}
1805
1806func Test_parseErrorResponse(t *testing.T) {
1807 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