From f7a2c1168a81d879c1307b38b679614fc0752e42 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 29 May 2026 10:28:49 +0300 Subject: refactor(cli): use org host helpers in forge client dispatch (lq) --- internal/cli/forge_client_test.go | 75 +++++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 15 deletions(-) (limited to 'internal/cli/forge_client_test.go') diff --git a/internal/cli/forge_client_test.go b/internal/cli/forge_client_test.go index 9aff10b..6ce220a 100644 --- a/internal/cli/forge_client_test.go +++ b/internal/cli/forge_client_test.go @@ -37,31 +37,76 @@ func TestNewRepoClientForOrg(t *testing.T) { } }) - t.Run("unsupported", func(t *testing.T) { - client, ok := newRepoClientForOrg(config.Organization{ - Host: "ssh://example.org", - Name: "acme", - }) - if ok { - t.Fatal("expected unsupported host") + t.Run("github host variants", func(t *testing.T) { + t.Parallel() + + variantHosts := []string{ + "ssh://github.com", + "git@github.company.com", + "git@github.com:acme", + "https://github.com", } - if client != nil { - t.Fatal("expected nil client for unsupported host") + + for _, host := range variantHosts { + host := host + t.Run(host, func(t *testing.T) { + t.Parallel() + + client, ok := newRepoClientForOrg(config.Organization{ + Host: host, + Name: "acme", + GitHubToken: "token", + }) + if !ok { + t.Fatalf("expected supported github host variant %q", host) + } + if !client.HasToken() { + t.Fatalf("expected github client token for host variant %q", host) + } + }) } }) - t.Run("unsupported near miss hosts", func(t *testing.T) { + t.Run("codeberg host variants", func(t *testing.T) { t.Parallel() - nearMissHosts := []string{ - "ssh://github.com", - "git@github.company.com", - "git@github.com:acme", + variantHosts := []string{ "https://codeberg.org", + "ssh://codeberg.org", + "git@codeberg.org:acme", "git@codeberg.org.example", } - for _, host := range nearMissHosts { + for _, host := range variantHosts { + host := host + t.Run(host, func(t *testing.T) { + t.Parallel() + + client, ok := newRepoClientForOrg(config.Organization{ + Host: host, + Name: "acme", + CodebergToken: "token", + }) + if !ok { + t.Fatalf("expected supported codeberg host variant %q", host) + } + if !client.HasToken() { + t.Fatalf("expected codeberg client token for host variant %q", host) + } + }) + } + }) + + t.Run("unsupported hosts", func(t *testing.T) { + t.Parallel() + + unsupportedHosts := []string{ + "ssh://example.org", + "git@gitlab.com", + "file:///srv/git", + } + + for _, host := range unsupportedHosts { host := host t.Run(host, func(t *testing.T) { t.Parallel() -- cgit v1.2.3