MCPcopy Index your code
hub / github.com/larksuite/cli / TestHandleRootError_PartialWritePreservesExitCode

Function TestHandleRootError_PartialWritePreservesExitCode

cmd/root_test.go:444–456  ·  view source on GitHub ↗

TestHandleRootError_PartialWritePreservesExitCode pins that when the stderr write fails mid-envelope, handleRootError still returns the typed exit code (ExitAuth=3 for AuthenticationError), not fall through to the plain "Error:" path with exit 1. ExitCodeOf is computed from the typed err BEFORE the

(t *testing.T)

Source from the content-addressed store, hash-verified

442// err BEFORE the envelope write so the exit code is preserved even when
443// the consumer's stderr pipe dies.
444func TestHandleRootError_PartialWritePreservesExitCode(t *testing.T) {
445 t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir())
446
447 f, _, _, _ := cmdutil.TestFactory(t, nil)
448 w := &failingWriter{limit: 20}
449 f.IOStreams.ErrOut = w
450
451 err := errs.NewAuthenticationError(errs.SubtypeTokenExpired, "token expired")
452 exit := handleRootError(f, err)
453 if exit != int(output.ExitAuth) {
454 t.Errorf("exit = %d, want %d (typed exit code preserved despite write failure)", exit, int(output.ExitAuth))
455 }
456}
457
458// TestHandleRootError_BareErrorExitCodeNoStderr pins the silent-exit
459// contract: a *output.BareError is honored for its exit code while stderr stays

Callers

nothing calls this directly

Calls 3

TestFactoryFunction · 0.92
NewAuthenticationErrorFunction · 0.92
handleRootErrorFunction · 0.85

Tested by

no test coverage detected