Skip to content

Commit 8a8a812

Browse files
authored
Merge pull request #23 from jaypipes/fixture-debug
add context argument to fixture Stop/Start
2 parents d9a4f14 + 8b27fb6 commit 8a8a812

File tree

6 files changed

+24
-19
lines changed

6 files changed

+24
-19
lines changed

context/context_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"gopkg.in/yaml.v3"
1717
)
1818

19-
func fooStart() {}
19+
func fooStart(_ context.Context) {}
2020

2121
type fooDefaults struct {
2222
Foo string `yaml:"foo"`

fixture/generic.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,30 @@
55
package fixture
66

77
import (
8+
"context"
89
"strings"
910

1011
gdttypes "github.com/gdt-dev/gdt/types"
1112
)
1213

1314
// genericFixture adapts functions and state dicts into the Fixture type
1415
type genericFixture struct {
15-
starter func()
16-
stopper func()
16+
starter func(context.Context)
17+
stopper func(context.Context)
1718
state map[string]interface{}
1819
}
1920

2021
// Start sets up any resources the fixture uses
21-
func (f *genericFixture) Start() {
22+
func (f *genericFixture) Start(ctx context.Context) {
2223
if f.starter != nil {
23-
f.starter()
24+
f.starter(ctx)
2425
}
2526
}
2627

2728
// Stop cleans up any resources the fixture uses
28-
func (f *genericFixture) Stop() {
29+
func (f *genericFixture) Stop(ctx context.Context) {
2930
if f.stopper != nil {
30-
f.stopper()
31+
f.stopper(ctx)
3132
}
3233
}
3334

@@ -54,14 +55,14 @@ func (f *genericFixture) State(key string) interface{} {
5455
type genericFixtureModifier func(s *genericFixture)
5556

5657
// WithStarter allows a starter functor to be adapted into a fixture
57-
func WithStarter(starter func()) genericFixtureModifier {
58+
func WithStarter(starter func(context.Context)) genericFixtureModifier {
5859
return func(f *genericFixture) {
5960
f.starter = starter
6061
}
6162
}
6263

6364
// WithStopper allows a stopper functor to be adapted into a fixture
64-
func WithStopper(stopper func()) genericFixtureModifier {
65+
func WithStopper(stopper func(context.Context)) genericFixtureModifier {
6566
return func(f *genericFixture) {
6667
f.stopper = stopper
6768
}

fixture/generic_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package fixture_test
66

77
import (
8+
"context"
89
"testing"
910

1011
"github.com/gdt-dev/gdt/fixture"
@@ -35,7 +36,7 @@ func TestStarter(t *testing.T) {
3536

3637
started := false
3738

38-
starter := func() {
39+
starter := func(_ context.Context) {
3940
started = true
4041
}
4142

@@ -45,7 +46,7 @@ func TestStarter(t *testing.T) {
4546

4647
assert.False(started)
4748

48-
f.Start()
49+
f.Start(context.TODO())
4950

5051
assert.True(started)
5152
}
@@ -55,7 +56,7 @@ func TestStopper(t *testing.T) {
5556

5657
stopped := false
5758

58-
stopper := func() {
59+
stopper := func(_ context.Context) {
5960
stopped = true
6061
}
6162

@@ -65,7 +66,7 @@ func TestStopper(t *testing.T) {
6566

6667
assert.False(stopped)
6768

68-
f.Stop()
69+
f.Stop(context.TODO())
6970

7071
assert.True(stopped)
7172
}

fixture/json/json.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package json
66

77
import (
8+
"context"
89
"encoding/json"
910
"io"
1011
"io/ioutil"
@@ -18,9 +19,9 @@ type jsonFixture struct {
1819
data interface{}
1920
}
2021

21-
func (f *jsonFixture) Start() {}
22+
func (f *jsonFixture) Start(_ context.Context) {}
2223

23-
func (f *jsonFixture) Stop() {}
24+
func (f *jsonFixture) Stop(_ context.Context) {}
2425

2526
// HasState returns true if the supplied JSONPath expression results in a found
2627
// value in the fixture's data

scenario/run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ func (s *Scenario) Run(ctx context.Context, t *testing.T) error {
3232
if !found {
3333
return gdterrors.RequiredFixtureMissing(fname)
3434
}
35-
fix.Start()
36-
defer fix.Stop()
35+
fix.Start(ctx)
36+
defer fix.Stop(ctx)
3737
}
3838
}
3939
var rterr error

types/fixture.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
package types
66

7+
import "context"
8+
79
// A Fixture allows state to be passed from setups
810
type Fixture interface {
911
// Start sets up the fixture
10-
Start()
12+
Start(context.Context)
1113
// Stop tears down the fixture, cleaning up any owned resources
12-
Stop()
14+
Stop(context.Context)
1315
// HasState returns true if the fixture contains some state with the given
1416
// key
1517
HasState(string) bool

0 commit comments

Comments
 (0)