Skip to content

Commit 960c4b4

Browse files
committed
Use test variables in StepState class
Signed-off-by: Ilya <rihter007@inbox.ru>
1 parent 1b4a39b commit 960c4b4

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

pkg/runner/step_state.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type stepState struct {
2222
sb test.TestStepBundle // The test bundle.
2323

2424
ev testevent.Emitter
25+
tsv *testStepsVariables
2526
stepRunner *StepRunner
2627
addTarget AddTargetToStep
2728
stopped chan struct{}
@@ -37,6 +38,7 @@ func newStepState(
3738
stepIndex int,
3839
sb test.TestStepBundle,
3940
emitterFactory TestStepEventsEmitterFactory,
41+
tsv *testStepsVariables,
4042
resumeState json.RawMessage,
4143
resumeStateTargets []target.Target,
4244
onError func(err error),
@@ -45,6 +47,7 @@ func newStepState(
4547
stepIndex: stepIndex,
4648
sb: sb,
4749
ev: emitterFactory.New(sb.TestStepLabel),
50+
tsv: tsv,
4851
stepRunner: NewStepRunner(),
4952
stopped: make(chan struct{}),
5053
resumeState: resumeState,
@@ -113,7 +116,10 @@ func (ss *stepState) Run(ctx xcontext.Context) error {
113116
stepCtx = stepCtx.WithField("step_index", strconv.Itoa(ss.stepIndex))
114117
stepCtx = stepCtx.WithField("step_label", ss.sb.TestStepLabel)
115118

116-
addTarget, resumeTargetsNotifiers, stepRunResult, err := ss.stepRunner.Run(stepCtx, ss.sb, ss.ev, ss.resumeState, ss.resumeStateTargets)
119+
addTarget, resumeTargetsNotifiers, stepRunResult, err := ss.stepRunner.Run(
120+
stepCtx, ss.sb, newStepVariablesAccessor(ss.sb.TestStepLabel, ss.tsv), ss.ev, ss.resumeState,
121+
ss.resumeStateTargets,
122+
)
117123
if err != nil {
118124
return fmt.Errorf("failed to launch step runner: %v", err)
119125
}

pkg/runner/test_runner.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ type TestRunner struct {
4343
steps []*stepState // The pipeline, in order of execution
4444
targets map[string]*targetState // Target state lookup map
4545

46-
stepOutputs *testStepsVariables // contains emitted steps variables
47-
4846
// One mutex to rule them all, used to serialize access to all the state above.
4947
// Could probably be split into several if necessary.
5048
mu sync.Mutex
@@ -144,15 +142,14 @@ func (tr *TestRunner) Run(
144142
}
145143
}
146144

147-
var err error
148-
tr.stepOutputs, err = newTestStepsVariables(t.TestStepsBundles)
145+
stepOutputs, err := newTestStepsVariables(t.TestStepsBundles)
149146
if err != nil {
150147
ctx.Errorf("Failed to initialise test steps variables: %v", err)
151148
return nil, nil, err
152149
}
153150

154151
for targetID, targetState := range tr.targets {
155-
if err := tr.stepOutputs.initTargetStepsVariables(targetID, targetState.StepsVariables); err != nil {
152+
if err := stepOutputs.initTargetStepsVariables(targetID, targetState.StepsVariables); err != nil {
156153
ctx.Errorf("Failed to initialise test steps variables for target: %s: %v", targetID, err)
157154
return nil, nil, err
158155
}
@@ -174,7 +171,7 @@ func (tr *TestRunner) Run(
174171
}
175172

176173
// Step handlers will be started from target handlers as targets reach them.
177-
tr.steps = append(tr.steps, newStepState(i, sb, emitterFactory, srs, resumeStateTargets, func(err error) {
174+
tr.steps = append(tr.steps, newStepState(i, sb, emitterFactory, stepOutputs, srs, resumeStateTargets, func(err error) {
178175
tr.monitorCond.Signal()
179176
}))
180177
}
@@ -221,7 +218,7 @@ func (tr *TestRunner) Run(
221218
numInFlightTargets := 0
222219
for i, tgt := range targets {
223220
tgs := tr.targets[tgt.ID]
224-
tgs.StepsVariables, err = tr.stepOutputs.getTargetStepsVariables(tgt.ID)
221+
tgs.StepsVariables, err = stepOutputs.getTargetStepsVariables(tgt.ID)
225222
if err != nil {
226223
ctx.Errorf("Failed to get steps variables: %v", err)
227224
return nil, nil, err

pkg/test/step.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func CheckIdentifier(s string) error {
156156
return fmt.Errorf("empty identifier")
157157
}
158158
match := identifierRegexPattern.FindString(s)
159-
if match != s {
159+
if len(match) != len(s) {
160160
return fmt.Errorf("identifier should be an non-empty string that matches: %s", identifierRegexPattern.String())
161161
}
162162
return nil

0 commit comments

Comments
 (0)