Skip to content

Commit c575ba3

Browse files
authored
test(sidekick): api.PatchDocumentation coverage (#1584)
1 parent a1b3bb6 commit c575ba3

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

internal/sidekick/internal/api/documentation_test.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,102 @@ func TestPatchCommentsMessage(t *testing.T) {
8989
}
9090
}
9191

92+
func testPatchCommentsModel() *API {
93+
m0 := &Message{
94+
Name: "Message0",
95+
Package: "test",
96+
ID: ".test.Message0",
97+
Documentation: Input,
98+
Fields: []*Field{
99+
{
100+
Name: "Field0",
101+
ID: ".test.Message0.Field0",
102+
Documentation: Input,
103+
},
104+
},
105+
}
106+
e0 := &Enum{
107+
Name: "Enum0",
108+
Package: "test",
109+
ID: ".test.Enum0",
110+
Documentation: Input,
111+
Values: []*EnumValue{
112+
{
113+
Name: "EV0",
114+
ID: ".test.Enum0.EV0",
115+
Documentation: Input,
116+
},
117+
},
118+
}
119+
s0 := &Service{
120+
Name: "Service0",
121+
Package: "test",
122+
ID: ".test.Service0",
123+
Documentation: Input,
124+
Methods: []*Method{
125+
{
126+
Name: "Method0",
127+
ID: ".test.Service0.Method0",
128+
Documentation: Input,
129+
},
130+
},
131+
}
132+
return NewTestAPI([]*Message{m0}, []*Enum{e0}, []*Service{s0})
133+
}
134+
135+
func TestPatchCommentsMessageNotFound(t *testing.T) {
136+
model := testPatchCommentsModel()
137+
138+
missing := []string{
139+
".test.MissingMessage",
140+
".test.Message0.MissingField",
141+
".test.Enum0.MissingEnumValue",
142+
".test.Service0.MissingMethod",
143+
"NotAThing",
144+
}
145+
for _, id := range missing {
146+
cfg := config.Config{
147+
CommentOverrides: []config.DocumentationOverride{
148+
{
149+
ID: id,
150+
Match: Match,
151+
Replace: Replace,
152+
},
153+
},
154+
}
155+
if err := PatchDocumentation(model, &cfg); err == nil {
156+
t.Errorf("expected an error searching for missing entity %q", id)
157+
}
158+
}
159+
}
160+
161+
func TestPatchCommentsNoMatch(t *testing.T) {
162+
model := testPatchCommentsModel()
163+
164+
missing := []string{
165+
".test.Message0",
166+
".test.Message0.Field0",
167+
".test.Enum0",
168+
".test.Enum0.EV0",
169+
".test.Service0",
170+
".test.Service0.Method0",
171+
}
172+
for _, id := range missing {
173+
cfg := config.Config{
174+
CommentOverrides: []config.DocumentationOverride{
175+
{
176+
ID: id,
177+
Match: "NOT A STRING WE WILL FIND",
178+
Replace: Replace,
179+
},
180+
},
181+
}
182+
if err := PatchDocumentation(model, &cfg); err == nil {
183+
t.Errorf("expected an error replacing comments for entity %q", id)
184+
}
185+
}
186+
}
187+
92188
func TestPatchCommentsField(t *testing.T) {
93189
f0 := &Field{
94190
Name: "field_name",

0 commit comments

Comments
 (0)