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