Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitac0e79e

Browse files
CopilotJoannaaKL
authored andcommitted
Add completion script and enhanced migration guide
Co-authored-by: JoannaaKL <67866556+JoannaaKL@users.noreply.github.com>
1 parent0eb2d2f commitac0e79e

File tree

3 files changed

+148
-12
lines changed

3 files changed

+148
-12
lines changed

‎MIGRATION_GUIDE.md‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44

55
**Completed: 8/14 files (57%)**
66

7+
**Next Priority Files:**
8+
1. notifications_test.go (801 lines) -**Easiest** - only 4 simple WithRequestMatch patterns
9+
2. search_test.go (776 lines) - 16 WithRequestMatchHandler (all with expectQueryParams)
10+
3. projects_test.go (1,711 lines) - 31 WithRequestMatchHandler
11+
4. pullrequests_test.go (3,355 lines) - Mixed patterns
12+
5. repositories_test.go (3,532 lines) - Mixed patterns
13+
6. issues_test.go (3,755 lines) -**Largest** - mixed patterns
14+
715
###✅ Migrated Files
816
1. pkg/raw/raw_test.go
917
2. pkg/github/actions_test.go (1,428 lines)
@@ -110,6 +118,40 @@ Replace old mock constants with new ones (note ID vs Id):
110118

111119
All endpoint constants are defined in`pkg/github/helper_test.go`.
112120

121+
##Special Cases
122+
123+
###Case 1: With expectQueryParams and andThen
124+
125+
When the handler uses`expectQueryParams(...).andThen(...)`, the structure must be carefully closed:
126+
127+
```go
128+
// CORRECT:
129+
MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
130+
GetSearchRepositories:expectQueryParams(t,map[string]string{
131+
"q":"test",
132+
}).andThen(
133+
mockResponse(t, http.StatusOK, data),
134+
),// <- Close andThen with ),
135+
}),// <- Close map with }),
136+
137+
// INCORRECT (missing map close):
138+
MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
139+
GetSearchRepositories:expectQueryParams(t,map[string]string{
140+
"q":"test",
141+
}).andThen(
142+
mockResponse(t, http.StatusOK, data),
143+
),// <- Only closes andThen, missing }),
144+
```
145+
146+
### Case 2: Multiple Endpoints in One Mock
147+
148+
```go
149+
MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
150+
GetReposPullsByOwnerByRepoByPullNumber:mockResponse(t, http.StatusOK, mockPR),
151+
GetRawReposContentsByOwnerByRepoBySHAByPath:mockResponse(t, http.StatusOK, mockContent),
152+
}),
153+
```
154+
113155
## Common Issues and Solutions
114156
115157
### Issue 1: Extra Closing Braces

