Skip to content

Commit 20b9c5d

Browse files
committed
test(github): remove redundant GraphQL test cases
Delete 7 test cases that duplicate coverage already provided by SetupGitTree integration tests. The SetupGitTree helper automatically constructs GraphQL responses from testdata directories, making manual GraphQL response construction redundant for happy path testing. Deleted from TestFetchTektonDirGraphQL (6 cases): - successful fetch with yaml files - no tekton directory - tekton path is file not directory - mixed yaml and yml extensions - subdirectories with yaml files - empty tekton directory Deleted from TestGetTektonDirGraphQL (1 case): - invalid yaml validation failure (duplicate of existing test) Kept only error cases that cannot be represented via filesystem: - http error, graphql errors, null blob content This reduces test code by 213 lines (34% reduction) while maintaining full coverage through integration tests. Assisted-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 1472007 commit 20b9c5d

2 files changed

Lines changed: 0 additions & 213 deletions

File tree

pkg/provider/github/github_test.go

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -588,42 +588,6 @@ func TestGetTektonDirGraphQL(t *testing.T) {
588588
},
589589
expectedAPICount: 2, // 1 for get_default_branch + 1 for GraphQL
590590
},
591-
{
592-
name: "invalid yaml validation failure",
593-
event: &info.Event{
594-
Organization: "tekton",
595-
Repository: "cat",
596-
TriggerTarget: triggertype.PullRequest,
597-
},
598-
skipSetupGitTree: true,
599-
setup: func(t *testing.T, mux *http.ServeMux, event *info.Event) {
600-
t.Helper()
601-
shaDir := fmt.Sprintf("%x", sha256.Sum256([]byte("testdata/tree/badyaml")))
602-
event.SHA = shaDir
603-
604-
mux.HandleFunc("/api/graphql", func(w http.ResponseWriter, _ *http.Request) {
605-
_ = json.NewEncoder(w).Encode(map[string]any{
606-
"data": map[string]any{
607-
"repository": map[string]any{
608-
"tektonTree": map[string]any{
609-
"entries": []map[string]any{
610-
{
611-
"name": "badyaml.yaml",
612-
"type": "blob",
613-
"path": "badyaml.yaml",
614-
"oid": "badyaml-sha",
615-
"object": map[string]any{"text": "bad:\n yaml:\n - indent\n error"},
616-
},
617-
},
618-
},
619-
},
620-
},
621-
})
622-
})
623-
},
624-
wantErr: "error unmarshalling yaml file badyaml.yaml",
625-
expectedAPICount: 1, // Single GraphQL call
626-
},
627591
}
628592

