aboutsummaryrefslogtreecommitdiff
path: root/internal/cli/cli_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-23 13:47:25 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-23 13:47:25 +0200
commitb3e5db93f7b59c7b80706ae30b505cb6b7945ec3 (patch)
treef42c52132b49b58540ef78be68cf0bef7479cab5 /internal/cli/cli_test.go
parentcb1f49117d15b9690b46f344c0d6777e558b9021 (diff)
downloadlectio-b3e5db93f7b59c7b80706ae30b505cb6b7945ec3.tar.gz
lectio-b3e5db93f7b59c7b80706ae30b505cb6b7945ec3.zip
cli: subcommand dispatch
Diffstat (limited to 'internal/cli/cli_test.go')
-rw-r--r--internal/cli/cli_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/internal/cli/cli_test.go b/internal/cli/cli_test.go
new file mode 100644
index 0000000..85097ed
--- /dev/null
+++ b/internal/cli/cli_test.go
@@ -0,0 +1,51 @@
+package cli
+
+import (
+ "bytes"
+ "strings"
+ "testing"
+)
+
+func TestHelp(t *testing.T) {
+ var out, errb bytes.Buffer
+ code := Run([]string{"help"}, nil, &out, &errb)
+ if code != 0 || !strings.Contains(out.String(), "lectio") {
+ t.Errorf("help code=%d out=%q", code, out.String())
+ }
+}
+
+func TestUnknownCommand(t *testing.T) {
+ var out, errb bytes.Buffer
+ if code := Run([]string{"bogus"}, nil, &out, &errb); code != 2 {
+ t.Errorf("unknown cmd code=%d want 2", code)
+ }
+}
+
+func TestVersion(t *testing.T) {
+ var out, errb bytes.Buffer
+ if code := Run([]string{"--version"}, nil, &out, &errb); code != 0 {
+ t.Errorf("version code=%d", code)
+ }
+}
+
+// TestBadDate exercises the "date" subcommand's usage-error path (bad
+// YYYY-MM-DD format) without touching the network: format validation
+// happens before any fetch is attempted.
+func TestBadDate(t *testing.T) {
+ t.Setenv("XDG_CONFIG_HOME", t.TempDir())
+ var out, errb bytes.Buffer
+ if code := Run([]string{"date", "13-13-13"}, nil, &out, &errb); code != 2 {
+ t.Errorf("bad date code=%d want 2 (stderr=%q)", code, errb.String())
+ }
+}
+
+// TestUnknownVersion exercises "show"'s version-validation usage-error path
+// without touching the network: the version code is checked against the
+// five known codes before any fetch is attempted.
+func TestUnknownVersion(t *testing.T) {
+ t.Setenv("XDG_CONFIG_HOME", t.TempDir())
+ var out, errb bytes.Buffer
+ if code := Run([]string{"show", "zzz"}, nil, &out, &errb); code != 2 {
+ t.Errorf("unknown version code=%d want 2 (stderr=%q)", code, errb.String())
+ }
+}