-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcleaner_test.go
More file actions
60 lines (53 loc) · 1.84 KB
/
cleaner_test.go
File metadata and controls
60 lines (53 loc) · 1.84 KB
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
55
56
57
58
59
60
package cleaner
import (
"testing"
"time"
"github.com/deis/builder/pkg/sys"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/watch"
)
type namespace struct {
}
// Watch returns a watch.Interface that watches the requested namespaces.
func (r *namespace) Watch(label labels.Selector, field fields.Selector, resourceversion string) (watch.Interface, error) {
nst := watch.NewFake()
go func() {
nst.Add(&api.Namespace{ObjectMeta: api.ObjectMeta{Name: "dir1"}})
nst.Modify(&api.Namespace{ObjectMeta: api.ObjectMeta{Name: "dir1"}})
nst.Delete(&api.Namespace{ObjectMeta: api.ObjectMeta{Name: "dir1"}})
nst.Modify(&api.Namespace{ObjectMeta: api.ObjectMeta{Name: "dir2"}})
nst.Delete(nil)
nst.Add(&api.Pod{ObjectMeta: api.ObjectMeta{Name: "dir3"}})
nst.Delete(&api.Pod{ObjectMeta: api.ObjectMeta{Name: "dir3"}})
nst.Stop()
}()
return nst, nil
}
func (r *namespace) IsAnAPIObject() {}
func TestCleanerRun(t *testing.T) {
ns := &namespace{}
fs := sys.NewFakeFS()
dirhome := "/home/git"
fs.Files["/home/git/dir1.git"] = []byte{}
fs.Files["/home/git/dir2.git"] = []byte{}
fs.Files["/home/git/dir3.git"] = []byte{}
go Run(dirhome, ns, fs)
time.Sleep(5 * time.Second)
// Namespace with name dir1 got deleted directory should be deleted
_, ok := fs.Files["/home/git/dir1.git"]
if ok {
t.Fatal("Test failed: Deleting a namespace should delete respective direcotry")
}
// Namespace with name dir2 got modified directory should not be deleted
_, ok = fs.Files["/home/git/dir2.git"]
if !ok {
t.Fatal("Test failed: Modyfiying a namespace should not delete respective direcotry")
}
// Pod with name dir3 got deleted directory should not be deleted
_, ok = fs.Files["/home/git/dir3.git"]
if !ok {
t.Fatal("Test failed: Deleting a pod should not delete respective direcotry")
}
}