diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-29 09:50:52 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-29 09:50:52 +0300 |
| commit | 820c24ffb8bfdd2cd7cba1a5d599cbd6d092ad81 (patch) | |
| tree | 5c47bec2c6938cca0616868d7a2cf68ae148f205 /internal | |
| parent | 6226a1e62b0e7730a5ac1763f03e3fc948d2f894 (diff) | |
fix(config): return stored org pointer in FindOrganization (wq)
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/config/config.go | 6 | ||||
| -rw-r--r-- | internal/config/config_test.go | 21 |
2 files changed, 24 insertions, 3 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 02f2fee..c2084b1 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -151,9 +151,9 @@ func (o *Organization) GetGitURL() string { // FindOrganization finds an organization by host func (c *Config) FindOrganization(host string) *Organization { - for _, org := range c.Organizations { - if org.Host == host { - return &org + for i := range c.Organizations { + if c.Organizations[i].Host == host { + return &c.Organizations[i] } } return nil diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 30b59df..45b8024 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -47,3 +47,24 @@ func TestValidate_DescriptionSyncFieldsMustBePaired(t *testing.T) { t.Fatalf("Validate() error = %q, want descriptionSyncHost context", err) } } + +func TestFindOrganization_ReturnsPointerToStoredElement(t *testing.T) { + t.Parallel() + + cfg := &Config{ + Organizations: []Organization{ + {Host: "git@github.com", Name: "before"}, + }, + } + + org := cfg.FindOrganization("git@github.com") + if org == nil { + t.Fatal("FindOrganization() returned nil, want organization") + } + + org.Name = "after" + + if cfg.Organizations[0].Name != "after" { + t.Fatalf("Organizations[0].Name = %q, want %q", cfg.Organizations[0].Name, "after") + } +} |
