-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bedc04d
commit 4077a01
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io | ||
|
||
import ( | ||
"errors" | ||
"github.com/stretchr/testify/assert" | ||
"os" | ||
"path" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestClose(t *testing.T) { | ||
var err error | ||
t.TempDir() | ||
f, err := os.Create(path.Join(t.TempDir(), "test")) | ||
assert.NoError(t, err) | ||
|
||
Close(f, &err) | ||
assert.NoError(t, err) | ||
|
||
// Try closing the same file again and expect error | ||
Close(f, &err) | ||
assert.Error(t, err) | ||
|
||
// Check that both errors are aggregated | ||
err = errors.New("original error") | ||
Close(f, &err) | ||
assert.Len(t, strings.Split(err.Error(), "\n"), 2) | ||
} |