MCPcopy
hub / github.com/wagoodman/dive / TestCompareWithAdds

Function TestCompareWithAdds

dive/filetree/file_tree_test.go:478–546  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

476}
477
478func TestCompareWithAdds(t *testing.T) {
479 lowerTree := NewFileTree()
480 upperTree := NewFileTree()
481 lowerPaths := [...]string{"/etc", "/etc/sudoers", "/usr", "/etc/hosts", "/usr/bin"}
482 upperPaths := [...]string{"/etc", "/etc/sudoers", "/usr", "/etc/hosts", "/usr/bin", "/usr/bin/bash", "/a/new/path"}
483
484 for _, value := range lowerPaths {
485 _, _, err := lowerTree.AddPath(value, FileInfo{
486 Path: value,
487 TypeFlag: 1,
488 hash: 123,
489 })
490 if err != nil {
491 t.Errorf("could not setup test: %v", err)
492 }
493 }
494
495 for _, value := range upperPaths {
496 _, _, err := upperTree.AddPath(value, FileInfo{
497 Path: value,
498 TypeFlag: 1,
499 hash: 123,
500 })
501 if err != nil {
502 t.Errorf("could not setup test: %v", err)
503 }
504 }
505
506 failedAssertions := []error{}
507 failedPaths, err := lowerTree.CompareAndMark(upperTree)
508 if err != nil {
509 t.Errorf("Expected tree compare to have no errors, got: %v", err)
510 }
511 if len(failedPaths) > 0 {
512 t.Errorf("expected no filepath errors, got %d", len(failedPaths))
513 }
514 asserter := func(n *FileNode) error {
515
516 p := n.Path()
517 if p == "/" {
518 return nil
519 } else if stringInSlice(p, []string{"/usr/bin/bash", "/a", "/a/new", "/a/new/path"}) {
520 if err := AssertDiffType(n, Added); err != nil {
521 failedAssertions = append(failedAssertions, err)
522 }
523 } else if stringInSlice(p, []string{"/usr/bin", "/usr"}) {
524 if err := AssertDiffType(n, Modified); err != nil {
525 failedAssertions = append(failedAssertions, err)
526 }
527 } else {
528 if err := AssertDiffType(n, Unmodified); err != nil {
529 failedAssertions = append(failedAssertions, err)
530 }
531 }
532 return nil
533 }
534 err = lowerTree.VisitDepthChildFirst(asserter, nil)
535 if err != nil {

Callers

nothing calls this directly

Calls 7

AddPathMethod · 0.95
CompareAndMarkMethod · 0.95
VisitDepthChildFirstMethod · 0.95
NewFileTreeFunction · 0.85
stringInSliceFunction · 0.85
AssertDiffTypeFunction · 0.85
PathMethod · 0.80

Tested by

no test coverage detected