File tree Expand file tree Collapse file tree 2 files changed +5
-6
lines changed Expand file tree Collapse file tree 2 files changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,6 @@ import (
1717func TestFixtureAdd (t * testing.T ) {
1818 t .Run ("should add request and response to fixture store" , func (t * testing.T ) {
1919 req , res := setupFixture ()
20- defer req .Body .Close ()
2120 defer res .Body .Close ()
2221 store := newFakeStorage ()
2322 f := fixture .NewFixture (store )
@@ -30,7 +29,6 @@ func TestFixtureAdd(t *testing.T) {
3029
3130 t .Run ("should apply request processor" , func (t * testing.T ) {
3231 req , res := setupFixture ()
33- defer req .Body .Close ()
3432 defer res .Body .Close ()
3533 store := newFakeStorage ()
3634 f := fixture .NewFixture (store )
@@ -46,7 +44,6 @@ func TestFixtureAdd(t *testing.T) {
4644
4745 t .Run ("should apply response processor" , func (t * testing.T ) {
4846 req , res := setupFixture ()
49- defer req .Body .Close ()
5047 defer res .Body .Close ()
5148 store := newFakeStorage ()
5249 f := fixture .NewFixture (store )
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ import (
2020
2121// HARStorage is a Storage implementation that stores requests and responses in HAR format on disk.
2222type HARStorage struct {
23- lock sync.Mutex
23+ lock sync.RWMutex
2424 path string
2525 har * har.HAR
2626 currentTime func () time.Time
@@ -165,8 +165,8 @@ func (s *HARStorage) Add(req *http.Request, res *http.Response) {
165165// Entries converts HAR entries to a slice of Entry (http.Request and http.Response pairs).
166166func (s * HARStorage ) Entries () []* Entry {
167167 entries := make ([]* Entry , len (s .har .Log .Entries ))
168- s .lock .Lock ()
169- defer s .lock .Unlock ()
168+ s .lock .RLock ()
169+ defer s .lock .RUnlock ()
170170
171171 for i , e := range s .har .Log .Entries {
172172 postData := ""
@@ -220,6 +220,8 @@ func (s *HARStorage) Entries() []*Entry {
220220
221221// Delete removes the HAR entry with the given ID.
222222func (s * HARStorage ) Delete (id string ) bool {
223+ s .lock .Lock ()
224+ defer s .lock .Unlock ()
223225 for i , e := range s .har .Log .Entries {
224226 if e .Comment == id {
225227 s .har .Log .Entries = append (s .har .Log .Entries [:i ], s .har .Log .Entries [i + 1 :]... )
You can’t perform that action at this time.
0 commit comments