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

Function Test_processResponse_template

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

Source from the content-addressed store, hash-verified

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