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