From a6e537820b7b4554637de588e87ca2d77b8cad90 Mon Sep 17 00:00:00 2001 From: Todd Treece <360020+toddtreece@users.noreply.github.com> Date: Mon, 28 Feb 2022 13:46:05 -0500 Subject: [PATCH] address PR comments (#467) --- experimental/e2e/fixture/fixture_test.go | 3 --- experimental/e2e/storage/har.go | 8 +++++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/experimental/e2e/fixture/fixture_test.go b/experimental/e2e/fixture/fixture_test.go index ec34ffce5..694216a7e 100644 --- a/experimental/e2e/fixture/fixture_test.go +++ b/experimental/e2e/fixture/fixture_test.go @@ -17,7 +17,6 @@ import ( func TestFixtureAdd(t *testing.T) { t.Run("should add request and response to fixture store", func(t *testing.T) { req, res := setupFixture() - defer req.Body.Close() defer res.Body.Close() store := newFakeStorage() f := fixture.NewFixture(store) @@ -30,7 +29,6 @@ func TestFixtureAdd(t *testing.T) { t.Run("should apply request processor", func(t *testing.T) { req, res := setupFixture() - defer req.Body.Close() defer res.Body.Close() store := newFakeStorage() f := fixture.NewFixture(store) @@ -46,7 +44,6 @@ func TestFixtureAdd(t *testing.T) { t.Run("should apply response processor", func(t *testing.T) { req, res := setupFixture() - defer req.Body.Close() defer res.Body.Close() store := newFakeStorage() f := fixture.NewFixture(store) diff --git a/experimental/e2e/storage/har.go b/experimental/e2e/storage/har.go index 4a189df41..3ca760bb2 100644 --- a/experimental/e2e/storage/har.go +++ b/experimental/e2e/storage/har.go @@ -20,7 +20,7 @@ import ( // HARStorage is a Storage implementation that stores requests and responses in HAR format on disk. type HARStorage struct { - lock sync.Mutex + lock sync.RWMutex path string har *har.HAR currentTime func() time.Time @@ -165,8 +165,8 @@ func (s *HARStorage) Add(req *http.Request, res *http.Response) { // Entries converts HAR entries to a slice of Entry (http.Request and http.Response pairs). func (s *HARStorage) Entries() []*Entry { entries := make([]*Entry, len(s.har.Log.Entries)) - s.lock.Lock() - defer s.lock.Unlock() + s.lock.RLock() + defer s.lock.RUnlock() for i, e := range s.har.Log.Entries { postData := "" @@ -220,6 +220,8 @@ func (s *HARStorage) Entries() []*Entry { // Delete removes the HAR entry with the given ID. func (s *HARStorage) Delete(id string) bool { + s.lock.Lock() + defer s.lock.Unlock() for i, e := range s.har.Log.Entries { if e.Comment == id { s.har.Log.Entries = append(s.har.Log.Entries[:i], s.har.Log.Entries[i+1:]...)