test: Add edge cases for normalizeRequestedScopes

- Test blank scope identifier returns error
- Test wildcard-only input returns wildcard scope

Coverage: 89.7% → 96.6% (remaining 3.4% is defensive
unreachable code path)
This commit is contained in:
rcourtman 2025-12-02 00:19:20 +00:00
parent e07bd834b6
commit 6777257a7a

View file

@ -1,6 +1,7 @@
package api
import (
"strings"
"testing"
"github.com/rcourtman/pulse-go-rewrite/internal/config"
@ -50,3 +51,25 @@ func TestNormalizeRequestedScopesRejectsEmpty(t *testing.T) {
t.Fatal("expected error for empty scopes array")
}
}
func TestNormalizeRequestedScopesRejectsBlankScope(t *testing.T) {
raw := []string{config.ScopeHostReport, " ", config.ScopeSettingsRead}
_, err := normalizeRequestedScopes(&raw)
if err == nil {
t.Fatal("expected error for blank scope identifier")
}
if !strings.Contains(err.Error(), "cannot be blank") {
t.Errorf("expected blank scope error, got: %v", err)
}
}
func TestNormalizeRequestedScopesWildcardOnly(t *testing.T) {
raw := []string{config.ScopeWildcard}
scopes, err := normalizeRequestedScopes(&raw)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(scopes) != 1 || scopes[0] != config.ScopeWildcard {
t.Fatalf("expected wildcard scope only, got %#v", scopes)
}
}