-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some more tests for config validation, and fix some gaps (#274)
I set these tests up in #270, but I realized there's a lot more we could test unrelated to that PR. In this commit I add some more tests. They're not really exhaustive yet, but they did catch a few bugs, which I fixed: - we weren't validating the package-name if you do set it (only if we guess it) - If you omitted `generated`, you would try to write generated code to the directory containing `genqlient.yaml`, which makes no sense; now we default to `generated.go`. In the real world it's probably good to set explicitly, but it's actually very convenient in tests that we don't have to, and maybe in small projects too.
- Loading branch information
1 parent
ff790e1
commit 65d934a
Showing
18 changed files
with
141 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
package: invalidConfig | ||
casing: | ||
enums: | ||
MyType: bogus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package: invalidConfig | ||
optional: bogus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package: bogus-package-name |
2 changes: 1 addition & 1 deletion
2
...thConfig-PackageBindings-testdata-queries → ...ageBindings-testdata-queries-generated.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
generate/testdata/snapshots/TestInvalidConfigs-CantGuessPackage.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
invalid config file testdata/invalid-config/CantGuessPackage.yaml: unable to guess package-name: 'invalid-config' is not a valid identifier | ||
Set package name in genqlient.yaml | ||
Example: https://github.com/Khan/genqlient/blob/main/example/genqlient.yaml#L6 |
1 change: 1 addition & 0 deletions
1
generate/testdata/snapshots/TestInvalidConfigs-InvalidOptional.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
invalid config file testdata/invalid-config/InvalidOptional.yaml: optional must be one of: 'value' (default), 'pointer', or 'generic' |
1 change: 1 addition & 0 deletions
1
generate/testdata/snapshots/TestInvalidConfigs-InvalidPackage.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
invalid config file testdata/invalid-config/InvalidPackage.yaml: invalid package in genqlient.yaml: 'bogus-package-name' is not a valid identifier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
(*generate.Config)({ | ||
Schema: (generate.StringList) (len=2) { | ||
(string) (len=42) "testdata/valid-config/first_schema.graphql", | ||
(string) (len=43) "testdata/valid-config/second_schema.graphql" | ||
}, | ||
Operations: (generate.StringList) (len=2) { | ||
(string) (len=46) "testdata/valid-config/first_operations.graphql", | ||
(string) (len=47) "testdata/valid-config/second_operations.graphql" | ||
}, | ||
Generated: (string) (len=34) "testdata/valid-config/generated.go", | ||
Package: (string) (len=11) "validConfig", | ||
ExportOperations: (string) "", | ||
ContextType: (string) (len=15) "context.Context", | ||
ClientGetter: (string) "", | ||
Bindings: (map[string]*generate.TypeBinding) <nil>, | ||
PackageBindings: ([]*generate.PackageBinding) <nil>, | ||
Casing: (generate.Casing) { | ||
AllEnums: (generate.CasingAlgorithm) "", | ||
Enums: (map[string]generate.CasingAlgorithm) <nil> | ||
}, | ||
Optional: (string) "", | ||
OptionalGenericType: (string) "", | ||
StructReferences: (bool) false, | ||
Extensions: (bool) false, | ||
AllowBrokenFeatures: (bool) false, | ||
baseDir: (string) (len=21) "testdata/valid-config" | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
(*generate.Config)({ | ||
Schema: (generate.StringList) <nil>, | ||
Operations: (generate.StringList) <nil>, | ||
Generated: (string) (len=34) "testdata/valid-config/generated.go", | ||
Package: (string) (len=11) "validConfig", | ||
ExportOperations: (string) "", | ||
ContextType: (string) (len=15) "context.Context", | ||
ClientGetter: (string) "", | ||
Bindings: (map[string]*generate.TypeBinding) <nil>, | ||
PackageBindings: ([]*generate.PackageBinding) <nil>, | ||
Casing: (generate.Casing) { | ||
AllEnums: (generate.CasingAlgorithm) "", | ||
Enums: (map[string]generate.CasingAlgorithm) <nil> | ||
}, | ||
Optional: (string) "", | ||
OptionalGenericType: (string) "", | ||
StructReferences: (bool) false, | ||
Extensions: (bool) false, | ||
AllowBrokenFeatures: (bool) false, | ||
baseDir: (string) (len=21) "testdata/valid-config" | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(*generate.Config)({ | ||
Schema: (generate.StringList) (len=1) { | ||
(string) (len=36) "testdata/valid-config/schema.graphql" | ||
}, | ||
Operations: (generate.StringList) (len=1) { | ||
(string) (len=40) "testdata/valid-config/operations.graphql" | ||
}, | ||
Generated: (string) (len=34) "testdata/valid-config/generated.go", | ||
Package: (string) (len=11) "validConfig", | ||
ExportOperations: (string) "", | ||
ContextType: (string) (len=15) "context.Context", | ||
ClientGetter: (string) "", | ||
Bindings: (map[string]*generate.TypeBinding) <nil>, | ||
PackageBindings: ([]*generate.PackageBinding) <nil>, | ||
Casing: (generate.Casing) { | ||
AllEnums: (generate.CasingAlgorithm) "", | ||
Enums: (map[string]generate.CasingAlgorithm) <nil> | ||
}, | ||
Optional: (string) "", | ||
OptionalGenericType: (string) "", | ||
StructReferences: (bool) false, | ||
Extensions: (bool) false, | ||
AllowBrokenFeatures: (bool) false, | ||
baseDir: (string) (len=21) "testdata/valid-config" | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
schema: | ||
- first_schema.graphql | ||
- second_schema.graphql | ||
|
||
operations: | ||
- first_operations.graphql | ||
- second_operations.graphql | ||
|
||
package: validConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package: validConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
schema: schema.graphql | ||
operations: operations.graphql | ||
package: validConfig |