git-lfs/lfs/gitfilter.go
Chris Darroch 6db0c47acf go.*,lfs: mock time in copy callback log file test
In commit 00f1e9521ab5d39aab393796745189d39c27b9a0 of PR #5504 we added
the TestCopyCallbackFileThrottle() test function to confirm that the
CopyCallbackFile() method of GitFilter structure in the "lfs" package
now throttled its output of progress messages into a log file so that,
in general, no more than one message was written during the interval
defined by the tasklog.DefaultLoggingThrottle value.  This new throttling
behaviour was added in commit 5bfa9009dafce59789b88b1a0854691b596f6e76
in the same PR.

The TestCopyCallbackFileThrottle() function attempts to validate
the throttling action by reading a test buffer in segments and waiting
or not waiting between each read, expecting the log messages to be
written or not written, as appropriate.  However, because our CI test
suite may experience slow execution times as a result of running in
virtualized environments, reads may occur at times more than the
tasklog.DefaultLoggingThrottle interval apart even without the artifical
waits injected by the test function, causing the test to fail when it
sees more log messages than it expects.

We can avoid this problem by making the wait intervals in the test
deterministic using a mocked value for the current time.  We use
the github.com/jmhodges/clock package for this purpose, adding an
object of its Clock interface type to the GitFilter structure.  In
all non-test code this object is simply a wrapper for the "time"
package's functions, but in our test we can use a variant which allows
us to control the time values returned to the CopyCallbackFile() method,
either stepping forward or not, as we desire.
2023-09-28 00:04:40 -07:00

29 lines
716 B
Go

package lfs
import (
"github.com/git-lfs/git-lfs/v3/config"
"github.com/git-lfs/git-lfs/v3/fs"
"github.com/git-lfs/git-lfs/v3/git"
"github.com/jmhodges/clock"
)
// GitFilter provides clean and smudge capabilities
type GitFilter struct {
cfg *config.Configuration
fs *fs.Filesystem
clk clock.Clock
}
// NewGitFilter initializes a new *GitFilter
func NewGitFilter(cfg *config.Configuration) *GitFilter {
return &GitFilter{cfg: cfg, fs: cfg.Filesystem(), clk: clock.New()}
}
func (f *GitFilter) ObjectPath(oid string) (string, error) {
return f.fs.ObjectPath(oid)
}
func (f *GitFilter) RemoteRef() *git.Ref {
return git.NewRefUpdate(f.cfg.Git, f.cfg.PushRemote(), f.cfg.CurrentRef(), nil).RemoteRef()
}