Skip to content

Commit 560d0ce

Browse files
committed
rename Suite.Require -> Suite.Fixtures
Also adds an `api.Runnable` interface and switches the porcelain `gdt.From()` function to return that interface instead of a concrete `*suite.Suite` struct. Signed-off-by: Jay Pipes <[email protected]>
1 parent 3b6bfd3 commit 560d0ce

File tree

5 files changed

+71
-32
lines changed

5 files changed

+71
-32
lines changed

Diff for: api/runnable.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Use and distribution licensed under the Apache license version 2.
2+
//
3+
// See the COPYING file in the root project directory for full text.
4+
5+
package api
6+
7+
import (
8+
"context"
9+
"testing"
10+
)
11+
12+
// Runnable are things that Run a `*testing.T`
13+
type Runnable interface {
14+
// Run accepts a context and a `*testing.T` and runs some tests within that
15+
// context
16+
//
17+
// Errors returned by Run() are **RuntimeErrors**, not failures in
18+
// assertions.
19+
Run(context.Context, *testing.T) error
20+
}

Diff for: porcelain.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ var (
8989
NewJSONFixture = jsonfix.New
9090
)
9191

92-
// From returns a new suite.Suite from an `io.Reader`, a string file or
92+
// From returns a new `api.Runnable` from an `io.Reader`, a string file or
9393
// directory path, or the raw bytes of YAML content describing a scenario or
9494
// suite.
95-
func From(source interface{}) (*suite.Suite, error) {
95+
func From(source interface{}) (api.Runnable, error) {
9696
switch src := source.(type) {
9797
case io.Reader:
9898
s, err := scenario.FromReader(src)

Diff for: porcelain_test.go

+40-20
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/gdt-dev/gdt"
1414
"github.com/gdt-dev/gdt/api"
15+
"github.com/gdt-dev/gdt/suite"
1516
"github.com/stretchr/testify/assert"
1617
"github.com/stretchr/testify/require"
1718
)
@@ -39,27 +40,35 @@ func TestFromFileNotFound(t *testing.T) {
3940
assert.True(os.IsNotExist(err))
4041
}
4142

42-
func TestFromSuite(t *testing.T) {
43+
func TestFromSuitePath(t *testing.T) {
4344
assert := assert.New(t)
4445
require := require.New(t)
4546

4647
fp := filepath.Join("suite", "testdata", "exec")
47-
suite, err := gdt.From(fp)
48+
r, err := gdt.From(fp)
4849
require.Nil(err)
49-
require.NotNil(suite)
50+
require.NotNil(r)
5051

51-
assert.Equal(fp, suite.Path)
52-
assert.Len(suite.Scenarios, 2)
52+
assert.IsType(r, &suite.Suite{})
53+
54+
s := r.(*suite.Suite)
55+
56+
assert.Equal(fp, s.Path)
57+
assert.Len(s.Scenarios, 2)
5358
}
5459

55-
func TestFromScenarioPath(t *testing.T) {
60+
func TestFromFilePath(t *testing.T) {
5661
assert := assert.New(t)
5762
require := require.New(t)
5863

5964
fp := filepath.Join("suite", "testdata", "exec", "ls.yaml")
60-
s, err := gdt.From(fp)
65+
r, err := gdt.From(fp)
6166
require.Nil(err)
62-
require.NotNil(s)
67+
require.NotNil(r)
68+
69+
assert.IsType(r, &suite.Suite{})
70+
71+
s := r.(*suite.Suite)
6372

6473
assert.Equal(fp, s.Path)
6574
assert.Len(s.Scenarios, 1)
@@ -74,33 +83,44 @@ func TestFromScenarioReader(t *testing.T) {
7483
fp := filepath.Join("suite", "testdata", "exec", "ls.yaml")
7584
f, err := os.Open(fp)
7685
require.Nil(err)
77-
suite, err := gdt.From(f)
78-
assert.Nil(err)
79-
assert.NotNil(suite)
86+
87+
r, err := gdt.From(f)
88+
require.Nil(err)
89+
require.NotNil(r)
90+
91+
assert.IsType(r, &suite.Suite{})
92+
93+
s := r.(*suite.Suite)
8094

8195
// The scenario's path isn't set because we didn't supply a filepath...
82-
assert.Equal("", suite.Path)
83-
assert.Len(suite.Scenarios, 1)
84-
assert.Len(suite.Scenarios[0].Tests, 1)
96+
assert.Equal("", s.Path)
97+
assert.Len(s.Scenarios, 1)
98+
assert.Len(s.Scenarios[0].Tests, 1)
8599
}
86100

87101
func TestFromScenarioBytes(t *testing.T) {
88102
assert := assert.New(t)
103+
require := require.New(t)
89104

90105
raw := `name: foo
91106
description: simple foo test
92107
tests:
93108
- exec: echo foo
94109
`
95110
b := []byte(raw)
96-
suite, err := gdt.From(b)
97-
assert.Nil(err)
98-
assert.NotNil(suite)
111+
112+
r, err := gdt.From(b)
113+
require.Nil(err)
114+
require.NotNil(r)
115+
116+
assert.IsType(r, &suite.Suite{})
117+
118+
s := r.(*suite.Suite)
99119

100120
// The scenario's path isn't set because we didn't supply a filepath...
101-
assert.Equal("", suite.Path)
102-
assert.Len(suite.Scenarios, 1)
103-
assert.Len(suite.Scenarios[0].Tests, 1)
121+
assert.Equal("", s.Path)
122+
assert.Len(s.Scenarios, 1)
123+
assert.Len(s.Scenarios[0].Tests, 1)
104124
}
105125

106126
func TestRunExecSuite(t *testing.T) {

Diff for: suite/from.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,9 @@ func FromScenario(s *scenario.Scenario) *Suite {
7070
Path: s.Path,
7171
Name: suiteNameFromScenarioPath(s.Path),
7272
Description: s.Description,
73-
// NOTE: require needs to be named to fixture?
74-
Require: s.Fixtures,
75-
Defaults: s.Defaults,
76-
Scenarios: []*scenario.Scenario{s},
73+
Fixtures: s.Fixtures,
74+
Defaults: s.Defaults,
75+
Scenarios: []*scenario.Scenario{s},
7776
}
7877
}
7978

Diff for: suite/suite.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ type Suite struct {
2323
// During parsing, plugins are handed this raw data and asked to interpret
2424
// it into known configuration values for that plugin.
2525
Defaults map[string]interface{} `yaml:"defaults,omitempty"`
26-
// Require specifies an ordered list of fixtures the test suite's test
27-
// cases depends on.
28-
Require []string `yaml:"require,omitempty"`
26+
// Fixtures specifies an ordered list of fixtures the test suite's test
27+
// cases depend on.
28+
Fixtures []string `yaml:"fixtures,omitempty"`
2929
// Scenarios is a collection of test scenarios in this test suite
3030
Scenarios []*scenario.Scenario `yaml:"-"`
3131
}
@@ -61,10 +61,10 @@ func WithDefaults(defaults map[string]interface{}) SuiteModifier {
6161
}
6262
}
6363

64-
// WithRequires sets a test suite's Requires attribute
65-
func WithRequires(require []string) SuiteModifier {
64+
// WithFixtures sets a test suite's Fixtures attribute
65+
func WithFixtures(fixtures []string) SuiteModifier {
6666
return func(s *Suite) {
67-
s.Require = require
67+
s.Fixtures = fixtures
6868
}
6969
}
7070

0 commit comments

Comments
 (0)