From e0bc2ff0caab8dbaf2fd2a5176e788fdfc0b8268 Mon Sep 17 00:00:00 2001 From: William Martin Date: Thu, 19 Oct 2023 12:08:03 +0200 Subject: [PATCH] Add test that host is added on Login --- internal/config/auth_config_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/internal/config/auth_config_test.go b/internal/config/auth_config_test.go index a1f9b0833..772452b3b 100644 --- a/internal/config/auth_config_test.go +++ b/internal/config/auth_config_test.go @@ -299,6 +299,27 @@ func TestLoginSetsGitProtocolForProdivdedHost(t *testing.T) { require.Equal(t, "ssh", gitProtocol) } +func TestLoginAddsHostIfNotAlreadyAdded(t *testing.T) { + tempDir := t.TempDir() + t.Setenv("GH_CONFIG_DIR", tempDir) + + // Given a usable keyring and an empty config + keyring.MockInit() + authCfg := newTestAuthConfig() + ghConfig.Read = func() (*ghConfig.Config, error) { + return authCfg.cfg, nil + } + + // When we login + _, err := authCfg.Login("github.com", "test-user", "test-token", "ssh", true) + + // Then it returns success and a host is added + require.NoError(t, err) + + hosts := authCfg.Hosts() + require.Contains(t, hosts, "github.com") +} + func TestLogoutRemovesHostAndKeyringToken(t *testing.T) { tempDir := t.TempDir() t.Setenv("GH_CONFIG_DIR", tempDir)