(t *testing.T)
| 70 | } |
| 71 | |
| 72 | func TestCopyCallbackFileThrottle(t *testing.T) { |
| 73 | tmpDir := t.TempDir() |
| 74 | logFile := tmpDir + "/git_lfs_progress.log" |
| 75 | osMf := config.UniqMapFetcher(map[string]string{ |
| 76 | "GIT_LFS_PROGRESS": logFile, |
| 77 | }) |
| 78 | gitMf := config.UniqMapFetcher(map[string]string{}) |
| 79 | |
| 80 | fc := clock.NewFake() |
| 81 | gf := GitFilter{ |
| 82 | cfg: &config.Configuration{ |
| 83 | Os: config.EnvironmentOf(osMf), |
| 84 | Git: config.EnvironmentOf(gitMf), |
| 85 | }, |
| 86 | clk: fc, |
| 87 | } |
| 88 | |
| 89 | bufSize := int64(128 * 1024) |
| 90 | cb, f, err := gf.CopyCallbackFile("clean", "test_copy", 1, 1) |
| 91 | assert.NoError(t, err) |
| 92 | defer f.Close() |
| 93 | |
| 94 | r := &tools.CallbackReader{ |
| 95 | TotalSize: bufSize, |
| 96 | Reader: bytes.NewReader(make([]byte, bufSize)), |
| 97 | C: cb, |
| 98 | } |
| 99 | readbuf := make([]byte, 32*1024) |
| 100 | r.Read(readbuf) // message skipped |
| 101 | |
| 102 | fc.Add(tasklog.DefaultLoggingThrottle) |
| 103 | r.Read(readbuf) // message logged due to delay |
| 104 | |
| 105 | fc.Add(tasklog.DefaultLoggingThrottle / 2) |
| 106 | r.Read(readbuf) // message skipped |
| 107 | |
| 108 | r.Read(readbuf) // message logged because reader is finished |
| 109 | |
| 110 | logBytes, err := os.ReadFile(logFile) |
| 111 | assert.Nil(t, err) |
| 112 | |
| 113 | expectedLog := "clean 1/1 65536/131072 test_copy\nclean 1/1 131072/131072 test_copy\n" |
| 114 | assert.Equal(t, expectedLog, string(logBytes)) |
| 115 | } |
nothing calls this directly
no test coverage detected