From 4b2cded1f86e9cfac309b96814f999a847c24dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 17 Jun 2021 17:59:34 +0200 Subject: [PATCH] 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. --- pkg/cmd/factory/default_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/cmd/factory/default_test.go b/pkg/cmd/factory/default_test.go index 1bf8702c8..c7e641aa1 100644 --- a/pkg/cmd/factory/default_test.go +++ b/pkg/cmd/factory/default_test.go @@ -333,8 +333,10 @@ func Test_ioStreams_pager(t *testing.T) { } } f := New("1") - if tt.config != nil { - f.Config = func() (config.Config, error) { + f.Config = func() (config.Config, error) { + if tt.config == nil { + return config.NewBlankConfig(), nil + } else { return tt.config, nil } } @@ -363,8 +365,10 @@ func Test_ioStreams_prompt(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { f := New("1") - if tt.config != nil { - f.Config = func() (config.Config, error) { + f.Config = func() (config.Config, error) { + if tt.config == nil { + return config.NewBlankConfig(), nil + } else { return tt.config, nil } }