wip
Signed-off-by: Brian McGee <brian@bmcgee.ie>
This commit is contained in:
parent
12e795acf1
commit
efdfe9e808
8
cache/cache.go
vendored
8
cache/cache.go
vendored
|
@ -260,19 +260,17 @@ func ChangeSet(ctx context.Context, walker walk.Walker, filesCh chan<- *walk.Fil
|
|||
}
|
||||
|
||||
// Update is used to record updated cache information for the specified list of paths.
|
||||
func Update(files []*walk.File) (int, error) {
|
||||
func Update(files []*walk.File) error {
|
||||
start := time.Now()
|
||||
defer func() {
|
||||
logger.Infof("finished processing %v paths in %v", len(files), time.Since(start))
|
||||
}()
|
||||
|
||||
if len(files) == 0 {
|
||||
return 0, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
var changes int
|
||||
|
||||
return changes, db.Update(func(tx *bolt.Tx) error {
|
||||
return db.Update(func(tx *bolt.Tx) error {
|
||||
bucket := tx.Bucket([]byte(pathsBucket))
|
||||
|
||||
for _, f := range files {
|
||||
|
|
|
@ -214,17 +214,9 @@ func updateCache(ctx context.Context) func() error {
|
|||
return func() error {
|
||||
batch := make([]*walk.File, 0, BatchSize)
|
||||
|
||||
var changes int
|
||||
|
||||
processBatch := func() error {
|
||||
if Cli.NoCache {
|
||||
changes += len(batch)
|
||||
} else {
|
||||
count, err := cache.Update(batch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
changes += count
|
||||
if err := cache.Update(batch); err != nil {
|
||||
return err
|
||||
}
|
||||
batch = batch[:0]
|
||||
return nil
|
||||
|
@ -253,7 +245,7 @@ func updateCache(ctx context.Context) func() error {
|
|||
return err
|
||||
}
|
||||
|
||||
if Cli.FailOnChange && changes != 0 {
|
||||
if Cli.FailOnChange && stats.Value(stats.Formatted) != 0 {
|
||||
return ErrFailOnChange
|
||||
}
|
||||
|
||||
|
|
|
@ -245,27 +245,26 @@ func TestChangeWorkingDirectory(t *testing.T) {
|
|||
assertStats(t, as, out, 31, 31, 31, 0)
|
||||
}
|
||||
|
||||
//
|
||||
//func TestFailOnChange(t *testing.T) {
|
||||
// as := require.New(t)
|
||||
//
|
||||
// tempDir := test.TempExamples(t)
|
||||
// configPath := tempDir + "/echo.toml"
|
||||
//
|
||||
// // test without any excludes
|
||||
// cfg := config2.Config{
|
||||
// Formatters: map[string]*config2.Formatter{
|
||||
// "echo": {
|
||||
// Command: "echo",
|
||||
// Includes: []string{"*"},
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// test.WriteConfig(t, configPath, cfg)
|
||||
// _, err := cmd(t, "--fail-on-change", "--config-file", configPath, "--tree-root", tempDir)
|
||||
// as.ErrorIs(err, ErrFailOnChange)
|
||||
//}
|
||||
func TestFailOnChange(t *testing.T) {
|
||||
as := require.New(t)
|
||||
|
||||
tempDir := test.TempExamples(t)
|
||||
configPath := tempDir + "/echo.toml"
|
||||
|
||||
// test without any excludes
|
||||
cfg := config2.Config{
|
||||
Formatters: map[string]*config2.Formatter{
|
||||
"touch": {
|
||||
Command: "touch",
|
||||
Includes: []string{"*"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
test.WriteConfig(t, configPath, cfg)
|
||||
_, err := cmd(t, "--fail-on-change", "--config-file", configPath, "--tree-root", tempDir)
|
||||
as.ErrorIs(err, ErrFailOnChange)
|
||||
}
|
||||
|
||||
func TestBustCacheOnFormatterChange(t *testing.T) {
|
||||
as := require.New(t)
|
||||
|
|
Reference in New Issue
Block a user