actions_test.go 914 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Author: simon
  2. // Author: ynwdlxm@163.com
  3. // Date: 2025/1/26 16:36
  4. // Desc:
  5. package main
  6. import (
  7. "os"
  8. "testing"
  9. )
  10. func TestFilterOut(t *testing.T) {
  11. testCases := []struct {
  12. name string
  13. file string
  14. ext string
  15. minSize int64
  16. expected bool
  17. }{
  18. {"FilterNoExtension", "testdata/dir.log", "", 0, false},
  19. {"FilterExtensionMath", "testdata/dir.log", ".log", 0, false},
  20. {"FilterExtensionNoMatch", "testdata/dir.log", ".sh", 0, true},
  21. {"FilterExtensionSizeMatch", "testdata/dir.log", ".log", 10, false},
  22. {"FilterExtensionSizeNoMatch", "testdata/dir.log", ".log", 20, true},
  23. }
  24. for _, tc := range testCases {
  25. t.Run(tc.name, func(t *testing.T) {
  26. info, err := os.Stat(tc.file)
  27. if err != nil {
  28. t.Fatal(err)
  29. }
  30. f := filterOut(tc.file, tc.ext, tc.minSize, info)
  31. if f != tc.expected {
  32. t.Errorf("Expected '%t', got '%t' instead\n", tc.expected, f)
  33. }
  34. })
  35. }
  36. }