util_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package internal
  2. import (
  3. "os"
  4. "path/filepath"
  5. "testing"
  6. . "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestExtractSizeFromRsyncLog(t *testing.T) {
  9. realLogContent := `
  10. Number of files: 998,470 (reg: 925,484, dir: 58,892, link: 14,094)
  11. Number of created files: 1,049 (reg: 1,049)
  12. Number of deleted files: 1,277 (reg: 1,277)
  13. Number of regular files transferred: 5,694
  14. Total file size: 1.33T bytes
  15. Total transferred file size: 2.86G bytes
  16. Literal data: 780.62M bytes
  17. Matched data: 2.08G bytes
  18. File list size: 37.55M
  19. File list generation time: 7.845 seconds
  20. File list transfer time: 0.000 seconds
  21. Total bytes sent: 7.55M
  22. Total bytes received: 823.25M
  23. sent 7.55M bytes received 823.25M bytes 5.11M bytes/sec
  24. total size is 1.33T speedup is 1,604.11
  25. `
  26. Convey("Log parser should work", t, func() {
  27. tmpDir, err := os.MkdirTemp("", "tunasync")
  28. So(err, ShouldBeNil)
  29. defer os.RemoveAll(tmpDir)
  30. logFile := filepath.Join(tmpDir, "rs.log")
  31. err = os.WriteFile(logFile, []byte(realLogContent), 0755)
  32. So(err, ShouldBeNil)
  33. res := ExtractSizeFromRsyncLog(logFile)
  34. So(res, ShouldEqual, "1.33T")
  35. })
  36. }