This repository has been archived by the owner on Dec 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(trash): create trash dir path for individual block device
- Loading branch information
Showing
9 changed files
with
229 additions
and
16 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
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,37 @@ | ||
package linux | ||
|
||
import ( | ||
"bufio" | ||
"os" | ||
"strings" | ||
) | ||
|
||
type FileSystem struct { | ||
Device string | ||
MountedPoint string | ||
Type string | ||
} | ||
|
||
func MountedList() (fss []FileSystem, err error) { | ||
f, err := os.Open("/etc/mtab") | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer f.Close() | ||
|
||
scanner := bufio.NewScanner(f) | ||
|
||
for scanner.Scan() { | ||
buf := strings.Split(scanner.Text(), " ") | ||
|
||
fs := FileSystem{ | ||
Device: buf[0], | ||
MountedPoint: buf[1], | ||
Type: buf[2], | ||
} | ||
|
||
fss = append(fss, fs) | ||
} | ||
|
||
return | ||
} |
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,20 @@ | ||
package linux | ||
|
||
import "testing" | ||
|
||
func TestMountedList(t *testing.T) { | ||
res, err := MountedList() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if len(res) == 0 { | ||
t.Fatal("Mounted list is empty") | ||
} | ||
|
||
elem := res[0] | ||
|
||
if elem.MountedPoint == "" || elem.Device == "" || elem.Type == "" { | ||
t.Fatalf("Sample element of mounted list is invalid. MountedPoint: %s, Device: %s, Type: %s", elem.MountedPoint, elem.Device, elem.Type) | ||
} | ||
} |
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,62 @@ | ||
package logger | ||
|
||
import ( | ||
"bytes" | ||
"github.com/wittano/filebot/internal/test" | ||
"io" | ||
"os" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestLogInfo(t *testing.T) { | ||
path := test.CreateTempFile(t) | ||
logger := NewLogger(path, ALL) | ||
|
||
input := "Test" | ||
logger.Info(input) | ||
|
||
time.Sleep(10 * time.Millisecond) | ||
|
||
f, err := os.Open(path) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
res, err := io.ReadAll(f) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if len(res) == 0 { | ||
t.Fatalf("Log file is empty") | ||
} | ||
} | ||
|
||
func TestFileStdWriter(t *testing.T) { | ||
path := test.CreateTempFile(t) | ||
writer := fileStdWriter{path} | ||
|
||
exp := []byte("test") | ||
|
||
_, err := writer.Write(exp) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
time.Sleep(10 * time.Millisecond) | ||
|
||
f, err := os.Open(path) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
res, err := io.ReadAll(f) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if !bytes.Equal(exp, res) { | ||
t.Fatalf("Invalid data saved in log file. Expected %v, Actually: %v", exp, res) | ||
} | ||
} |
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
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