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

Function TestMvJSONErrorUsesCommandStderr

cmd/mv_test.go:147–175  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

145}
146
147func TestMvJSONErrorUsesCommandStderr(t *testing.T) {
148 stubFilesClient(t, &mockFilesClient{
149 getMetadataFn: func(arg *files.GetMetadataArg) (files.IsMetadata, error) {
150 return nil, fmt.Errorf("path/not_found/")
151 },
152 moveV2Fn: func(arg *files.RelocationArg) (*files.RelocationResult, error) {
153 return nil, fmt.Errorf("path/malformed_path/")
154 },
155 })
156
157 var stdout bytes.Buffer
158 var stderr bytes.Buffer
159 cmd := newRelocationTestCommand(&stdout, &stderr)
160
161 err := mv(cmd, []string{"/src/file.txt", "/dest/file.txt"})
162 if err == nil {
163 t.Fatal("expected mv error")
164 }
165 if stdout.String() != "" {
166 t.Fatalf("stdout = %q, want empty", stdout.String())
167 }
168 if !strings.Contains(stderr.String(), `move "/src/file.txt" to "/dest/file.txt": path/malformed_path/`) {
169 t.Fatalf("stderr = %q, want move API error", stderr.String())
170 }
171 details := jsonErrorDetails(err)
172 if details["operation"] != "move" || details["from_path"] != "/src/file.txt" || details["to_path"] != "/dest/file.txt" {
173 t.Fatalf("details = %#v, want move from/to paths", details)
174 }
175}
176
177func TestMvCommandDefinesIfExistsFlag(t *testing.T) {
178 flag := mvCmd.Flags().Lookup("if-exists")

Callers

nothing calls this directly

Calls 4

stubFilesClientFunction · 0.85
newRelocationTestCommandFunction · 0.85
mvFunction · 0.85
jsonErrorDetailsFunction · 0.85

Tested by

no test coverage detected