logo

go-deblob

Remove binary blobs from a directory (deprecated, consider <https://git.sr.ht/~lanodan/deblob> instead) git clone https://hacktivis.me/git/go-deblob.git

go-deblob_test.go (1793B)


  1. // This file is part of https://hacktivis.me/git/go-deblob
  2. // Copyright © 2019 Haelwenn (lanodan) Monnier <contact+go-deblob-notice@hacktivis.me>
  3. // SPDX-License-Identifier: BSD-3-Clause
  4. package main
  5. import (
  6. "testing"
  7. "os"
  8. "path/filepath"
  9. "reflect"
  10. )
  11. func TestIsBlob(t *testing.T) {
  12. tests := []struct {
  13. path string
  14. expect bool
  15. }{
  16. {"test/fixtures/hello.1", false},
  17. {"test/fixtures/hello.c", false},
  18. {"test/fixtures/hello", true},
  19. // {"test/fixtures/hello.o", true},
  20. {"test/fixtures/hello.a", true},
  21. {"test/fixtures/empty", false},
  22. // {"test/fixtures/option.rom", true},
  23. }
  24. for _, test := range tests {
  25. got := isBlob(test.path)
  26. if got != test.expect {
  27. t.Errorf("isBlob(%s) was incorrect, got: %v, expects: %v.", test.path, got, test.expect)
  28. }
  29. }
  30. }
  31. func TestCheckDir(t *testing.T) {
  32. dirname := "test/checkDir-fixtures"
  33. var files_before []string
  34. var files_after []string
  35. err := filepath.Walk(dirname, func(path string, info os.FileInfo, err error) error {
  36. if err != nil {
  37. t.Errorf("filepath.Walk(%s, /*files_before*/): %s\n", dirname, err)
  38. return err
  39. }
  40. files_before = append(files_before, path)
  41. return nil
  42. })
  43. if err != nil {
  44. t.Errorf("filepath.Walk(%s, /*files_before*/): %s\n", dirname, err)
  45. return
  46. }
  47. checkDir(dirname, false)
  48. err = filepath.Walk(dirname, func(path string, info os.FileInfo, err error) error {
  49. if err != nil {
  50. t.Errorf("filepath.Walk(%s, /*files_after*/): %s\n", dirname, err)
  51. return err
  52. }
  53. files_after = append(files_after, path)
  54. return nil
  55. })
  56. if err != nil {
  57. t.Errorf("filepath.Walk(%s, /*files_after*/): %s\n", dirname, err)
  58. return
  59. }
  60. if reflect.DeepEqual(files_before, files_after) {
  61. t.Errorf("Expected files_before and files_after to differ. files_after: %v\n", files_after)
  62. }
  63. }