diff options
author | Bjørn Erik Pedersen <[email protected]> | 2019-12-20 08:11:36 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2019-12-20 11:38:44 +0100 |
commit | 8a58ebb311fd079f65068e7e37725e4d43f17ab5 (patch) | |
tree | b214284b27d2a2cf35ba0689bea688bdd0597e5f /hugolib/testhelpers_test.go | |
parent | 0453683816cfbc94e1e19c644f5f84213bb8cf35 (diff) | |
download | hugo-8a58ebb311fd079f65068e7e37725e4d43f17ab5.tar.gz hugo-8a58ebb311fd079f65068e7e37725e4d43f17ab5.zip |
hugolib: Improve error and reload handling of hook templates in server mode
Fixes #6635
Diffstat (limited to 'hugolib/testhelpers_test.go')
-rw-r--r-- | hugolib/testhelpers_test.go | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/hugolib/testhelpers_test.go b/hugolib/testhelpers_test.go index 80aafe052..93ea9477c 100644 --- a/hugolib/testhelpers_test.go +++ b/hugolib/testhelpers_test.go @@ -68,6 +68,7 @@ type sitesBuilder struct { // Used to test partial rebuilds. changedFiles []string + removedFiles []string // Aka the Hugo server mode. running bool @@ -386,16 +387,22 @@ func (s *sitesBuilder) WithI18nAdded(filenameContent ...string) *sitesBuilder { } func (s *sitesBuilder) EditFiles(filenameContent ...string) *sitesBuilder { - var changedFiles []string for i := 0; i < len(filenameContent); i += 2 { filename, content := filepath.FromSlash(filenameContent[i]), filenameContent[i+1] absFilename := s.absFilename(filename) - changedFiles = append(changedFiles, absFilename) + s.changedFiles = append(s.changedFiles, absFilename) writeSource(s.T, s.Fs, absFilename, content) } - s.changedFiles = changedFiles + return s +} +func (s *sitesBuilder) RemoveFiles(filenames ...string) *sitesBuilder { + for _, filename := range filenames { + absFilename := s.absFilename(filename) + s.removedFiles = append(s.removedFiles, absFilename) + s.Assert(s.Fs.Source.Remove(absFilename), qt.IsNil) + } return s } @@ -523,17 +530,20 @@ func (s *sitesBuilder) BuildFail(cfg BuildCfg) *sitesBuilder { } func (s *sitesBuilder) changeEvents() []fsnotify.Event { - if len(s.changedFiles) == 0 { - return nil - } - events := make([]fsnotify.Event, len(s.changedFiles)) - // TODO(bep) remove? - for i, v := range s.changedFiles { - events[i] = fsnotify.Event{ + var events []fsnotify.Event + + for _, v := range s.changedFiles { + events = append(events, fsnotify.Event{ Name: v, Op: fsnotify.Write, - } + }) + } + for _, v := range s.removedFiles { + events = append(events, fsnotify.Event{ + Name: v, + Op: fsnotify.Remove, + }) } return events |