mirror of https://github.com/qwc/backive.git
Add first unit test
This commit is contained in:
parent
e5e7f7326a
commit
5602907eb0
|
@ -65,10 +65,9 @@ func (b *Backup) PrepareRun() error {
|
||||||
)
|
)
|
||||||
CreateDirectoryIfNotExists(backupPath)
|
CreateDirectoryIfNotExists(backupPath)
|
||||||
// configure extra logger
|
// configure extra logger
|
||||||
logname := "/var/log/backive/backive.log"
|
logdir := config.Settings.LogLocation
|
||||||
logdir, _ := path.Split(logname)
|
|
||||||
CreateDirectoryIfNotExists(logdir)
|
CreateDirectoryIfNotExists(logdir)
|
||||||
logname = path.Join(logdir, b.Name) + ".log"
|
logname := path.Join(logdir, b.Name) + ".log"
|
||||||
logfile, err := os.OpenFile(logname, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
|
logfile, err := os.OpenFile(logname, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error creating logfile!")
|
log.Println("Error creating logfile!")
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package backive
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestFindBackupsForDevice(t *testing.T) {
|
||||||
|
var testBackups = Backups{}
|
||||||
|
|
||||||
|
testBackups["backup1"] = &Backup{
|
||||||
|
Name: "backup1",
|
||||||
|
TargetDevice: "dev1",
|
||||||
|
}
|
||||||
|
testBackups["backup2"] = &Backup{
|
||||||
|
Name: "backup2",
|
||||||
|
TargetDevice: "dev1",
|
||||||
|
}
|
||||||
|
testBackups["backup3"] = &Backup{
|
||||||
|
Name: "backup3",
|
||||||
|
TargetDevice: "dev2",
|
||||||
|
}
|
||||||
|
|
||||||
|
var testDevice = Device{
|
||||||
|
Name: "dev1",
|
||||||
|
}
|
||||||
|
bkps, found := testBackups.FindBackupsForDevice(testDevice)
|
||||||
|
|
||||||
|
if !found {
|
||||||
|
t.Log("found has to be true")
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
if len(bkps) != 2 {
|
||||||
|
t.Log("Length of the returned backup slice has to be 2")
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
for _, b := range bkps {
|
||||||
|
if b.TargetDevice != testDevice.Name {
|
||||||
|
t.Log("All resulting elements of the returned slice have to have the questioned device as TargetDevice!")
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -12,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func setupLogging() {
|
func setupLogging() {
|
||||||
logname := "/var/log/backive/backive.log"
|
logname := path.Join(config.Settings.LogLocation, "backive.log")
|
||||||
logdir, _ := path.Split(logname)
|
logdir, _ := path.Split(logname)
|
||||||
backive.CreateDirectoryIfNotExists(logdir)
|
backive.CreateDirectoryIfNotExists(logdir)
|
||||||
logfile, err := os.OpenFile(logname, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
|
logfile, err := os.OpenFile(logname, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
|
||||||
|
@ -87,7 +87,6 @@ func defaultCallback(envMap map[string]string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
setupLogging()
|
|
||||||
signalChan := make(chan os.Signal, 1)
|
signalChan := make(chan os.Signal, 1)
|
||||||
signal.Notify(signalChan,
|
signal.Notify(signalChan,
|
||||||
syscall.SIGHUP,
|
syscall.SIGHUP,
|
||||||
|
@ -131,6 +130,7 @@ func main() {
|
||||||
// find and load config
|
// find and load config
|
||||||
database.Load()
|
database.Load()
|
||||||
config.Load()
|
config.Load()
|
||||||
|
setupLogging()
|
||||||
backive.Init(config, database)
|
backive.Init(config, database)
|
||||||
|
|
||||||
// init scheduler and check for next needed runs?
|
// init scheduler and check for next needed runs?
|
||||||
|
|
Loading…
Reference in New Issue