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

Function TestSpoolStdinToTemp_ReadErrorReportsCleanupFailure

cmd/stdin_test.go:75–107  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

73}
74
75func TestSpoolStdinToTemp_ReadErrorReportsCleanupFailure(t *testing.T) {
76 readErr := io.ErrUnexpectedEOF
77 cleanupErr := errors.New("remove failed")
78 var tempPath string
79 origRemoveFile := removeFile
80 removeFile = func(path string) error {
81 tempPath = path
82 return cleanupErr
83 }
84 t.Cleanup(func() {
85 removeFile = origRemoveFile
86 if tempPath != "" {
87 _ = origRemoveFile(tempPath)
88 }
89 })
90
91 _, _, _, err := spoolStdinToTemp(&failingReader{err: readErr})
92 if err == nil {
93 t.Fatal("expected error for failing reader")
94 }
95 if !errors.Is(err, readErr) {
96 t.Fatalf("error = %v, want read error", err)
97 }
98 if !errors.Is(err, cleanupErr) {
99 t.Fatalf("error = %v, want cleanup error", err)
100 }
101 if tempPath == "" {
102 t.Fatal("expected temp path to be captured")
103 }
104 if !strings.Contains(err.Error(), "sensitive stdin data may remain on disk") {
105 t.Errorf("error = %q, want sensitive-data warning", err.Error())
106 }
107}
108
109func TestSpoolStdinToTemp_CleanupRemovesFile(t *testing.T) {
110 r := bytes.NewReader([]byte("data"))

Callers

nothing calls this directly

Calls 2

spoolStdinToTempFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected