TestBuild_ExternalAPI asserts the library surface that external consumers (e.g. cli-server) depend on: Build composes a root command from an InvocationContext plus BuildOptions (WithIO, WithKeychain, HideProfile), and SetDefaultFS swaps the global VFS. This test is the contract guard.
(t *testing.T)
| 25 | // InvocationContext plus BuildOptions (WithIO, WithKeychain, HideProfile), |
| 26 | // and SetDefaultFS swaps the global VFS. This test is the contract guard. |
| 27 | func TestBuild_ExternalAPI(t *testing.T) { |
| 28 | // Exercise SetDefaultFS both directions. Passing nil restores the OS FS. |
| 29 | SetDefaultFS(vfs.OsFs{}) |
| 30 | SetDefaultFS(nil) |
| 31 | |
| 32 | var in, out, errOut bytes.Buffer |
| 33 | rootCmd := Build( |
| 34 | context.Background(), |
| 35 | cmdutil.InvocationContext{}, |
| 36 | WithIO(&in, &out, &errOut), |
| 37 | WithKeychain(noopKeychain{}), |
| 38 | HideProfile(true), |
| 39 | ) |
| 40 | |
| 41 | if rootCmd == nil { |
| 42 | t.Fatal("Build returned nil root command") |
| 43 | } |
| 44 | if rootCmd.Use != "lark-cli" { |
| 45 | t.Errorf("rootCmd.Use = %q, want %q", rootCmd.Use, "lark-cli") |
| 46 | } |
| 47 | if len(rootCmd.Commands()) == 0 { |
| 48 | t.Error("Build produced a root command with no subcommands") |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | // TestBuild_NoOptions guards against regression of the nil-streams panic: |
| 53 | // calling Build without WithIO must fall back to SystemIO rather than |
nothing calls this directly
no test coverage detected