@@ -10,8 +10,8 @@ import (
1010
1111type tinyConfig map [string ]string
1212
13- func (c tinyConfig ) Get (host , key string ) (string , error ) {
14- return c [fmt .Sprintf ("%s:%s" , host , key )], nil
13+ func (c tinyConfig ) GetWithSource (host , key string ) (string , string , error ) {
14+ return c [fmt .Sprintf ("%s:%s" , host , key )], c [ "_source" ], nil
1515}
1616
1717func Test_helperRun (t * testing.T ) {
@@ -29,6 +29,7 @@ func Test_helperRun(t *testing.T) {
2929 Operation : "get" ,
3030 Config : func () (config , error ) {
3131 return tinyConfig {
32+ "_source" : "/Users/monalisa/.config/gh/hosts.yml" ,
3233 "example.com:user" : "monalisa" ,
3334 "example.com:oauth_token" : "OTOKEN" ,
3435 }, nil
@@ -53,6 +54,7 @@ func Test_helperRun(t *testing.T) {
5354 Operation : "get" ,
5455 Config : func () (config , error ) {
5556 return tinyConfig {
57+ "_source" : "/Users/monalisa/.config/gh/hosts.yml" ,
5658 "example.com:user" : "monalisa" ,
5759 "example.com:oauth_token" : "OTOKEN" ,
5860 }, nil
@@ -78,6 +80,7 @@ func Test_helperRun(t *testing.T) {
7880 Operation : "get" ,
7981 Config : func () (config , error ) {
8082 return tinyConfig {
83+ "_source" : "/Users/monalisa/.config/gh/hosts.yml" ,
8184 "example.com:user" : "monalisa" ,
8285 "example.com:oauth_token" : "OTOKEN" ,
8386 }, nil
@@ -101,6 +104,7 @@ func Test_helperRun(t *testing.T) {
101104 Operation : "get" ,
102105 Config : func () (config , error ) {
103106 return tinyConfig {
107+ "_source" : "/Users/monalisa/.config/gh/hosts.yml" ,
104108 "example.com:user" : "monalisa" ,
105109 }, nil
106110 },
@@ -119,6 +123,7 @@ func Test_helperRun(t *testing.T) {
119123 Operation : "get" ,
120124 Config : func () (config , error ) {
121125 return tinyConfig {
126+ "_source" : "/Users/monalisa/.config/gh/hosts.yml" ,
122127 "example.com:user" : "monalisa" ,
123128 "example.com:oauth_token" : "OTOKEN" ,
124129 }, nil
@@ -133,6 +138,31 @@ func Test_helperRun(t *testing.T) {
133138 wantStdout : "" ,
134139 wantStderr : "" ,
135140 },
141+ {
142+ name : "token from env" ,
143+ opts : CredentialOptions {
144+ Operation : "get" ,
145+ Config : func () (config , error ) {
146+ return tinyConfig {
147+ "_source" : "GITHUB_ENTERPRISE_TOKEN" ,
148+ "example.com:oauth_token" : "OTOKEN" ,
149+ }, nil
150+ },
151+ },
152+ input : heredoc .Doc (`
153+ protocol=https
154+ host=example.com
155+ username=hubot
156+ ` ),
157+ wantErr : false ,
158+ wantStdout : heredoc .Doc (`
159+ protocol=https
160+ host=example.com
161+ username=x-access-token
162+ password=OTOKEN
163+ ` ),
164+ wantStderr : "" ,
165+ },
136166 }
137167 for _ , tt := range tests {
138168 t .Run (tt .name , func (t * testing.T ) {
0 commit comments