summaryrefslogtreecommitdiffstats
path: root/filetree/data_test.go
blob: 351d6df9d83f314de623d08adb69884ab90ef468 (plain)
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
package filetree

import (
	"testing"
)

func TestAssignDiffType(t *testing.T) {
	tree := NewFileTree()
	node, _, err := tree.AddPath("/usr", *BlankFileChangeInfo("/usr"))
	if err != nil {
		t.Errorf("Expected no error from fetching path. got: %v", err)
	}
	node.Data.DiffType = Modified
	if tree.Root.Children["usr"].Data.DiffType != Modified {
		t.Fail()
	}
}

func TestMergeDiffTypes(t *testing.T) {
	a := Unmodified
	b := Unmodified
	merged := a.merge(b)
	if merged != Unmodified {
		t.Errorf("Expected Unchaged (0) but got %v", merged)
	}
	a = Modified
	b = Unmodified
	merged = a.merge(b)
	if merged != Modified {
		t.Errorf("Expected Unchaged (0) but got %v", merged)
	}
}

func BlankFileChangeInfo(path string) (f *FileInfo) {
	result := FileInfo{
		Path:     path,
		TypeFlag: 1,
		hash:     123,
	}
	return &result
}