Skip to content

Commit 4b2cded

Browse files
committed
Ensure that tests for command factory never read from user's config
If these tests are going to exerise `factory.New()`, the config getter should always be overriden since the default config getter reads from `~/.config/gh` and thus makes tests dependent on the user's environment.
1 parent dd3aac7 commit 4b2cded

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pkg/cmd/factory/default_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,10 @@ func Test_ioStreams_pager(t *testing.T) {
333333
}
334334
}
335335
f := New("1")
336-
if tt.config != nil {
337-
f.Config = func() (config.Config, error) {
336+
f.Config = func() (config.Config, error) {
337+
if tt.config == nil {
338+
return config.NewBlankConfig(), nil
339+
} else {
338340
return tt.config, nil
339341
}
340342
}
@@ -363,8 +365,10 @@ func Test_ioStreams_prompt(t *testing.T) {
363365
for _, tt := range tests {
364366
t.Run(tt.name, func(t *testing.T) {
365367
f := New("1")
366-
if tt.config != nil {
367-
f.Config = func() (config.Config, error) {
368+
f.Config = func() (config.Config, error) {
369+
if tt.config == nil {
370+
return config.NewBlankConfig(), nil
371+
} else {
368372
return tt.config, nil
369373
}
370374
}

0 commit comments

Comments
 (0)