|
|
@ -16,7 +16,7 @@ var date4 = time.Date(2016, 13, 11, 4, 34, 58, 651387237, time.UTC)
|
|
|
|
func TestDiffEmpty(t *testing.T) {
|
|
|
|
func TestDiffEmpty(t *testing.T) {
|
|
|
|
source := []Metadata{}
|
|
|
|
source := []Metadata{}
|
|
|
|
target := []Metadata{}
|
|
|
|
target := []Metadata{}
|
|
|
|
test(t, source, target, []DiffChange{})
|
|
|
|
test(t, source, target, false, []DiffChange{})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestNoDiff(t *testing.T) {
|
|
|
|
func TestNoDiff(t *testing.T) {
|
|
|
@ -35,7 +35,7 @@ func TestNoDiff(t *testing.T) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
test(t, files, files, []DiffChange{})
|
|
|
|
test(t, files, files, false, []DiffChange{})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestDiff(t *testing.T) {
|
|
|
|
func TestDiff(t *testing.T) {
|
|
|
@ -73,7 +73,7 @@ func TestDiff(t *testing.T) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
test(t, source, target, []DiffChange{
|
|
|
|
test(t, source, target, false, []DiffChange{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Path: "a/1",
|
|
|
|
Path: "a/1",
|
|
|
|
Kind: DiffModified,
|
|
|
|
Kind: DiffModified,
|
|
|
@ -89,6 +89,62 @@ func TestDiff(t *testing.T) {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestDiffForceModified(t *testing.T) {
|
|
|
|
|
|
|
|
source := []Metadata{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Path: "a/1",
|
|
|
|
|
|
|
|
Modified: date1,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Path: "a/2",
|
|
|
|
|
|
|
|
Modified: date2,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Path: "b/1",
|
|
|
|
|
|
|
|
Modified: date3,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
target := []Metadata{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Date changed
|
|
|
|
|
|
|
|
Path: "a/1",
|
|
|
|
|
|
|
|
Modified: date1.Add(time.Hour),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
// 2 is added
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 3 is removed
|
|
|
|
|
|
|
|
Path: "a/3",
|
|
|
|
|
|
|
|
Modified: date3,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// No change
|
|
|
|
|
|
|
|
Path: "b/1",
|
|
|
|
|
|
|
|
Modified: date3,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test(t, source, target, true, []DiffChange{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Path: "a/1",
|
|
|
|
|
|
|
|
Kind: DiffModified,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Path: "a/2",
|
|
|
|
|
|
|
|
Kind: DiffAdded,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Path: "a/3",
|
|
|
|
|
|
|
|
Kind: DiffRemoved,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Forced modified
|
|
|
|
|
|
|
|
Path: "b/1",
|
|
|
|
|
|
|
|
Kind: DiffModified,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestDiffWithMoreInSource(t *testing.T) {
|
|
|
|
func TestDiffWithMoreInSource(t *testing.T) {
|
|
|
|
source := []Metadata{
|
|
|
|
source := []Metadata{
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -108,7 +164,7 @@ func TestDiffWithMoreInSource(t *testing.T) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
test(t, source, target, []DiffChange{
|
|
|
|
test(t, source, target, false, []DiffChange{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Path: "a/2",
|
|
|
|
Path: "a/2",
|
|
|
|
Kind: DiffAdded,
|
|
|
|
Kind: DiffAdded,
|
|
|
@ -135,7 +191,7 @@ func TestDiffWithMoreInTarget(t *testing.T) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
test(t, source, target, []DiffChange{
|
|
|
|
test(t, source, target, false, []DiffChange{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Path: "a/2",
|
|
|
|
Path: "a/2",
|
|
|
|
Kind: DiffRemoved,
|
|
|
|
Kind: DiffRemoved,
|
|
|
@ -157,7 +213,7 @@ func TestDiffEmptySource(t *testing.T) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
test(t, source, target, []DiffChange{
|
|
|
|
test(t, source, target, false, []DiffChange{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Path: "a/1",
|
|
|
|
Path: "a/1",
|
|
|
|
Kind: DiffRemoved,
|
|
|
|
Kind: DiffRemoved,
|
|
|
@ -183,7 +239,7 @@ func TestDiffEmptyTarget(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
target := []Metadata{}
|
|
|
|
target := []Metadata{}
|
|
|
|
|
|
|
|
|
|
|
|
test(t, source, target, []DiffChange{
|
|
|
|
test(t, source, target, false, []DiffChange{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Path: "a/1",
|
|
|
|
Path: "a/1",
|
|
|
|
Kind: DiffAdded,
|
|
|
|
Kind: DiffAdded,
|
|
|
@ -210,7 +266,7 @@ func TestDiffCancellation(t *testing.T) {
|
|
|
|
target := []Metadata{}
|
|
|
|
target := []Metadata{}
|
|
|
|
|
|
|
|
|
|
|
|
received := make([]DiffChange, 0)
|
|
|
|
received := make([]DiffChange, 0)
|
|
|
|
err := Diff(toChannel(source), toChannel(target), func(change DiffChange) error {
|
|
|
|
err := Diff(toChannel(source), toChannel(target), false, func(change DiffChange) error {
|
|
|
|
received = append(received, change)
|
|
|
|
received = append(received, change)
|
|
|
|
|
|
|
|
|
|
|
|
if len(received) == 1 {
|
|
|
|
if len(received) == 1 {
|
|
|
@ -229,9 +285,9 @@ func TestDiffCancellation(t *testing.T) {
|
|
|
|
assert.Err(t, err, "cancelled")
|
|
|
|
assert.Err(t, err, "cancelled")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func test(t *testing.T, source, target []Metadata, expected []DiffChange) {
|
|
|
|
func test(t *testing.T, source, target []Metadata, forceModified bool, expected []DiffChange) {
|
|
|
|
received := make([]DiffChange, 0)
|
|
|
|
received := make([]DiffChange, 0)
|
|
|
|
err := Diff(toChannel(source), toChannel(target), func(change DiffChange) error {
|
|
|
|
err := Diff(toChannel(source), toChannel(target), forceModified, func(change DiffChange) error {
|
|
|
|
received = append(received, change)
|
|
|
|
received = append(received, change)
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
})
|
|
|
|