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

Function TestRenderJSONOperationOutput

cmd/output_test.go:770–813  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

768}
769
770func TestRenderJSONOperationOutput(t *testing.T) {
771 var stdout bytes.Buffer
772 root := &cobra.Command{Use: "dbxcli"}
773 cmd := &cobra.Command{Use: "get"}
774 root.AddCommand(cmd)
775 cmd.SetOut(&stdout)
776 cmd.Flags().String(outputFlag, "json", "")
777
778 err := renderJSONOperationOutput(
779 cmd,
780 struct {
781 Path string `json:"path"`
782 }{Path: "/file.txt"},
783 []jsonOperationResult{
784 newJSONOperationResult(
785 "downloaded",
786 "file",
787 struct {
788 Source string `json:"source"`
789 }{Source: "/file.txt"},
790 struct {
791 Type string `json:"type"`
792 }{Type: "file"},
793 ),
794 },
795 )
796 if err != nil {
797 t.Fatalf("renderJSONOperationOutput returned error: %v", err)
798 }
799
800 rendered := stdout.String()
801 for _, want := range []string{
802 `"ok":true`,
803 `"schema_version":"1"`,
804 `"command":"get"`,
805 `"input":{"path":"/file.txt"}`,
806 `"results":[{"status":"downloaded","kind":"file"`,
807 `"warnings":[]`,
808 } {
809 if !strings.Contains(rendered, want) {
810 t.Fatalf("output = %s, want %s", rendered, want)
811 }
812 }
813}
814
815func TestNewJSONOperationResultNormalizesObjectFields(t *testing.T) {
816 got := newJSONOperationResult(

Callers

nothing calls this directly

Calls 2

newJSONOperationResultFunction · 0.85

Tested by

no test coverage detected