-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
54 lines (47 loc) · 1.29 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// This file is part of netbackup, a frontend to simplify periodic backups.
// For further information, check https://github.com/marcopaganini/netbackup
//
// (C) 2015-2024 by Marco Paganini <paganini AT paganini DOT net>
package main
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
)
// Test logOpen
func TestLogOpen(t *testing.T) {
w, err := ioutil.TempFile("/tmp/", "test")
if err != nil {
t.Fatalf("TempFile failed: %v", err)
}
testFname := w.Name()
w.Close()
// Test specific file under /tmp. File must exist at the end.
w, err = logOpen(testFname)
if err != nil {
t.Fatalf("logOpen failed: %v", err)
}
w.Close()
if _, err := os.Stat(testFname); err != nil {
t.Errorf("should be able to open %s; got %v", testFname, err)
}
os.Remove(testFname)
// Test that intermediate directories are created
basedir, err := ioutil.TempDir("/tmp", "netbackup_test")
if err != nil {
t.Errorf("error creating temporary dir: %v", err)
}
logpath := "a/b/c/log"
w, err = logOpen(filepath.Join(basedir, logpath))
if err != nil {
t.Fatalf("logOpen failed: %v", err)
}
w.Close()
// File must match the expected name and exist
expected := filepath.Join(basedir, logpath)
if _, err := os.Stat(expected); os.IsNotExist(err) {
t.Errorf("%s not created", expected)
}
os.RemoveAll(basedir)
}