Skip to content

Commit 6a84917

Browse files
committed
test: Fixture sets the testing.TB recursively
When fixtures embed or include fixtures, make sure the TB value is set on nested fields.
1 parent 0fd803a commit 6a84917

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

internal/testing/exp/fixture/fixture.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,21 @@ func (f FixtureSetup[T]) setup(val reflect.Value) Setuper {
125125
}
126126
setups.append(f.setup(val.FieldByIndex(field.Index)))
127127
}
128-
if setup, ok := val.Interface().(Setuper); ok {
128+
actualVal := val.Interface()
129+
if setup, ok := actualVal.(Setuper); ok {
129130
setups.append(setup)
130131
} else if val.CanAddr() {
131132
if setup, ok := val.Addr().Interface().(Setuper); ok {
132133
setups.append(setup)
133134
}
134135
}
136+
if init, ok := actualVal.(FixtureInit); ok {
137+
init.SetTB(f.TB)
138+
} else if val.CanAddr() {
139+
if init, ok := val.Addr().Interface().(FixtureInit); ok {
140+
init.SetTB(f.TB)
141+
}
142+
}
135143
// var res *NullSetup
136144
return setups
137145
}

0 commit comments

Comments
 (0)