@@ -49,23 +49,31 @@ func TestConfigGet_not_found(t *testing.T) {
4949func TestConfigSet (t * testing.T ) {
5050 initBlankContext ("" , "OWNER/REPO" , "master" )
5151
52- buf := bytes .NewBufferString ("" )
53- defer config .StubWriteConfig (buf )()
52+ mainBuf := bytes.Buffer {}
53+ hostsBuf := bytes.Buffer {}
54+ defer config .StubWriteConfig (& mainBuf , & hostsBuf )()
55+
5456 output , err := RunCommand ("config set editor ed" )
5557 if err != nil {
5658 t .Fatalf ("error running command `config set editor ed`: %v" , err )
5759 }
5860
59- eq (t , output .String (), "" )
61+ if len (output .String ()) > 0 {
62+ t .Errorf ("expected output to be blank: %q" , output .String ())
63+ }
6064
61- expected := `hosts:
62- github.com:
63- user: OWNER
64- oauth_token: 1234567890
65- editor: ed
65+ expectedMain := "editor: ed\n "
66+ expectedHosts := `github.com:
67+ user: OWNER
68+ oauth_token: "1234567890"
6669`
6770
68- eq (t , buf .String (), expected )
71+ if mainBuf .String () != expectedMain {
72+ t .Errorf ("expected config.yml to be %q, got %q" , expectedMain , mainBuf .String ())
73+ }
74+ if hostsBuf .String () != expectedHosts {
75+ t .Errorf ("expected hosts.yml to be %q, got %q" , expectedHosts , hostsBuf .String ())
76+ }
6977}
7078
7179func TestConfigSet_update (t * testing.T ) {
@@ -79,23 +87,31 @@ editor: ed
7987
8088 initBlankContext (cfg , "OWNER/REPO" , "master" )
8189
82- buf := bytes .NewBufferString ("" )
83- defer config .StubWriteConfig (buf )()
90+ mainBuf := bytes.Buffer {}
91+ hostsBuf := bytes.Buffer {}
92+ defer config .StubWriteConfig (& mainBuf , & hostsBuf )()
8493
8594 output , err := RunCommand ("config set editor vim" )
8695 if err != nil {
8796 t .Fatalf ("error running command `config get editor`: %v" , err )
8897 }
8998
90- eq (t , output .String (), "" )
99+ if len (output .String ()) > 0 {
100+ t .Errorf ("expected output to be blank: %q" , output .String ())
101+ }
91102
92- expected := `hosts:
93- github.com:
94- user: OWNER
95- oauth_token: MUSTBEHIGHCUZIMATOKEN
96- editor: vim
103+ expectedMain := "editor: vim\n "
104+ expectedHosts := `github.com:
105+ user: OWNER
106+ oauth_token: MUSTBEHIGHCUZIMATOKEN
97107`
98- eq (t , buf .String (), expected )
108+
109+ if mainBuf .String () != expectedMain {
110+ t .Errorf ("expected config.yml to be %q, got %q" , expectedMain , mainBuf .String ())
111+ }
112+ if hostsBuf .String () != expectedHosts {
113+ t .Errorf ("expected hosts.yml to be %q, got %q" , expectedHosts , hostsBuf .String ())
114+ }
99115}
100116
101117func TestConfigGetHost (t * testing.T ) {
@@ -141,23 +157,32 @@ git_protocol: ssh
141157func TestConfigSetHost (t * testing.T ) {
142158 initBlankContext ("" , "OWNER/REPO" , "master" )
143159
144- buf := bytes .NewBufferString ("" )
145- defer config .StubWriteConfig (buf )()
160+ mainBuf := bytes.Buffer {}
161+ hostsBuf := bytes.Buffer {}
162+ defer config .StubWriteConfig (& mainBuf , & hostsBuf )()
163+
146164 output , err := RunCommand ("config set -hgithub.com git_protocol ssh" )
147165 if err != nil {
148166 t .Fatalf ("error running command `config set editor ed`: %v" , err )
149167 }
150168
151- eq (t , output .String (), "" )
169+ if len (output .String ()) > 0 {
170+ t .Errorf ("expected output to be blank: %q" , output .String ())
171+ }
152172
153- expected := `hosts:
154- github.com:
155- user: OWNER
156- oauth_token: 1234567890
157- git_protocol: ssh
173+ expectedMain := ""
174+ expectedHosts := ` github.com:
175+ user: OWNER
176+ oauth_token: " 1234567890"
177+ git_protocol: ssh
158178`
159179
160- eq (t , buf .String (), expected )
180+ if mainBuf .String () != expectedMain {
181+ t .Errorf ("expected config.yml to be %q, got %q" , expectedMain , mainBuf .String ())
182+ }
183+ if hostsBuf .String () != expectedHosts {
184+ t .Errorf ("expected hosts.yml to be %q, got %q" , expectedHosts , hostsBuf .String ())
185+ }
161186}
162187
163188func TestConfigSetHost_update (t * testing.T ) {
@@ -171,21 +196,30 @@ hosts:
171196
172197 initBlankContext (cfg , "OWNER/REPO" , "master" )
173198
174- buf := bytes .NewBufferString ("" )
175- defer config .StubWriteConfig (buf )()
199+ mainBuf := bytes.Buffer {}
200+ hostsBuf := bytes.Buffer {}
201+ defer config .StubWriteConfig (& mainBuf , & hostsBuf )()
176202
177203 output , err := RunCommand ("config set -hgithub.com git_protocol https" )
178204 if err != nil {
179205 t .Fatalf ("error running command `config get editor`: %v" , err )
180206 }
181207
182- eq (t , output .String (), "" )
208+ if len (output .String ()) > 0 {
209+ t .Errorf ("expected output to be blank: %q" , output .String ())
210+ }
183211
184- expected := `hosts:
185- github.com:
186- git_protocol: https
187- user: OWNER
188- oauth_token: MUSTBEHIGHCUZIMATOKEN
212+ expectedMain := ""
213+ expectedHosts := ` github.com:
214+ git_protocol: https
215+ user: OWNER
216+ oauth_token: MUSTBEHIGHCUZIMATOKEN
189217`
190- eq (t , buf .String (), expected )
218+
219+ if mainBuf .String () != expectedMain {
220+ t .Errorf ("expected config.yml to be %q, got %q" , expectedMain , mainBuf .String ())
221+ }
222+ if hostsBuf .String () != expectedHosts {
223+ t .Errorf ("expected hosts.yml to be %q, got %q" , expectedHosts , hostsBuf .String ())
224+ }
191225}
0 commit comments