@@ -15,39 +15,6 @@ import (
1515 "github.com/stretchr/testify/require"
1616)
1717
18- var mockCommits = []* github.RepositoryCommit {
19- {
20- SHA : github .Ptr ("abc123def456" ),
21- Commit : & github.Commit {
22- Message : github .Ptr ("First commit" ),
23- Author : & github.CommitAuthor {
24- Name : github .Ptr ("Test User" ),
25- Email :
github .
Ptr (
"[email protected] " ),
26- Date : & github.Timestamp {Time : time .Now ().Add (- 48 * time .Hour )},
27- },
28- },
29- Author : & github.User {
30- Login : github .Ptr ("testuser" ),
31- },
32- HTMLURL : github .Ptr ("https://github.com/owner/repo/commit/abc123def456" ),
33- },
34- {
35- SHA : github .Ptr ("def456abc789" ),
36- Commit : & github.Commit {
37- Message : github .Ptr ("Second commit" ),
38- Author : & github.CommitAuthor {
39- Name : github .Ptr ("Another User" ),
40- Email :
github .
Ptr (
"[email protected] " ),
41- Date : & github.Timestamp {Time : time .Now ().Add (- 24 * time .Hour )},
42- },
43- },
44- Author : & github.User {
45- Login : github .Ptr ("anotheruser" ),
46- },
47- HTMLURL : github .Ptr ("https://github.com/owner/repo/commit/def456abc789" ),
48- },
49- }
50-
5118func Test_GetFileContents (t * testing.T ) {
5219 // Verify tool definition once
5320 mockClient := github .NewClient (nil )
@@ -520,7 +487,36 @@ func Test_GetCommit(t *testing.T) {
520487 assert .Contains (t , tool .InputSchema .Properties , "sha" )
521488 assert .ElementsMatch (t , tool .InputSchema .Required , []string {"owner" , "repo" , "sha" })
522489
523- mockCommit := mockCommits [0 ]
490+ mockCommit := & github.RepositoryCommit {
491+ SHA : github .Ptr ("abc123def456" ),
492+ Commit : & github.Commit {
493+ Message : github .Ptr ("First commit" ),
494+ Author : & github.CommitAuthor {
495+ Name : github .Ptr ("Test User" ),
496+ Email :
github .
Ptr (
"[email protected] " ),
497+ Date : & github.Timestamp {Time : time .Now ().Add (- 48 * time .Hour )},
498+ },
499+ },
500+ Author : & github.User {
501+ Login : github .Ptr ("testuser" ),
502+ },
503+ HTMLURL : github .Ptr ("https://github.com/owner/repo/commit/abc123def456" ),
504+ Stats : & github.CommitStats {
505+ Additions : github .Ptr (10 ),
506+ Deletions : github .Ptr (2 ),
507+ Total : github .Ptr (12 ),
508+ },
509+ Files : []* github.CommitFile {
510+ {
511+ Filename : github .Ptr ("file1.go" ),
512+ Status : github .Ptr ("modified" ),
513+ Additions : github .Ptr (10 ),
514+ Deletions : github .Ptr (2 ),
515+ Changes : github .Ptr (12 ),
516+ Patch : github .Ptr ("@@ -1,2 +1,10 @@" ),
517+ },
518+ },
519+ }
524520 // This one currently isn't defined in the mock package we're using.
525521 var mockEndpointPattern = mock.EndpointPattern {
526522 Pattern : "/repos/{owner}/{repo}/commits/{sha}" ,
@@ -600,7 +596,7 @@ func Test_GetCommit(t *testing.T) {
600596 var returnedCommit github.RepositoryCommit
601597 err = json .Unmarshal ([]byte (textContent .Text ), & returnedCommit )
602598 require .NoError (t , err )
603-
599+
604600 assert .Equal (t , * tc .expectedCommit .SHA , * returnedCommit .SHA )
605601 assert .Equal (t , * tc .expectedCommit .Commit .Message , * returnedCommit .Commit .Message )
606602 assert .Equal (t , * tc .expectedCommit .Author .Login , * returnedCommit .Author .Login )
@@ -622,7 +618,41 @@ func Test_ListCommits(t *testing.T) {
622618 assert .Contains (t , tool .InputSchema .Properties , "page" )
623619 assert .Contains (t , tool .InputSchema .Properties , "perPage" )
624620 assert .ElementsMatch (t , tool .InputSchema .Required , []string {"owner" , "repo" })
625-
621+
622+ // Setup mock commits for success case
623+ mockCommits := []* github.RepositoryCommit {
624+ {
625+ SHA : github .Ptr ("abc123def456" ),
626+ Commit : & github.Commit {
627+ Message : github .Ptr ("First commit" ),
628+ Author : & github.CommitAuthor {
629+ Name : github .Ptr ("Test User" ),
630+ Email :
github .
Ptr (
"[email protected] " ),
631+ Date : & github.Timestamp {Time : time .Now ().Add (- 48 * time .Hour )},
632+ },
633+ },
634+ Author : & github.User {
635+ Login : github .Ptr ("testuser" ),
636+ },
637+ HTMLURL : github .Ptr ("https://github.com/owner/repo/commit/abc123def456" ),
638+ },
639+ {
640+ SHA : github .Ptr ("def456abc789" ),
641+ Commit : & github.Commit {
642+ Message : github .Ptr ("Second commit" ),
643+ Author : & github.CommitAuthor {
644+ Name : github .Ptr ("Another User" ),
645+ Email :
github .
Ptr (
"[email protected] " ),
646+ Date : & github.Timestamp {Time : time .Now ().Add (- 24 * time .Hour )},
647+ },
648+ },
649+ Author : & github.User {
650+ Login : github .Ptr ("anotheruser" ),
651+ },
652+ HTMLURL : github .Ptr ("https://github.com/owner/repo/commit/def456abc789" ),
653+ },
654+ }
655+
626656 tests := []struct {
627657 name string
628658 mockedClient * http.Client
0 commit comments