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:
parent
e07bd834b6
commit
6777257a7a
1 changed files with 23 additions and 0 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue