-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for
getFileOwner_unix
(#48)
- Loading branch information
Showing
2 changed files
with
49 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
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,45 @@ | ||
// +build aix darwin dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris | ||
|
||
package datasetIngestor | ||
|
||
import ( | ||
"os" | ||
"os/user" | ||
"testing" | ||
"io/ioutil" | ||
) | ||
|
||
func TestGetFileOwner(t *testing.T) { | ||
// Create a temporary file | ||
tmpfile, err := ioutil.TempFile("", "example") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.Remove(tmpfile.Name()) // clean up | ||
|
||
// Get the current user | ||
currentUser, err := user.Current() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Get the file info | ||
fileInfo, err := tmpfile.Stat() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Get the file owner | ||
uidName, _ := GetFileOwner(fileInfo) | ||
|
||
// Check if the file owner matches the current user | ||
if uidName != currentUser.Username { | ||
t.Errorf("Expected %s, got %s", currentUser.Username, uidName) | ||
} | ||
|
||
// Check owner of a non-existent file | ||
_, err = os.Stat("non_existent_file") | ||
if err == nil { | ||
t.Fatal("Expected error, got none") | ||
} | ||
} |