MCPcopy Create free account
hub / github.com/dropbox/dbxcli / TestJSONHelpDoesNotChangeCommandExecution

Function TestJSONHelpDoesNotChangeCommandExecution

cmd/help_json_test.go:859–882  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

857}
858
859func TestJSONHelpDoesNotChangeCommandExecution(t *testing.T) {
860 var stdout bytes.Buffer
861 called := false
862 root := newJSONHelpTestRoot(t)
863 ls, _, _ := root.Find([]string{"ls"})
864 ls.RunE = func(cmd *cobra.Command, args []string) error {
865 called = true
866 _, _ = cmd.OutOrStdout().Write([]byte("executed\n"))
867 return nil
868 }
869 root.PersistentPreRunE = nil
870 root.SetOut(&stdout)
871 root.SetArgs([]string{"ls", "--output=json", "/"})
872
873 if err := root.Execute(); err != nil {
874 t.Fatalf("Execute returned error: %v", err)
875 }
876 if !called {
877 t.Fatal("ls command did not execute")
878 }
879 if got := stdout.String(); got != "executed\n" {
880 t.Fatalf("stdout = %q, want command output", got)
881 }
882}
883
884func newJSONHelpTestRoot(t *testing.T) *cobra.Command {
885 t.Helper()

Callers

nothing calls this directly

Calls 2

newJSONHelpTestRootFunction · 0.85
WriteMethod · 0.45

Tested by

no test coverage detected