| 19 | } |
| 20 | |
| 21 | func Test_helperRun(t *testing.T) { |
| 22 | tests := []struct { |
| 23 | name string |
| 24 | opts CredentialOptions |
| 25 | input string |
| 26 | wantStdout string |
| 27 | wantStderr string |
| 28 | wantErr bool |
| 29 | }{ |
| 30 | { |
| 31 | name: "host only, credentials found", |
| 32 | opts: CredentialOptions{ |
| 33 | Operation: "get", |
| 34 | Config: func() (config, error) { |
| 35 | return tinyConfig{ |
| 36 | "_source": "/Users/monalisa/.config/gh/hosts.yml", |
| 37 | "example.com:user": "monalisa", |
| 38 | "example.com:oauth_token": "OTOKEN", |
| 39 | }, nil |
| 40 | }, |
| 41 | }, |
| 42 | input: heredoc.Doc(` |
| 43 | protocol=https |
| 44 | host=example.com |
| 45 | `), |
| 46 | wantErr: false, |
| 47 | wantStdout: heredoc.Doc(` |
| 48 | protocol=https |
| 49 | host=example.com |
| 50 | username=monalisa |
| 51 | password=OTOKEN |
| 52 | `), |
| 53 | wantStderr: "", |
| 54 | }, |
| 55 | { |
| 56 | name: "host plus user", |
| 57 | opts: CredentialOptions{ |
| 58 | Operation: "get", |
| 59 | Config: func() (config, error) { |
| 60 | return tinyConfig{ |
| 61 | "_source": "/Users/monalisa/.config/gh/hosts.yml", |
| 62 | "example.com:user": "monalisa", |
| 63 | "example.com:oauth_token": "OTOKEN", |
| 64 | }, nil |
| 65 | }, |
| 66 | }, |
| 67 | input: heredoc.Doc(` |
| 68 | protocol=https |
| 69 | host=example.com |
| 70 | username=monalisa |
| 71 | `), |
| 72 | wantErr: false, |
| 73 | wantStdout: heredoc.Doc(` |
| 74 | protocol=https |
| 75 | host=example.com |
| 76 | username=monalisa |
| 77 | password=OTOKEN |
| 78 | `), |