walk_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package main
  2. import (
  3. "fmt"
  4. "testing"
  5. "time"
  6. )
  7. var testdata = []struct {
  8. name string
  9. size int
  10. hash string
  11. }{
  12. {"bar", 10, "2f72cc11a6fcd0271ecef8c61056ee1eb1243be3805bf9a9df98f92f7636b05c"},
  13. {"baz/quux", 9, "c154d94e94ba7298a6adb0523afe34d1b6a581d6b893a763d45ddc5e209dcb83"},
  14. {"foo", 7, "aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f"},
  15. }
  16. func TestWalk(t *testing.T) {
  17. m := new(Model)
  18. files := Walk("testdata", m, false)
  19. if l1, l2 := len(files), len(testdata); l1 != l2 {
  20. t.Fatalf("Incorrect number of walked files %d != %d", l1, l2)
  21. }
  22. for i := range testdata {
  23. if n1, n2 := testdata[i].name, files[i].Name; n1 != n2 {
  24. t.Errorf("Incorrect file name %q != %q for case #%d", n1, n2, i)
  25. }
  26. if h1, h2 := fmt.Sprintf("%x", files[i].Blocks[0].Hash), testdata[i].hash; h1 != h2 {
  27. t.Errorf("Incorrect hash %q != %q for case #%d", h1, h2, i)
  28. }
  29. t0 := time.Date(2010, 1, 1, 0, 0, 0, 0, time.UTC).Unix()
  30. t1 := time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC).Unix()
  31. if mt := files[i].Modified; mt < t0 || mt > t1 {
  32. t.Errorf("Unrealistic modtime %d for test %d", mt, i)
  33. }
  34. }
  35. }