MCPcopy
hub / github.com/larksuite/cli / TestHandleRootError_DeprecatedAliasMissingFlagStructured

Function TestHandleRootError_DeprecatedAliasMissingFlagStructured

cmd/root_test.go:276–303  ·  view source on GitHub ↗

TestHandleRootError_DeprecatedAliasMissingFlagStructured pins that a backward-compat alias failing on a cobra-level required flag (which short-circuits before RunE) routes through the structured envelope, so the deprecation notice OnInvoke records in PreRunE is carried on the wire instead of being d

(t *testing.T)

Source from the content-addressed store, hash-verified

274// deprecation notice OnInvoke records in PreRunE is carried on the wire instead
275// of being dropped on a plain "Error:" line.
276func TestHandleRootError_DeprecatedAliasMissingFlagStructured(t *testing.T) {
277 t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir())
278 t.Cleanup(func() { deprecation.SetPending(nil) })
279
280 f, _, _, _ := cmdutil.TestFactory(t, nil)
281 errOut := &bytes.Buffer{}
282 f.IOStreams.ErrOut = errOut
283
284 deprecation.SetPending(&deprecation.Notice{
285 Command: "+write", Replacement: "+cells-set", Skill: "lark-sheets",
286 })
287 // The bare error shape cobra's ValidateRequiredFlags produces: not a typed
288 // errs.* error, so it reaches the deprecation fallback.
289 exit := handleRootError(f, fmt.Errorf(`required flag(s) %q not set`, "values"))
290
291 out := errOut.String()
292 if strings.HasPrefix(strings.TrimSpace(out), "Error:") {
293 t.Fatalf("deprecation pending: want a structured envelope, got a plain Error: line:\n%s", out)
294 }
295 if !strings.Contains(out, `"message"`) || !strings.Contains(out, "values") {
296 t.Errorf("expected a JSON error envelope carrying the failure message; got:\n%s", out)
297 }
298 // The envelope is typed validation, so the exit code must derive from that
299 // category (2) — the wire type and the exit code must not disagree.
300 if exit != int(output.ExitValidation) {
301 t.Errorf("exit = %d, want %d (validation envelope → category-derived exit)", exit, int(output.ExitValidation))
302 }
303}
304
305// TestHandleRootError_AuthConfigWireGolden is the wire-consistency regression
306// baseline for auth/config errors: it pins the typed envelope and exit code the

Callers

nothing calls this directly

Calls 6

SetPendingFunction · 0.92
TestFactoryFunction · 0.92
handleRootErrorFunction · 0.85
CleanupMethod · 0.65
StringMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected