(t *testing.T)
| 844 | } |
| 845 | |
| 846 | func TestPutJSONIfExistsFailReturnsErrorWithoutStdout(t *testing.T) { |
| 847 | tmpFile := filepath.Join(t.TempDir(), "test.txt") |
| 848 | if err := os.WriteFile(tmpFile, []byte("test"), 0644); err != nil { |
| 849 | t.Fatal(err) |
| 850 | } |
| 851 | |
| 852 | mock := &mockFilesClient{ |
| 853 | getMetadataFn: func(arg *files.GetMetadataArg) (files.IsMetadata, error) { |
| 854 | return putFileMetadata(arg.Path, 12), nil |
| 855 | }, |
| 856 | uploadFn: func(arg *files.UploadArg, content io.Reader) (*files.FileMetadata, error) { |
| 857 | t.Fatal("upload should not be called for failed destination") |
| 858 | return nil, nil |
| 859 | }, |
| 860 | } |
| 861 | stubFilesClient(t, mock) |
| 862 | |
| 863 | var stdout bytes.Buffer |
| 864 | cmd := testPutJSONCmd(&stdout, nil) |
| 865 | if err := cmd.Flags().Set("if-exists", putIfExistsFail); err != nil { |
| 866 | t.Fatal(err) |
| 867 | } |
| 868 | err := put(cmd, []string{tmpFile, "/existing.txt"}) |
| 869 | if err == nil { |
| 870 | t.Fatal("expected error") |
| 871 | } |
| 872 | details := jsonErrorDetails(err) |
| 873 | if details["operation"] != "upload" || details["from_path"] != tmpFile || details["to_path"] != "/existing.txt" { |
| 874 | t.Fatalf("details = %#v, want upload operation and source/destination", details) |
| 875 | } |
| 876 | if stdout.Len() != 0 { |
| 877 | t.Fatalf("stdout = %q, want empty on error", stdout.String()) |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | func TestPutJSONStdinDoesNotExposeTempPath(t *testing.T) { |
| 882 | mock := &mockFilesClient{ |
nothing calls this directly
no test coverage detected