‎complete_migration.sh‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/bin/bash
2+
# Script to complete the go-github-mock to testify migration
3+
# Usage: ./complete_migration.sh
4+
5+
set -e
6+
7+
echo"=== Completing go-github-mock Migration ==="
8+
echo""
9+
echo"This script will:"
10+
echo"1. Migrate remaining 6 test files"
11+
echo"2. Remove go-github-mock dependency"
12+
echo"3. Remove raw_mock.go"
13+
echo"4. Run tests and linter"
14+
echo""
15+
16+
# Files to migrate
17+
FILES=(
18+
"pkg/github/notifications_test.go"
19+
"pkg/github/search_test.go"
20+
"pkg/github/projects_test.go"
21+
"pkg/github/pullrequests_test.go"
22+
"pkg/github/repositories_test.go"
23+
"pkg/github/issues_test.go"
24+
)
25+
26+
echo"Files to migrate:"
27+
forfin"${FILES[@]}";do
28+
lines=$(wc -l<"$f")
29+
echo" -$f ($lines lines)"
30+
done
31+
echo""
32+
33+
read -p"Continue with migration? (y/n)" -n 1 -r
34+
echo
35+
if [[!$REPLY=~ ^[Yy]$ ]];then
36+
echo"Migration cancelled"
37+
exit 1
38+
fi
39+
40+
# Backup files
41+
echo"Creating backups..."
42+
forfin"${FILES[@]}";do
43+
cp"$f""$f.backup"
44+
done
45+
46+
# Migration function
47+
migrate_file() {
48+
local file=$1
49+
echo"Migrating$file..."
50+
51+
# Remove mock import
52+
sed -i'/github\.com\/migueleliasweb\/go-github-mock\/src\/mock/d'"$file"
53+
54+
# Fix ID naming
55+
sed -i's/ThreadId/ThreadID/g; s/GistId/GistID/g; s/GhsaId/GhsaID/g'"$file"
56+
sed -i's/WorkflowId/WorkflowID/g; s/RunId/RunID/g; s/JobId/JobID/g'"$file"
57+
58+
# Replace empty mocks
59+
sed -i's/mock\.NewMockedHTTPClient()/MockHTTPClientWithHandlers(map[string]http.HandlerFunc{})/g'"$file"
60+
61+
echo" Basic patterns applied. Manual review needed for:"
62+
echo" - mock.WithRequestMatch patterns"
63+
echo" - mock.WithRequestMatchHandler patterns"
64+
echo" - Closing braces for maps"
65+
}
66+
67+
# Migrate each file
68+
forfin"${FILES[@]}";do
69+
migrate_file"$f"
70+
done
71+
72+
echo""
73+
echo"=== Migration Step 1 Complete ==="
74+
echo""
75+
echo"NEXT STEPS (Manual):"
76+
echo"1. For each file, replace mock.NewMockedHTTPClient patterns:"
77+
echo" - Find: mock.NewMockedHTTPClient(mock.WithRequestMatch(mock.GetX, data),)"
78+
echo" - Replace with: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{GetX: mockResponse(t, http.StatusOK, data),})"
79+
echo""
80+
echo"2. For mock.WithRequestMatchHandler patterns:"
81+
echo" - Find: mock.NewMockedHTTPClient(mock.WithRequestMatchHandler(mock.GetX, handler),)"
82+
echo" - Replace with: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{GetX: handler,})"
83+
echo""
84+
echo"3. Test each file: go test ./pkg/github -run TestName -v"
85+
echo""
86+
echo"4. When all files pass tests:"
87+
echo" - Remove: go.mod entry for migueleliasweb/go-github-mock"
88+
echo" - Remove: pkg/raw/raw_mock.go"
89+
echo" - Run: go mod tidy"
90+
echo" - Run: script/licenses"
91+
echo" - Run: script/test"
92+
echo" - Run: script/lint"
93+
echo""
94+
echo"Backups saved as *.backup in case you need to revert."

‎pkg/github/gists_test.go‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ func Test_ListGists(t *testing.T) {
128128
name:"list gists fails with error",
129129
mockedClient:MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
130130
GetGists:http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
131-
w.WriteHeader(http.StatusUnauthorized)
132-
_,_=w.Write([]byte(`{"message": "Requires authentication"}`))
133-
}),
131+
w.WriteHeader(http.StatusUnauthorized)
132+
_,_=w.Write([]byte(`{"message": "Requires authentication"}`))
133+
}),
134134
}),
135135
requestArgs:map[string]interface{}{},
136136
expectError:true,
@@ -239,9 +239,9 @@ func Test_GetGist(t *testing.T) {
239239
name:"gist_id parameter missing",
240240
mockedClient:MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
241241
GetGistsByGistID:http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
242-
w.WriteHeader(http.StatusUnprocessableEntity)
243-
_,_=w.Write([]byte(`{"message": "Invalid Request"}`))
244-
}),
242+
w.WriteHeader(http.StatusUnprocessableEntity)
243+
_,_=w.Write([]byte(`{"message": "Invalid Request"}`))
244+
}),
245245
}),
246246
requestArgs:map[string]interface{}{},
247247
expectError:true,
@@ -375,9 +375,9 @@ func Test_CreateGist(t *testing.T) {
375375
name:"api returns error",
376376
mockedClient:MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
377377
PostGists:http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
378-
w.WriteHeader(http.StatusUnauthorized)
379-
_,_=w.Write([]byte(`{"message": "Requires authentication"}`))
380-
}),
378+
w.WriteHeader(http.StatusUnauthorized)
379+
_,_=w.Write([]byte(`{"message": "Requires authentication"}`))
380+
}),
381381
}),
382382
requestArgs:map[string]interface{}{
383383
"filename":"test.go",
@@ -527,9 +527,9 @@ func Test_UpdateGist(t *testing.T) {
527527
name:"api returns error",
528528
mockedClient:MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
529529
PatchGistsByGistID:http.HandlerFunc(func(w http.ResponseWriter,_*http.Request) {
530-
w.WriteHeader(http.StatusNotFound)
531-
_,_=w.Write([]byte(`{"message": "Not Found"}`))
532-
}),
530+
w.WriteHeader(http.StatusNotFound)
531+
_,_=w.Write([]byte(`{"message": "Not Found"}`))
532+
}),
533533
}),
534534
requestArgs:map[string]interface{}{
535535
"gist_id":"nonexistent-gist-id",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp