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

Function Test_processResponse_template

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

Source from the content-addressed store, hash-verified

1830}
1831
1832func Test_processResponse_template(t *testing.T) {
1833 ios, _, stdout, stderr := iostreams.Test()
1834
1835 resp := http.Response{
1836 StatusCode: 200,
1837 Header: map[string][]string{
1838 "Content-Type": {"application/json"},
1839 },
1840 Body: io.NopCloser(strings.NewReader(`[
1841 {
1842 "title": "First title",
1843 "labels": [{"name":"bug"}, {"name":"help wanted"}]
1844 },
1845 {
1846 "title": "Second but not last"
1847 },
1848 {
1849 "title": "Alas, tis' the end",
1850 "labels": [{}, {"name":"feature"}]
1851 }
1852 ]`)),
1853 }
1854
1855 opts := ApiOptions{
1856 IO: ios,
1857 Template: `{{range .}}{{.title}} ({{.labels | pluck "name" | join ", " }}){{"\n"}}{{end}}`,
1858 }
1859
1860 tmpl := template.New(ios.Out, ios.TerminalWidth(), ios.ColorEnabled())
1861 err := tmpl.Parse(opts.Template)
1862 require.NoError(t, err)
1863 _, err = processResponse(&resp, &opts, ios.Out, io.Discard, tmpl, true, true)
1864 require.NoError(t, err)
1865 err = tmpl.Flush()
1866 require.NoError(t, err)
1867
1868 assert.Equal(t, heredoc.Doc(`
1869 First title (bug, help wanted)
1870 Second but not last ()
1871 Alas, tis' the end (, feature)
1872 `), stdout.String())
1873 assert.Equal(t, "", stderr.String())
1874}
1875
1876func Test_parseErrorResponse(t *testing.T) {
1877 type args struct {

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected