From 4c96ad8d061c56c386f9a16be8f556b8743e1273 Mon Sep 17 00:00:00 2001 From: Tom Fleet Date: Wed, 26 Mar 2025 08:59:45 +0000 Subject: [PATCH] Ensure clean removes the entire snapshot directory --- snapshot.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/snapshot.go b/snapshot.go index 10bc103..47f3c7f 100644 --- a/snapshot.go +++ b/snapshot.go @@ -75,11 +75,12 @@ func (s *SnapShotter) Snap(value any) { // and use that in the call to MkDirAll dir := filepath.Dir(path) - // If clean is set, erase the snapshot directory and then carry on + // If clean is set, erase the entire snapshot directory then carry on, + // re-populating it with the fresh snaps if s.clean { - if err := os.RemoveAll(dir); err != nil { - s.tb.Fatalf("failed to delete %s: %v", dir, err) - + toRemove := filepath.Join("testdata", "snapshots") + if err := os.RemoveAll(toRemove); err != nil { + s.tb.Fatalf("failed to delete %s: %v", toRemove, err) return } } @@ -91,7 +92,6 @@ func (s *SnapShotter) Snap(value any) { content, err := val.Snap() if err != nil { s.tb.Fatalf("%T implements Snapper but Snap() returned an error: %v", val, err) - return } @@ -101,7 +101,6 @@ func (s *SnapShotter) Snap(value any) { content, err := json.MarshalIndent(val, "", " ") if err != nil { s.tb.Fatalf("%T implements json.Marshaler but MarshalJSON() returned an error: %v", val, err) - return } @@ -110,7 +109,6 @@ func (s *SnapShotter) Snap(value any) { content, err := val.MarshalText() if err != nil { s.tb.Fatalf("%T implements encoding.TextMarshaler but MarshalText() returned an error: %v", val, err) - return }