MCPcopy
hub / github.com/cli/cli / Test_apiRun_acceptHeader

Function Test_apiRun_acceptHeader

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

Source from the content-addressed store, hash-verified

1774}
1775
1776func Test_apiRun_acceptHeader(t *testing.T) {
1777 tests := []struct {
1778 name string
1779 options ApiOptions
1780 wantAcceptHeader string
1781 }{
1782 {
1783 name: "sets default accept header",
1784 options: ApiOptions{},
1785 wantAcceptHeader: "*/*",
1786 },
1787 {
1788 name: "does not override user accept header",
1789 options: ApiOptions{
1790 RequestHeaders: []string{"Accept: testing"},
1791 },
1792 wantAcceptHeader: "testing",
1793 },
1794 {
1795 name: "does not override preview names",
1796 options: ApiOptions{
1797 Previews: []string{"nebula"},
1798 },
1799 wantAcceptHeader: "application/vnd.github.nebula-preview+json",
1800 },
1801 }
1802 for _, tt := range tests {
1803 t.Run(tt.name, func(t *testing.T) {
1804 ios, _, _, _ := iostreams.Test()
1805 tt.options.IO = ios
1806
1807 tt.options.Config = func() (gh.Config, error) {
1808 return config.NewBlankConfig(), nil
1809 }
1810
1811 var gotReq *http.Request
1812 tt.options.HttpClient = func() (*http.Client, error) {
1813 var tr roundTripper = func(req *http.Request) (*http.Response, error) {
1814 gotReq = req
1815 resp := &http.Response{
1816 StatusCode: 200,
1817 Request: req,
1818 Body: io.NopCloser(bytes.NewBufferString("")),
1819 }
1820 return resp, nil
1821 }
1822 return &http.Client{Transport: tr}, nil
1823 }
1824
1825 assert.NoError(t, apiRun(&tt.options))
1826 assert.Equal(t, tt.wantAcceptHeader, gotReq.Header.Get("Accept"))
1827 })
1828 }
1829}

Callers

nothing calls this directly

Calls 6

TestFunction · 0.92
NewBlankConfigFunction · 0.92
apiRunFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected