Skip to content

Commit

Permalink
Merge pull request #1120 from k1LoW/stepList
Browse files Browse the repository at this point in the history
Change the method of holding the list type step in store from slice to map.
  • Loading branch information
k1LoW authored Dec 18, 2024
2 parents ea242a3 + 58dddb4 commit e1b024f
Show file tree
Hide file tree
Showing 24 changed files with 421 additions and 176 deletions.
2 changes: 1 addition & 1 deletion bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (rnr *bindRunner) Run(ctx context.Context, s *step, first bool) error {
o.store.bindVars = kv
}
if first {
o.record(nil)
o.record(s.idx, nil)
}
return nil
}
Expand Down
42 changes: 21 additions & 21 deletions bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ func TestBindRunnerRun(t *testing.T) {
}{
{
store{
steps: []map[string]any{},
stepList: map[int]map[string]any{},
vars: map[string]any{},
bindVars: map[string]any{},
},
map[string]any{},
store{
steps: []map[string]any{
{},
stepList: map[int]map[string]any{
0: {},
},
vars: map[string]any{},
bindVars: map[string]any{},
Expand All @@ -42,7 +42,7 @@ func TestBindRunnerRun(t *testing.T) {
},
{
store{
steps: []map[string]any{},
stepList: map[int]map[string]any{},
vars: map[string]any{
"key": "value",
},
Expand All @@ -52,8 +52,8 @@ func TestBindRunnerRun(t *testing.T) {
"newkey": "vars.key",
},
store{
steps: []map[string]any{
{},
stepList: map[int]map[string]any{
0: {},
},
vars: map[string]any{
"key": "value",
Expand All @@ -77,7 +77,7 @@ func TestBindRunnerRun(t *testing.T) {
},
{
store{
steps: []map[string]any{},
stepList: map[int]map[string]any{},
vars: map[string]any{
"key": "value",
},
Expand All @@ -87,8 +87,8 @@ func TestBindRunnerRun(t *testing.T) {
"newkey": "'hello'",
},
store{
steps: []map[string]any{
{},
stepList: map[int]map[string]any{
0: {},
},
vars: map[string]any{
"key": "value",
Expand All @@ -112,7 +112,7 @@ func TestBindRunnerRun(t *testing.T) {
},
{
store{
steps: []map[string]any{},
stepList: map[int]map[string]any{},
vars: map[string]any{
"key": "value",
},
Expand All @@ -122,8 +122,8 @@ func TestBindRunnerRun(t *testing.T) {
"newkey": []any{"vars.key", 4, "'hello'"},
},
store{
steps: []map[string]any{
{},
stepList: map[int]map[string]any{
0: {},
},
vars: map[string]any{
"key": "value",
Expand All @@ -147,7 +147,7 @@ func TestBindRunnerRun(t *testing.T) {
},
{
store{
steps: []map[string]any{},
stepList: map[int]map[string]any{},
vars: map[string]any{
"key": "value",
},
Expand All @@ -160,8 +160,8 @@ func TestBindRunnerRun(t *testing.T) {
},
},
store{
steps: []map[string]any{
{},
stepList: map[int]map[string]any{
0: {},
},
vars: map[string]any{
"key": "value",
Expand Down Expand Up @@ -191,7 +191,7 @@ func TestBindRunnerRun(t *testing.T) {
},
{
store{
steps: []map[string]any{},
stepList: map[int]map[string]any{},
vars: map[string]any{
"key": "value",
},
Expand All @@ -205,8 +205,8 @@ func TestBindRunnerRun(t *testing.T) {
"bar[]": "'six'",
},
store{
steps: []map[string]any{
{},
stepList: map[int]map[string]any{
0: {},
},
vars: map[string]any{
"key": "value",
Expand Down Expand Up @@ -244,7 +244,7 @@ func TestBindRunnerRun(t *testing.T) {
},
{
store{
steps: []map[string]any{},
stepList: map[int]map[string]any{},
vars: map[string]any{
"key": "value",
},
Expand All @@ -256,8 +256,8 @@ func TestBindRunnerRun(t *testing.T) {
"bar[]": "'seven'",
},
store{
steps: []map[string]any{
{},
stepList: map[int]map[string]any{
0: {},
},
vars: map[string]any{
"key": "value",
Expand Down
2 changes: 1 addition & 1 deletion cdp.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (rnr *cdpRunner) run(ctx context.Context, cas CDPActions, s *step) error {
r[k] = vv
}
}
o.record(r)
o.record(s.idx, r)

rnr.store = map[string]any{} // clear

Expand Down
6 changes: 3 additions & 3 deletions cdp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,13 @@ func TestCDPRunner(t *testing.T) {
}
})
t.Cleanup(func() {
o.store.steps = []map[string]any{}
o.store.stepList = map[int]map[string]any{}
})
s := newStep(0, "stepKey", o, nil)
if err := r.run(ctx, tt.actions, s); err != nil {
t.Fatal(err)
}
got, ok := o.store.steps[0][tt.wantKey]
got, ok := o.store.stepList[0][tt.wantKey]
if !ok {
t.Errorf("%v not found", tt.wantKey)
}
Expand Down Expand Up @@ -288,7 +288,7 @@ func TestSetUploadFile(t *testing.T) {
{
key := "text"
want := "Posted"
got, ok := o.store.steps[0][key]
got, ok := o.store.stepList[0][key]
if !ok {
t.Errorf("%v not found", key)
}
Expand Down
2 changes: 1 addition & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func (rnr *dbRunner) run(ctx context.Context, q *dbQuery, s *step) error {
if err := tx.Commit(); err != nil {
return err
}
o.record(out)
o.record(s.idx, out)
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ SELECT * FROM users;
t.Error(err)
return
}
got := o.store.steps[0]
got := o.store.stepList[0]
if diff := cmp.Diff(got, tt.want, nil); diff != "" {
t.Error(diff)
}
Expand Down Expand Up @@ -163,7 +163,7 @@ SELECT * FROM users;
t.Error(err)
return
}
got := o.store.steps[0]
got := o.store.stepList[0]
if diff := cmp.Diff(got, tt.want, nil); diff != "" {
t.Error(diff)
}
Expand Down
2 changes: 1 addition & 1 deletion dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (rnr *dumpRunner) run(_ context.Context, out io.Writer, v any, disableNL bo
}
}
if first {
o.record(nil)
o.record(s.idx, nil)
}
return nil
}
Loading

0 comments on commit e1b024f

Please sign in to comment.