(t *testing.T)
| 17 | ) |
| 18 | |
| 19 | func TestNewHTTPClient(t *testing.T) { |
| 20 | type args struct { |
| 21 | config tokenGetter |
| 22 | appVersion string |
| 23 | invokingAgent string |
| 24 | logVerboseHTTP bool |
| 25 | skipDefaultHeaders bool |
| 26 | } |
| 27 | tests := []struct { |
| 28 | name string |
| 29 | args args |
| 30 | host string |
| 31 | wantHeader map[string][]string |
| 32 | wantStderr string |
| 33 | }{ |
| 34 | { |
| 35 | name: "github.com", |
| 36 | args: args{ |
| 37 | config: tinyConfig{"github.com:oauth_token": "MYTOKEN"}, |
| 38 | appVersion: "v1.2.3", |
| 39 | logVerboseHTTP: false, |
| 40 | }, |
| 41 | host: "github.com", |
| 42 | wantHeader: map[string][]string{ |
| 43 | "authorization": {"token MYTOKEN"}, |
| 44 | "user-agent": {"GitHub CLI v1.2.3"}, |
| 45 | "x-github-api-version": {"2022-11-28"}, |
| 46 | "accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"}, |
| 47 | }, |
| 48 | wantStderr: "", |
| 49 | }, |
| 50 | { |
| 51 | name: "GHES", |
| 52 | args: args{ |
| 53 | config: tinyConfig{"example.com:oauth_token": "GHETOKEN"}, |
| 54 | appVersion: "v1.2.3", |
| 55 | }, |
| 56 | host: "example.com", |
| 57 | wantHeader: map[string][]string{ |
| 58 | "authorization": {"token GHETOKEN"}, |
| 59 | "user-agent": {"GitHub CLI v1.2.3"}, |
| 60 | "x-github-api-version": {"2022-11-28"}, |
| 61 | "accept": {"application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview"}, |
| 62 | }, |
| 63 | wantStderr: "", |
| 64 | }, |
| 65 | { |
| 66 | name: "github.com no authentication token", |
| 67 | args: args{ |
| 68 | config: tinyConfig{"example.com:oauth_token": "MYTOKEN"}, |
| 69 | appVersion: "v1.2.3", |
| 70 | logVerboseHTTP: false, |
| 71 | }, |
| 72 | host: "github.com", |
| 73 | wantHeader: map[string][]string{ |
| 74 | "authorization": nil, // should not be set |
| 75 | "user-agent": {"GitHub CLI v1.2.3"}, |
| 76 | "x-github-api-version": {"2022-11-28"}, |
nothing calls this directly
no test coverage detected