gogcli/internal/cmd/auth_services_test.go
salmonumbrella 3371e3f3ad
feat(cli): agent ergonomics + gmail watch exclude labels (#201)
* feat(cli): improve agent ergonomics

* fix(cli): address code review findings

- Fix nil pointer dereference in confirmDestructive when flags is nil
- Deduplicate dry-run logic by delegating to dryRunExit
- Remove deprecated net.Error.Temporary() call (dead since Go 1.18)
- Add unit tests for resolveTasklistID and resolveCalendarID

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: resolve PR #201 conflicts and follow-ups (#201) (thanks @salmonumbrella)

* fix: resolve rebase fallout for PR #201 landing (#201) (thanks @salmonumbrella)

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Peter Steinberger <steipete@gmail.com>
2026-02-14 03:09:49 +01:00

69 lines
1.5 KiB
Go

package cmd
import (
"context"
"encoding/json"
"io"
"testing"
"github.com/steipete/gogcli/internal/outfmt"
"github.com/steipete/gogcli/internal/ui"
)
func TestAuthServices_JSON(t *testing.T) {
u, uiErr := ui.New(ui.Options{Stdout: io.Discard, Stderr: io.Discard, Color: "never"})
if uiErr != nil {
t.Fatalf("ui.New: %v", uiErr)
}
ctx := ui.WithUI(context.Background(), u)
ctx = outfmt.WithMode(ctx, outfmt.Mode{JSON: true})
out := captureStdout(t, func() {
cmd := &AuthServicesCmd{}
if err := cmd.Run(ctx, &RootFlags{}); err != nil {
t.Fatalf("run: %v", err)
}
})
var parsed map[string]any
if err := json.Unmarshal([]byte(out), &parsed); err != nil {
t.Fatalf("parse json: %v", err)
}
raw, ok := parsed["services"].([]any)
if !ok || len(raw) == 0 {
t.Fatalf("missing services in output")
}
var docs map[string]any
for _, entry := range raw {
item, ok := entry.(map[string]any)
if !ok {
continue
}
if svc, _ := item["service"].(string); svc == "docs" {
docs = item
break
}
}
if docs == nil {
t.Fatalf("missing docs service")
}
scopes, _ := docs["scopes"].([]any)
if !containsString(scopes, "https://www.googleapis.com/auth/drive") {
t.Fatalf("docs missing drive scope")
}
if !containsString(scopes, "https://www.googleapis.com/auth/documents") {
t.Fatalf("docs missing documents scope")
}
}
func containsString(items []any, want string) bool {
for _, item := range items {
if s, _ := item.(string); s == want {
return true
}
}
return false
}