1
0
Fork 0

Added tests to the main package and completely reworked the code around that

This commit is contained in:
Julien Dessaux 2020-02-24 23:05:45 +01:00
parent 2661ce9a2b
commit cadb15f7af
17 changed files with 285 additions and 239 deletions

38
zabbix/workdir.go Normal file
View file

@ -0,0 +1,38 @@
package zabbix
import (
"fmt"
"os"
"path/filepath"
)
const (
bareosWorkDir = "/var/lib/bareos"
baculaWorkDir = "/var/lib/bacula"
)
var root = "/"
// checkWorkDir checks if a work directory is valid
func checkWorkDir() error {
// Determine the work directory to use.
if workDir != "" {
workDir = filepath.Join(root, workDir)
info, err := os.Stat(workDir)
if os.IsNotExist(err) || !info.IsDir() {
return fmt.Errorf("Invalid work directory %s : it does not exist or is not a directory", workDir)
}
} else {
workDir = filepath.Join(root, bareosWorkDir)
info, err := os.Stat(workDir)
if os.IsNotExist(err) || !info.IsDir() {
workDir = filepath.Join(root, baculaWorkDir)
info, err := os.Stat(workDir)
if os.IsNotExist(err) || !info.IsDir() {
return fmt.Errorf("Could not find a suitable work directory. Is bareos or bacula installed?")
}
}
}
workDir = filepath.Clean(workDir)
return nil
}