initial
This commit is contained in:
87
monitor/drive_test.go
Executable file
87
monitor/drive_test.go
Executable file
@@ -0,0 +1,87 @@
|
||||
package monitor
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"local/sandbox/arlo-cleaner/arlo"
|
||||
"local/sandbox/arlo-cleaner/config"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func mockDrive(t *testing.T) (*Drive, func()) {
|
||||
arlo, def := mockArlo(t)
|
||||
d := &Drive{
|
||||
rclone: arlo.rclone,
|
||||
}
|
||||
return d, def
|
||||
}
|
||||
|
||||
func TestDriveFilters(t *testing.T) {
|
||||
d := &Drive{}
|
||||
videos := []string{expVideo()}
|
||||
videos = d.filters(videos)
|
||||
if len(videos) != 1 {
|
||||
t.Error(videos)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDriveExpired(t *testing.T) {
|
||||
d := &Drive{}
|
||||
if exp := d.expired(expVideo()); !exp {
|
||||
t.Error(exp)
|
||||
}
|
||||
if exp := d.expired(nonExpVideo()); exp {
|
||||
t.Error(exp)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDriveDeletes(t *testing.T) {
|
||||
d, def := mockDrive(t)
|
||||
defer def()
|
||||
|
||||
if err := d.deletes(nil); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := d.deletes([]string{}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := d.deletes([]string{expVideo()}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDriveDelete(t *testing.T) {
|
||||
d, def := mockDrive(t)
|
||||
defer def()
|
||||
|
||||
video := expVideo()
|
||||
abspath := path.Join(strings.TrimPrefix(config.RCloneName, "local:"), video)
|
||||
if err := ioutil.WriteFile(abspath, []byte("hi"), os.ModePerm); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := d.delete(expVideo()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if _, err := os.Stat(abspath); err == nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func expVideo() string {
|
||||
config.ArchiveLength = time.Duration(0)
|
||||
return videoName()
|
||||
}
|
||||
|
||||
func nonExpVideo() string {
|
||||
config.ArchiveLength = time.Hour
|
||||
return videoName()
|
||||
}
|
||||
|
||||
func videoName() string {
|
||||
return time.Now().UTC().Format(arlo.TSFormat)
|
||||
}
|
||||
Reference in New Issue
Block a user