Skip to content

Commit e11eb8d

Browse files
committed
better language in errors and tests
1 parent 99c6b99 commit e11eb8d

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

internal/models/stepdef.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func (sd *StepDefinition) tryStepParam(ctx context.Context, param reflect.Type,
267267

268268
text, err := tm.LoadParam(ctx)
269269
if err != nil {
270-
return val, fmt.Errorf("failed to marshal text for arg %d: %w", idx, err)
270+
return val, fmt.Errorf("failed to load param for arg[%d]: %w", idx, err)
271271
}
272272

273273
if param.Kind() == reflect.Ptr {

internal/models/stepdef_test.go

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -550,13 +550,13 @@ func (s sparam) LoadParam(ctx context.Context) (string, error) {
550550
}
551551

552552
func TestShouldSupportStepParam(t *testing.T) {
553-
var marshaller sparam
553+
var sp sparam
554554

555555
fn := func(
556556
ctx context.Context,
557557
a sparam,
558558
) {
559-
marshaller = a
559+
sp = a
560560
}
561561

562562
def := &models.StepDefinition{
@@ -569,7 +569,7 @@ func TestShouldSupportStepParam(t *testing.T) {
569569
def.Args = []interface{}{"hello"}
570570
_, err := def.Run(context.Background())
571571
assert.Nil(t, err)
572-
assert.Equal(t, sparam("hello world!"), marshaller)
572+
assert.Equal(t, sparam("hello world!"), sp)
573573
}
574574

575575
type sparamptr string
@@ -579,13 +579,13 @@ func (s *sparamptr) LoadParam(ctx context.Context) (string, error) {
579579
}
580580

581581
func TestShouldSupportStepParamPointerReceiver(t *testing.T) {
582-
var marshaller sparamptr
582+
var spptr sparamptr
583583

584584
fn := func(
585585
ctx context.Context,
586586
a *sparamptr,
587587
) {
588-
marshaller = *a
588+
spptr = *a
589589
}
590590

591591
def := &models.StepDefinition{
@@ -598,7 +598,30 @@ func TestShouldSupportStepParamPointerReceiver(t *testing.T) {
598598
def.Args = []interface{}{"hello"}
599599
_, err := def.Run(context.Background())
600600
assert.Nil(t, err)
601-
assert.Equal(t, sparamptr("hello world!"), marshaller)
601+
assert.Equal(t, sparamptr("hello world!"), spptr)
602+
}
603+
604+
type sparamerr string
605+
606+
func (s sparamerr) LoadParam(context.Context) (string, error) {
607+
return "", errors.New("oh no")
608+
}
609+
610+
func TestShouldSupportStepParamErrorOnLoad(t *testing.T) {
611+
expectedError := errors.New("failed to load param for arg[0]: oh no")
612+
613+
fn := func(ctx context.Context, s sparamerr) {}
614+
615+
def := &models.StepDefinition{
616+
StepDefinition: formatters.StepDefinition{
617+
Handler: fn,
618+
},
619+
HandlerValue: reflect.ValueOf(fn),
620+
}
621+
622+
def.Args = []interface{}{"hello"}
623+
_, err := def.Run(context.Background())
624+
assert.Equal(t, expectedError.Error(), err.(error).Error())
602625
}
603626

604627
// this test is superficial compared to the ones above where the actual error messages the user woudl see are verified

0 commit comments

Comments
 (0)