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

Function Test_apiRun_acceptHeader

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

Source from the content-addressed store, hash-verified

1854}
1855
1856func Test_apiRun_acceptHeader(t *testing.T) {
1857 tests := []struct {
1858 name string
1859 options ApiOptions
1860 wantAcceptHeader string
1861 }{
1862 {
1863 name: "sets default accept header",
1864 options: ApiOptions{},
1865 wantAcceptHeader: "*/*",
1866 },
1867 {
1868 name: "does not override user accept header",
1869 options: ApiOptions{
1870 RequestHeaders: []string{"Accept: testing"},
1871 },
1872 wantAcceptHeader: "testing",
1873 },
1874 {
1875 name: "does not override preview names",
1876 options: ApiOptions{
1877 Previews: []string{"nebula"},
1878 },
1879 wantAcceptHeader: "application/vnd.github.nebula-preview+json",
1880 },
1881 }
1882 for _, tt := range tests {
1883 t.Run(tt.name, func(t *testing.T) {
1884 ios, _, _, _ := iostreams.Test()
1885 tt.options.IO = ios
1886
1887 tt.options.Config = func() (gh.Config, error) {
1888 return config.NewMockConfig(), nil
1889 }
1890
1891 var gotReq *http.Request
1892 tt.options.HttpClient = func() (*http.Client, error) {
1893 var tr roundTripper = func(req *http.Request) (*http.Response, error) {
1894 gotReq = req
1895 resp := &http.Response{
1896 StatusCode: 200,
1897 Request: req,
1898 Body: io.NopCloser(bytes.NewBufferString("")),
1899 }
1900 return resp, nil
1901 }
1902 return &http.Client{Transport: tr}, nil
1903 }
1904
1905 assert.NoError(t, apiRun(&tt.options))
1906 assert.Equal(t, tt.wantAcceptHeader, gotReq.Header.Get("Accept"))
1907 })
1908 }
1909}

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected