Skip to content

Commit b87dc50

Browse files
authored
test(sidekick): improve testing for Generate() (#2413)
1 parent bd6d568 commit b87dc50

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

internal/sidekick/internal/rust/generate_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,41 @@ var (
7272
}
7373
)
7474

75+
func TestCodecError(t *testing.T) {
76+
outDir := t.TempDir()
77+
goodConfig := &config.Config{
78+
General: config.GeneralConfig{
79+
SpecificationFormat: "openapi",
80+
ServiceConfig: path.Join(testdataDir, "googleapis/google/cloud/secretmanager/v1/secretmanager_v1.yaml"),
81+
SpecificationSource: path.Join(testdataDir, "openapi/secretmanager_openapi_v1.json"),
82+
},
83+
}
84+
errorConfig := &config.Config{
85+
General: config.GeneralConfig{
86+
SpecificationFormat: "openapi",
87+
ServiceConfig: path.Join(testdataDir, "googleapis/google/cloud/secretmanager/v1/secretmanager_v1.yaml"),
88+
SpecificationSource: path.Join(testdataDir, "openapi/secretmanager_openapi_v1.json"),
89+
},
90+
Codec: map[string]string{
91+
"--invalid--": "--invalid--",
92+
},
93+
}
94+
model, err := parser.CreateModel(errorConfig)
95+
if err != nil {
96+
t.Fatal(err)
97+
}
98+
if err := Generate(model, outDir, errorConfig); err == nil {
99+
t.Errorf("expected an error with invalid Codec options")
100+
}
101+
102+
if err := GenerateStorage(outDir, model, errorConfig, model, goodConfig); err == nil {
103+
t.Errorf("expected an error with invalid Codec options for storage")
104+
}
105+
if err := GenerateStorage(outDir, model, goodConfig, model, errorConfig); err == nil {
106+
t.Errorf("expected an error with invalid Codec options for control")
107+
}
108+
}
109+
75110
func TestRustFromOpenAPI(t *testing.T) {
76111
requireProtoc(t)
77112
outDir := t.TempDir()

0 commit comments

Comments
 (0)