Skip to content

Commit

Permalink
Merge branch 'master' into ci-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
wagoodman committed Dec 28, 2018
2 parents 1fb9b31 + ad32c0a commit 6e7bdf8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
1 change: 1 addition & 0 deletions .data/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ RUN rm -rf /root/example/
ADD .data/ /root/.data/
RUN cp /root/saved.txt /tmp/saved.again1.txt
RUN cp /root/saved.txt /root/.data/saved.again2.txt
RUN chmod +x /root/saved.txt
5 changes: 4 additions & 1 deletion filetree/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ func (data *FileInfo) Copy() *FileInfo {
// Compare determines the DiffType between two FileInfos based on the type and contents of each given FileInfo
func (data *FileInfo) Compare(other FileInfo) DiffType {
if data.TypeFlag == other.TypeFlag {
if data.hash == other.hash {
if data.hash == other.hash &&
data.Mode == other.Mode &&
data.Uid == other.Uid &&
data.Gid == other.Gid {
return Unchanged
}
}
Expand Down
46 changes: 43 additions & 3 deletions filetree/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,9 @@ func TestCompareWithAdds(t *testing.T) {
func TestCompareWithChanges(t *testing.T) {
lowerTree := NewFileTree()
upperTree := NewFileTree()
paths := [...]string{"/etc", "/usr", "/etc/hosts", "/etc/sudoers", "/usr/bin"}
changedPaths := []string{"/etc", "/usr", "/etc/hosts", "/etc/sudoers", "/usr/bin"}

for _, value := range paths {
for _, value := range changedPaths {
lowerTree.AddPath(value, FileInfo{
Path: value,
TypeFlag: 1,
Expand All @@ -363,13 +363,53 @@ func TestCompareWithChanges(t *testing.T) {
})
}

chmodPath := "/etc/non-data-change"

lowerTree.AddPath(chmodPath, FileInfo{
Path: chmodPath,
TypeFlag: 1,
hash: 123,
Mode: 0,
})

upperTree.AddPath(chmodPath, FileInfo{
Path: chmodPath,
TypeFlag: 1,
hash: 123,
Mode: 1,
})

changedPaths = append(changedPaths, chmodPath)

chownPath := "/etc/non-data-change-2"

lowerTree.AddPath(chmodPath, FileInfo{
Path: chownPath,
TypeFlag: 1,
hash: 123,
Mode: 1,
Gid: 0,
Uid: 0,
})

upperTree.AddPath(chmodPath, FileInfo{
Path: chownPath,
TypeFlag: 1,
hash: 123,
Mode: 1,
Gid: 12,
Uid: 12,
})

changedPaths = append(changedPaths, chownPath)

lowerTree.Compare(upperTree)
failedAssertions := []error{}
asserter := func(n *FileNode) error {
p := n.Path()
if p == "/" {
return nil
} else if stringInSlice(p, []string{"/etc", "/usr", "/etc/hosts", "/etc/sudoers", "/usr/bin"}) {
} else if stringInSlice(p, changedPaths) {
if err := AssertDiffType(n, Changed); err != nil {
failedAssertions = append(failedAssertions, err)
}
Expand Down

0 comments on commit 6e7bdf8

Please sign in to comment.