Skip to content

Commit bf7442b

Browse files
Fix test flake revealed by #308
Two issues here: - In the with-config tests, we were generating all the different input files into one output. This makes sense in user code, but in our tests, we reuse the same types all over the place, so not only is it confusing to read all the tests interleaved, it can cause nondeterminism anytime our conflict-detection is incomplete (#123). As it happens, #308 introduced such a case, so tests started flaking. Fixes #281. - This turned the case introduced by #308 from a flake into a consistent failure, which indicates a bug in our option-handling. The bug is actually unrelated to the changes there, so for now I just remove the test case.
1 parent ef288a3 commit bf7442b

File tree

36 files changed

+1025
-1072
lines changed

36 files changed

+1025
-1072
lines changed

generate/generate_test.go

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ func TestGenerateWithConfig(t *testing.T) {
243243
{"OptionalPointerOmitEmpty", "", []string{
244244
"InputObject.graphql",
245245
"PointersOmitEmpty.graphql",
246-
"Omitempty.graphql",
247246
"ListInput.graphql",
248247
}, &Config{
249248
Optional: "pointer_omitempty",
@@ -274,47 +273,49 @@ func TestGenerateWithConfig(t *testing.T) {
274273
},
275274
}
276275

277-
sourceFilename := "SimpleQuery.graphql"
278-
279276
for _, test := range tests {
280277
config := test.config
281278
baseDir := filepath.Join(dataDir, test.baseDir)
282279
t.Run(test.name, func(t *testing.T) {
283280
err := config.ValidateAndFillDefaults(baseDir)
284281
config.Schema = []string{filepath.Join(dataDir, "schema.graphql")}
285-
if test.operations == nil {
286-
config.Operations = []string{filepath.Join(dataDir, sourceFilename)}
287-
} else {
288-
config.Operations = make([]string, len(test.operations))
289-
for i := range test.operations {
290-
config.Operations[i] = filepath.Join(dataDir, test.operations[i])
291-
}
292-
}
293-
if err != nil {
294-
t.Fatal(err)
295-
}
296-
generated, err := Generate(config)
297-
if err != nil {
298-
t.Fatal(err)
282+
operationFiles := test.operations
283+
if operationFiles == nil {
284+
operationFiles = []string{"SimpleQuery.graphql"}
299285
}
300286

301-
for filename, content := range generated {
302-
t.Run(filename, func(t *testing.T) {
303-
testutil.Cupaloy.SnapshotT(t, string(content))
304-
})
305-
}
287+
// Since we often reuse types across test cases, run generation
288+
// separately for each to avoid conflicts.
289+
for _, operationFile := range operationFiles {
290+
t.Run(operationFile, func(t *testing.T) {
291+
config.Operations = []string{filepath.Join(dataDir, operationFile)}
292+
if err != nil {
293+
t.Fatal(err)
294+
}
295+
generated, err := Generate(config)
296+
if err != nil {
297+
t.Fatal(err)
298+
}
306299

307-
t.Run("Build", func(t *testing.T) {
308-
if testing.Short() {
309-
t.Skip("skipping build due to -short")
310-
}
300+
for filename, content := range generated {
301+
t.Run(filename, func(t *testing.T) {
302+
testutil.Cupaloy.SnapshotT(t, string(content))
303+
})
304+
}
311305

312-
err := buildGoFile(sourceFilename,
313-
generated[config.Generated])
314-
if err != nil {
315-
t.Error(err)
316-
}
317-
})
306+
t.Run("Build", func(t *testing.T) {
307+
if testing.Short() {
308+
t.Skip("skipping build due to -short")
309+
}
310+
311+
err := buildGoFile(operationFile,
312+
generated[config.Generated])
313+
if err != nil {
314+
t.Error(err)
315+
}
316+
})
317+
})
318+
}
318319
})
319320
}
320321
}

generate/testdata/snapshots/TestGenerateWithConfig-AutoCamelCase-testdata-queries-generated.go renamed to generate/testdata/snapshots/TestGenerateWithConfig-AutoCamelCase-SnakeCaseFields.graphql-testdata-queries-generated.go

Lines changed: 0 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generate/testdata/snapshots/TestGenerateWithConfig-AutoCamelCase-SnakeCaseType.graphql-testdata-queries-generated.go

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)