// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial // SPDX-FileCopyrightText: 2025-2026 Christian Galo package integration import ( "strings" "testing" ) func TestAssertKeyMatch(t *testing.T) { tests := []struct { name string codeKey string manifest Manifest wantErr bool wantMsg []string // substrings the error must contain, when wantErr }{ { name: "matching keys pass", codeKey: "discourse", manifest: Manifest{Key: "discourse", DisplayName: "Discourse"}, }, { name: "matching keys pass with no display name", codeKey: "fedwiki", manifest: Manifest{Key: "fedwiki"}, }, { name: "mismatched keys fail naming both strings", codeKey: "discourse", manifest: Manifest{Key: "forum", DisplayName: "Discourse"}, wantErr: true, wantMsg: []string{"Discourse", "discourse", "forum"}, }, { name: "mismatched keys fail and fall back to codeKey when DisplayName is empty", codeKey: "discourse", manifest: Manifest{Key: "forum"}, wantErr: true, wantMsg: []string{"discourse", "forum"}, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { err := AssertKeyMatch(tt.codeKey, tt.manifest) if (err != nil) != tt.wantErr { t.Fatalf("AssertKeyMatch() error = %v, wantErr %v", err, tt.wantErr) } if !tt.wantErr { return } got := err.Error() for _, want := range tt.wantMsg { if !strings.Contains(got, want) { t.Errorf("error %q missing %q", got, want) } } }) } }