-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff_test.go
106 lines (91 loc) · 2.59 KB
/
diff_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"path/filepath"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestDiff(t *testing.T) {
Convey("Having different diffs", t, func() {
Convey("If we have both new and old artifacts", func() {
d := Diff{
New: &Artifact{Id: "new"},
Old: &Artifact{Id: "old"},
}
Convey("We need to download the new artifact", func() {
a, ok := d.ToDownload()
So(ok, ShouldBeTrue)
So(a, ShouldResemble, *d.New)
Convey("And remove the old artifact", func() {
a, ok := d.ToRemove()
So(ok, ShouldBeTrue)
So(a, ShouldResemble, *d.Old)
})
})
})
Convey("If have only a new artifact", func() {
d := Diff{
New: &Artifact{Id: "new"},
}
Convey("We need to download the new artifact", func() {
a, ok := d.ToDownload()
So(ok, ShouldBeTrue)
So(a, ShouldResemble, *d.New)
Convey("And we do NOT have to delete the old one", func() {
_, ok := d.ToRemove()
So(ok, ShouldBeFalse)
})
})
})
Convey("If have only an old artifact", func() {
d := Diff{
Old: &Artifact{Id: "old"},
}
Convey("We need to download the new artifact", func() {
_, ok := d.ToDownload()
So(ok, ShouldBeFalse)
Convey("And we do NOT have to delete the old one", func() {
a, ok := d.ToRemove()
So(ok, ShouldBeTrue)
So(a, ShouldResemble, *d.Old)
})
})
})
})
}
func TestDiffTest(t *testing.T) {
Convey("Having a diff set", t, func() {
ds := DiffSet{
Diff{
New: &Artifact{Id: "new1"},
Old: &Artifact{Id: "old1", DeployPath: "arts1"},
},
Diff{
New: &Artifact{Id: "new2"},
},
Diff{
Old: &Artifact{Id: "old3", DeployPath: "arts3"},
},
}
Convey("Get the artifacts we need to download", func() {
toDownload := ds.ToDownload()
So(len(toDownload), ShouldEqual, 2)
Convey("Check that we have all the elements that we need", func() {
So(toDownload[0], ShouldResemble, Artifact{Id: "new1"})
So(toDownload[1], ShouldResemble, Artifact{Id: "new2"})
})
})
Convey("Get the artifacts we need to delete", func() {
p := "rootpath"
toDelete := ds.ToRemove(p)
So(len(toDelete), ShouldEqual, 2)
Convey("Check that we have all the elements that we need", func() {
So(toDelete[0].Artifact, ShouldResemble, Artifact{Id: "old1", DeployPath: "arts1"})
So(toDelete[1].Artifact, ShouldResemble, Artifact{Id: "old3", DeployPath: "arts3"})
Convey("The paths should be be ready to clear", func() {
So(toDelete[0].Path, ShouldEqual, filepath.Join(p, "arts1"))
So(toDelete[1].Path, ShouldEqual, filepath.Join(p, "arts3"))
})
})
})
})
}