Files
xinmi/cli/internal/cmdutil/input_test.go
T
yawan f7fc992f57
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
2026-09-22 16:19:06 +08:00

67 lines
2.2 KiB
Go

package cmdutil
import (
"errors"
"strings"
"testing"
"time"
)
func TestParseTimeFlag(t *testing.T) {
// Empty → unset (nil, nil).
if got, err := ParseTimeFlag("--before", ""); err != nil || got != nil {
t.Errorf(`empty: got (%v, %v), want (nil, nil)`, got, err)
}
// Valid RFC3339 → parsed time.
want, _ := time.Parse(time.RFC3339, "2026-06-01T00:00:00Z")
got, err := ParseTimeFlag("--before", "2026-06-01T00:00:00Z")
if err != nil || got == nil || !got.Equal(want) {
t.Errorf("valid: got (%v, %v)", got, err)
}
// Malformed → CodeInputInvalidArgument naming the label.
_, err = ParseTimeFlag("start_time", "2026-06-01")
var typed *Error
if !errors.As(err, &typed) || typed.Code != CodeInputInvalidArgument {
t.Fatalf("malformed: expected CodeInputInvalidArgument, got %v", err)
}
if !strings.Contains(typed.Message, "start_time") || !strings.Contains(typed.Message, "RFC3339") {
t.Errorf("message %q missing label/RFC3339 hint", typed.Message)
}
}
func TestValidateEnum(t *testing.T) {
allowed := []string{"keyword", "vector", "hybrid"}
// Empty value is "unset" — allowed, returns "".
if got, err := ValidateEnum("mode", "", allowed); err != nil || got != "" {
t.Errorf(`empty: got (%q, %v), want ("", nil)`, got, err)
}
// Exact and case-insensitive matches return the canonical spelling.
for _, in := range []string{"hybrid", "Hybrid", "HYBRID"} {
got, err := ValidateEnum("mode", in, allowed)
if err != nil || got != "hybrid" {
t.Errorf(`%q: got (%q, %v), want ("hybrid", nil)`, in, got, err)
}
}
// Canonical spelling comes from `allowed`, not the input casing.
if got, _ := ValidateEnum("type", "embedding", []string{"Embedding", "Rerank"}); got != "Embedding" {
t.Errorf(`canonical: got %q, want "Embedding"`, got)
}
// Unknown value → CodeInputInvalidArgument naming the flag + valid set.
_, err := ValidateEnum("mode", "hybird", allowed)
var typed *Error
if !errors.As(err, &typed) || typed.Code != CodeInputInvalidArgument {
t.Fatalf("unknown: expected CodeInputInvalidArgument, got %v", err)
}
for _, want := range []string{"--mode", "keyword | vector | hybrid", `"hybird"`} {
if !strings.Contains(typed.Message, want) {
t.Errorf("message %q missing %q", typed.Message, want)
}
}
}