feat(cli): add internal/{text,compat} packages and acceptance scaffold (PR-6)
text/ gh-style display-width string helpers (Truncate / FuzzyAgo / Pluralize)
compat/ server-CLI version skew probe (kubectl) + 24h TTL cache (gh internal/update)
acceptance/contract/ helpers_test.go for in-process cobra exec + golden assert
(uses iostreams.SetForTest singleton replacement; no t.Parallel)
cmdutil/errors.go: AllCodes() + ClassifyHTTPErrorOutputs() bridge for the
contract test suite (no behavior change in error handling)
go-runewidth promoted from indirect to direct (used by text.Truncate for
display-width-aware CJK truncation).
acceptance/contract/helpers_test.go forward-references cmd.NewRootCmd which
is exported in PR-7 — that file does not compile until then by design.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package compat_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/cli/internal/compat"
|
||||
sdk "github.com/Tencent/WeKnora/client"
|
||||
)
|
||||
|
||||
type fakeProbeClient struct {
|
||||
info *sdk.SystemInfo
|
||||
err error
|
||||
}
|
||||
|
||||
func (f *fakeProbeClient) GetSystemInfo(ctx context.Context) (*sdk.SystemInfo, error) {
|
||||
return f.info, f.err
|
||||
}
|
||||
|
||||
func TestProbe_Success(t *testing.T) {
|
||||
c := &fakeProbeClient{info: &sdk.SystemInfo{Version: "1.2.3"}}
|
||||
got, err := compat.Probe(context.Background(), c)
|
||||
if err != nil {
|
||||
t.Fatalf("Probe: %v", err)
|
||||
}
|
||||
if got.ServerVersion != "1.2.3" {
|
||||
t.Errorf("ServerVersion = %q, want %q", got.ServerVersion, "1.2.3")
|
||||
}
|
||||
if got.ProbedAt.IsZero() {
|
||||
t.Error("ProbedAt should be set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestProbe_Error(t *testing.T) {
|
||||
c := &fakeProbeClient{err: errors.New("HTTP error 500: down")}
|
||||
_, err := compat.Probe(context.Background(), c)
|
||||
if err == nil {
|
||||
t.Fatal("expected error")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user