Skip to content

Commit

Permalink
Send valid path to generator while running test suite
Browse files Browse the repository at this point in the history
So I couldn't figure out what exactly changed here, but as reported in
our channel yesterday, `stripe-mock`'s test suite fails on the latest
version of the OpenAPI spec.

The reason is that when generating list resources, we're currently
filling in `url` with the dud string `<test request path>`, and doing so
causes the generated resource to fail to validate because that string is
not in the OpenAPI spec's `enum` set for `url`.

Here we resolve the problem by plumbing through each URL's path from the
ingested OpenAPI spec and sending it onto the generator.

This doesn't quite fix the problems with the latest OpenAPI though --
there's at least one more case of an invalid fixture which I'm trying to
resolve separately.
  • Loading branch information
brandur committed Mar 30, 2018
1 parent 1644ab8 commit 8867753
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func TestValidFixtures(t *testing.T) {

// Tests that DataGenerator can generate an example of the given schema, and
// that the example validates against the schema correctly
func testCanGenerate(t *testing.T, schema *spec.Schema, expand bool) {
func testCanGenerate(t *testing.T, path spec.Path, schema *spec.Schema, expand bool) {
assert.NotNil(t, schema)

generator := DataGenerator{
Expand All @@ -196,7 +196,7 @@ func testCanGenerate(t *testing.T, schema *spec.Schema, expand bool) {
var example interface{}
var err error
assert.NotPanics(t, func() {
example, err = generator.Generate(schema, "<test request path>", expansions)
example, err = generator.Generate(schema, string(path), expansions)
})
assert.NoError(t, err)

Expand All @@ -218,7 +218,7 @@ func TestResourcesCanBeGenerated(t *testing.T) {
schema := operation.Responses[spec.StatusCode("200")].Content["application/json"].Schema
t.Run(
fmt.Sprintf("%s %s (without expansions)", method, url),
func(t2 *testing.T) { testCanGenerate(t2, schema, false) },
func(t2 *testing.T) { testCanGenerate(t2, url, schema, false) },
)
}
}
Expand All @@ -232,7 +232,7 @@ func TestResourcesCanBeGeneratedAndExpanded(t *testing.T) {
schema := operation.Responses[spec.StatusCode("200")].Content["application/json"].Schema
t.Run(
fmt.Sprintf("%s %s (with expansions)", method, url),
func(t2 *testing.T) { testCanGenerate(t2, schema, true) },
func(t2 *testing.T) { testCanGenerate(t2, url, schema, true) },
)
}
}
Expand Down

0 comments on commit 8867753

Please sign in to comment.