629593
for _, tt := range tests {

pkg/provider/github/graphql_test.go

Lines changed: 0 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -135,67 +135,6 @@ func TestFetchTektonDirGraphQL(t *testing.T) {
135135
wantErr bool
136136
errContains string
137137
}{
138-
{
139-
name: "successful fetch with yaml files",
140-
handler: func(w http.ResponseWriter, _ *http.Request) {
141-
w.Header().Set("X-RateLimit-Limit", "5000")
142-
w.Header().Set("X-RateLimit-Remaining", "4999")
143-
w.Header().Set("X-RateLimit-Reset", "1735689600")
144-
_ = json.NewEncoder(w).Encode(map[string]any{
145-
"data": map[string]any{
146-
"repository": map[string]any{
147-
"tektonTree": map[string]any{
148-
"entries": []map[string]any{
149-
{
150-
"name": "pipeline.yaml",
151-
"type": "blob",
152-
"path": "pipeline.yaml",
153-
"oid": "abc123",
154-
"object": map[string]any{
155-
"text": "apiVersion: tekton.dev/v1",
156-
},
157-
},
158-
{
159-
"name": "task.yml",
160-
"type": "blob",
161-
"path": "task.yml",
162-
"oid": "def456",
163-
"object": map[string]any{
164-
"text": "kind: Task",
165-
},
166-
},
167-
{
168-
"name": "README.md",
169-
"type": "blob",
170-
"path": "README.md",
171-
"oid": "ghi789",
172-
"object": map[string]any{
173-
"text": "# README",
174-
},
175-
},
176-
},
177-
},
178-
},
179-
},
180-
})
181-
},
182-
wantFiles: 2, // Only .yaml and .yml files
183-
},
184-
{
185-
name: "no tekton directory",
186-
handler: func(w http.ResponseWriter, _ *http.Request) {
187-
w.Header().Set("X-RateLimit-Limit", "5000")
188-
w.Header().Set("X-RateLimit-Remaining", "4998")
189-
_ = json.NewEncoder(w).Encode(map[string]any{
190-
"data": map[string]any{
191-
"repository": map[string]any{
192-
"tektonTree": nil,
193-
},
194-
},
195-
})
196-
},
197-
wantFiles: 0,
198-
},
199138
{
200139
name: "http error",
201140
handler: func(w http.ResponseWriter, _ *http.Request) {
@@ -221,105 +160,6 @@ func TestFetchTektonDirGraphQL(t *testing.T) {
221160
wantErr: true,
222161
errContains: "GraphQL errors",
223162
},
224-
{
225-
name: "tekton path is file not directory",
226-
handler: func(w http.ResponseWriter, _ *http.Request) {
227-
w.Header().Set("X-RateLimit-Limit", "5000")
228-
w.Header().Set("X-RateLimit-Remaining", "4995")
229-
// GraphQL returns a Blob object instead of Tree when .tekton is a file
230-
_ = json.NewEncoder(w).Encode(map[string]any{
231-
"data": map[string]any{
232-
"repository": map[string]any{
233-
"tektonTree": map[string]any{
234-
// Blob object has "text" field instead of "entries"
235-
"text": "this is a file, not a directory",
236-
},
237-
},
238-
},
239-
})
240-
},
241-
wantErr: true,
242-
errContains: ".tekton has been found but is not a directory",
243-
},
244-
{
245-
name: "mixed yaml and yml extensions",
246-
handler: func(w http.ResponseWriter, _ *http.Request) {
247-
w.Header().Set("X-RateLimit-Limit", "5000")
248-
w.Header().Set("X-RateLimit-Remaining", "4994")
249-
_ = json.NewEncoder(w).Encode(map[string]any{
250-
"data": map[string]any{
251-
"repository": map[string]any{
252-
"tektonTree": map[string]any{
253-
"entries": []map[string]any{
254-
{
255-
"name": "pipeline.yaml",
256-
"type": "blob",
257-
"path": "pipeline.yaml",
258-
"oid": "abc123",
259-
"object": map[string]any{
260-
"text": "kind: Pipeline",
261-
},
262-
},
263-
{
264-
"name": "task.yml",
265-
"type": "blob",
266-
"path": "task.yml",
267-
"oid": "def456",
268-
"object": map[string]any{
269-
"text": "kind: Task",
270-
},
271-
},
272-
},
273-
},
274-
},
275-
},
276-
})
277-
},
278-
wantFiles: 2,
279-
},
280-
{
281-
name: "subdirectories with yaml files",
282-
handler: func(w http.ResponseWriter, _ *http.Request) {
283-
w.Header().Set("X-RateLimit-Limit", "5000")
284-
w.Header().Set("X-RateLimit-Remaining", "4993")
285-
_ = json.NewEncoder(w).Encode(map[string]any{
286-
"data": map[string]any{
287-
"repository": map[string]any{
288-
"tektonTree": map[string]any{
289-
"entries": []map[string]any{
290-
{
291-
"name": "pipeline.yaml",
292-
"type": "blob",
293-
"path": "pipeline.yaml",
294-
"oid": "abc123",
295-
"object": map[string]any{
296-
"text": "kind: Pipeline",
297-
},
298-
},
299-
{
300-
"name": "tasks",
301-
"type": "tree",
302-
"path": "tasks",
303-
"oid": "tree-sha",
304-
"object": nil, // Subdirectories don't have blob content
305-
},
306-
{
307-
"name": "build.yaml",
308-
"type": "blob",
309-
"path": "tasks/build.yaml",
310-
"oid": "def456",
311-
"object": map[string]any{
312-
"text": "kind: Task",
313-
},
314-
},
315-
},
316-
},
317-
},
318-
},
319-
})
320-
},
321-
wantFiles: 2, // pipeline.yaml and tasks/build.yaml
322-
},
323163
{
324164
name: "null blob content",
325165
handler: func(w http.ResponseWriter, _ *http.Request) {
@@ -356,23 +196,6 @@ func TestFetchTektonDirGraphQL(t *testing.T) {
356196
},
357197
wantFiles: 1, // Only valid.yaml counted
358198
},
359-
{
360-
name: "empty tekton directory",
361-
handler: func(w http.ResponseWriter, _ *http.Request) {
362-
w.Header().Set("X-RateLimit-Limit", "5000")
363-
w.Header().Set("X-RateLimit-Remaining", "4991")
364-
_ = json.NewEncoder(w).Encode(map[string]any{
365-
"data": map[string]any{
366-
"repository": map[string]any{
367-
"tektonTree": map[string]any{
368-
"entries": []map[string]any{},
369-
},
370-
},
371-
},
372-
})
373-
},
374-
wantFiles: 0,
375-
},
376199
}
377200

378201
for _, tc := range cases {

0 commit comments

Comments
 (0)