-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create
mountertest
package for mount test utils
Signed-off-by: Burak Varlı <[email protected]>
- Loading branch information
Showing
2 changed files
with
42 additions
and
34 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
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,35 @@ | ||
package mountertest | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
"testing" | ||
|
||
"github.com/awslabs/aws-s3-csi-driver/pkg/util/testutil/assert" | ||
) | ||
|
||
// OpenDevNull opens `/dev/null` and returns the file handle. | ||
func OpenDevNull(t *testing.T) *os.File { | ||
file, err := os.Open(os.DevNull) | ||
assert.NoError(t, err) | ||
t.Cleanup(func() { | ||
_ = file.Close() | ||
}) | ||
return file | ||
} | ||
|
||
// AssertSameFile checks if given file handles points to the same underlying file description. | ||
func AssertSameFile(t *testing.T, want *os.File, got *os.File) { | ||
t.Helper() | ||
|
||
var wantStat = &syscall.Stat_t{} | ||
err := syscall.Fstat(int(want.Fd()), wantStat) | ||
assert.NoError(t, err) | ||
|
||
var gotStat = &syscall.Stat_t{} | ||
err = syscall.Fstat(int(got.Fd()), gotStat) | ||
assert.NoError(t, err) | ||
|
||
assert.Equals(t, wantStat.Dev, gotStat.Dev) | ||
assert.Equals(t, wantStat.Ino, gotStat.Ino) | ||
} |