From d3cbab9b2815f48d373f8985de4bd8bcc3bf1df3 Mon Sep 17 00:00:00 2001 From: k1LoW Date: Tue, 24 Dec 2024 14:39:44 +0900 Subject: [PATCH] Fix a bug that caused store values to be lost when using `loop:`. Fix: https://github.com/k1LoW/runn/issues/1128 --- store.go | 9 --------- testdata/book/loop.yml | 12 ++++++++++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/store.go b/store.go index f004284f..e1bba224 100644 --- a/store.go +++ b/store.go @@ -114,11 +114,6 @@ func (s *store) recordAsMapped(idx int, v map[string]any) { if !s.useMap { panic("recordAsMapped can only be used if useMap = true") } - if s.loopIndex != nil && *s.loopIndex > 0 { - // delete values of prevous loop - latestKey := s.stepMapKeys[idx-1] - delete(s.stepMap, latestKey) - } k := s.stepMapKeys[idx] s.stepMap[k] = v } @@ -127,10 +122,6 @@ func (s *store) recordAsListed(idx int, v map[string]any) { if s.useMap { panic("recordAsMapped can only be used if useMap = false") } - if s.loopIndex != nil && *s.loopIndex > 0 { - // delete values of prevous loop - delete(s.stepList, idx-1) - } s.stepList[idx] = v } diff --git a/testdata/book/loop.yml b/testdata/book/loop.yml index 2a0d1d95..47403bb6 100644 --- a/testdata/book/loop.yml +++ b/testdata/book/loop.yml @@ -84,3 +84,15 @@ steps: // 11,12 steps[7].res.rawBody contains "12" && loopmap['hi'].rawBody contains "12" + - + desc: Check that the values of the steps are not lost when using loop + test: | + steps[0] != null + && steps[1] != null + && steps[2] != null + && steps[3] != null + && steps[4] != null + && steps[5] != null + && steps[6] != null + && steps[7] != null + && steps[8] != null