@@ -15,39 +15,6 @@ import (
15
15
"github.com/stretchr/testify/require"
16
16
)
17
17
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 ("test@example.com" ),
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 ("another@example.com" ),
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
-
51
18
func Test_GetFileContents (t * testing.T ) {
52
19
// Verify tool definition once
53
20
mockClient := github .NewClient (nil )
@@ -520,7 +487,36 @@ func Test_GetCommit(t *testing.T) {
520
487
assert .Contains (t , tool .InputSchema .Properties , "sha" )
521
488
assert .ElementsMatch (t , tool .InputSchema .Required , []string {"owner" , "repo" , "sha" })
522
489
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 ("test@example.com" ),
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
+ }
524
520
// This one currently isn't defined in the mock package we're using.
525
521
var mockEndpointPattern = mock.EndpointPattern {
526
522
Pattern : "/repos/{owner}/{repo}/commits/{sha}" ,
@@ -600,7 +596,7 @@ func Test_GetCommit(t *testing.T) {
600
596
var returnedCommit github.RepositoryCommit
601
597
err = json .Unmarshal ([]byte (textContent .Text ), & returnedCommit )
602
598
require .NoError (t , err )
603
-
599
+
604
600
assert .Equal (t , * tc .expectedCommit .SHA , * returnedCommit .SHA )
605
601
assert .Equal (t , * tc .expectedCommit .Commit .Message , * returnedCommit .Commit .Message )
606
602
assert .Equal (t , * tc .expectedCommit .Author .Login , * returnedCommit .Author .Login )
@@ -622,7 +618,41 @@ func Test_ListCommits(t *testing.T) {
622
618
assert .Contains (t , tool .InputSchema .Properties , "page" )
623
619
assert .Contains (t , tool .InputSchema .Properties , "perPage" )
624
620
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 ("test@example.com" ),
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 ("another@example.com" ),
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
+
626
656
tests := []struct {
627
657
name string
628
658
mockedClient * http.Client
0 commit comments