* 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>
42 lines
980 B
Go
42 lines
980 B
Go
package cmd
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestAutoJSON_Version_DefaultsToJSONWhenEnabled(t *testing.T) {
|
|
t.Setenv("GOG_AUTO_JSON", "1")
|
|
|
|
out := captureStdout(t, func() {
|
|
_ = captureStderr(t, func() {
|
|
if err := Execute([]string{"version"}); err != nil {
|
|
t.Fatalf("Execute: %v", err)
|
|
}
|
|
})
|
|
})
|
|
|
|
if !strings.HasPrefix(strings.TrimSpace(out), "{") {
|
|
t.Fatalf("expected json output, got: %q", out)
|
|
}
|
|
if !strings.Contains(out, "\"version\"") {
|
|
t.Fatalf("expected version field in json output, got: %q", out)
|
|
}
|
|
}
|
|
|
|
func TestAutoJSON_Version_RespectsExplicitPlainFlag(t *testing.T) {
|
|
t.Setenv("GOG_AUTO_JSON", "1")
|
|
|
|
out := captureStdout(t, func() {
|
|
_ = captureStderr(t, func() {
|
|
if err := Execute([]string{"--plain", "version"}); err != nil {
|
|
t.Fatalf("Execute: %v", err)
|
|
}
|
|
})
|
|
})
|
|
|
|
if strings.HasPrefix(strings.TrimSpace(out), "{") || strings.Contains(out, "\"version\"") {
|
|
t.Fatalf("expected text output (not json), got: %q", out)
|
|
}
|
|
}
|