@@ -70,9 +70,13 @@ func Test_GetFileContents(t *testing.T) {
70
70
{
71
71
name :"successful file content fetch" ,
72
72
mockedClient :mock .NewMockedHTTPClient (
73
- mock .WithRequestMatch (
73
+ mock .WithRequestMatchHandler (
74
74
mock .GetReposContentsByOwnerByRepoByPath ,
75
- mockFileContent ,
75
+ expectQueryParams (t ,map [string ]string {
76
+ "ref" :"main" ,
77
+ }).andThen (
78
+ mockResponse (t ,http .StatusOK ,mockFileContent ),
79
+ ),
76
80
),
77
81
),
78
82
requestArgs :map [string ]interface {}{
@@ -87,9 +91,11 @@ func Test_GetFileContents(t *testing.T) {
87
91
{
88
92
name :"successful directory content fetch" ,
89
93
mockedClient :mock .NewMockedHTTPClient (
90
- mock .WithRequestMatch (
94
+ mock .WithRequestMatchHandler (
91
95
mock .GetReposContentsByOwnerByRepoByPath ,
92
- mockDirContent ,
96
+ expectQueryParams (t ,map [string ]string {}).andThen (
97
+ mockResponse (t ,http .StatusOK ,mockDirContent ),
98
+ ),
93
99
),
94
100
),
95
101
requestArgs :map [string ]interface {}{
@@ -352,9 +358,14 @@ func Test_CreateBranch(t *testing.T) {
352
358
mock .GetReposGitRefByOwnerByRepoByRef ,
353
359
mockSourceRef ,
354
360
),
355
- mock .WithRequestMatch (
361
+ mock .WithRequestMatchHandler (
356
362
mock .PostReposGitRefsByOwnerByRepo ,
357
- mockCreatedRef ,
363
+ expectRequestBody (t ,map [string ]interface {}{
364
+ "ref" :"refs/heads/new-feature" ,
365
+ "sha" :"abc123def456" ,
366
+ }).andThen (
367
+ mockResponse (t ,http .StatusCreated ,mockCreatedRef ),
368
+ ),
358
369
),
359
370
),
360
371
requestArgs :map [string ]interface {}{
@@ -538,9 +549,15 @@ func Test_ListCommits(t *testing.T) {
538
549
{
539
550
name :"successful commits fetch with branch" ,
540
551
mockedClient :mock .NewMockedHTTPClient (
541
- mock .WithRequestMatch (
552
+ mock .WithRequestMatchHandler (
542
553
mock .GetReposCommitsByOwnerByRepo ,
543
- mockCommits ,
554
+ expectQueryParams (t ,map [string ]string {
555
+ "sha" :"main" ,
556
+ "page" :"1" ,
557
+ "per_page" :"30" ,
558
+ }).andThen (
559
+ mockResponse (t ,http .StatusOK ,mockCommits ),
560
+ ),
544
561
),
545
562
),
546
563
requestArgs :map [string ]interface {}{
@@ -554,9 +571,14 @@ func Test_ListCommits(t *testing.T) {
554
571
{
555
572
name :"successful commits fetch with pagination" ,
556
573
mockedClient :mock .NewMockedHTTPClient (
557
- mock .WithRequestMatch (
574
+ mock .WithRequestMatchHandler (
558
575
mock .GetReposCommitsByOwnerByRepo ,
559
- mockCommits ,
576
+ expectQueryParams (t ,map [string ]string {
577
+ "page" :"2" ,
578
+ "per_page" :"10" ,
579
+ }).andThen (
580
+ mockResponse (t ,http .StatusOK ,mockCommits ),
581
+ ),
560
582
),
561
583
),
562
584
requestArgs :map [string ]interface {}{
@@ -676,9 +698,15 @@ func Test_CreateOrUpdateFile(t *testing.T) {
676
698
{
677
699
name :"successful file creation" ,
678
700
mockedClient :mock .NewMockedHTTPClient (
679
- mock .WithRequestMatch (
701
+ mock .WithRequestMatchHandler (
680
702
mock .PutReposContentsByOwnerByRepoByPath ,
681
- mockFileResponse ,
703
+ expectRequestBody (t ,map [string ]interface {}{
704
+ "message" :"Add example file" ,
705
+ "content" :"IyBFeGFtcGxlCgpUaGlzIGlzIGFuIGV4YW1wbGUgZmlsZS4=" ,// Base64 encoded content
706
+ "branch" :"main" ,
707
+ }).andThen (
708
+ mockResponse (t ,http .StatusOK ,mockFileResponse ),
709
+ ),
682
710
),
683
711
),
684
712
requestArgs :map [string ]interface {}{
@@ -695,9 +723,16 @@ func Test_CreateOrUpdateFile(t *testing.T) {
695
723
{
696
724
name :"successful file update with SHA" ,
697
725
mockedClient :mock .NewMockedHTTPClient (
698
- mock .WithRequestMatch (
726
+ mock .WithRequestMatchHandler (
699
727
mock .PutReposContentsByOwnerByRepoByPath ,
700
- mockFileResponse ,
728
+ expectRequestBody (t ,map [string ]interface {}{
729
+ "message" :"Update example file" ,
730
+ "content" :"IyBVcGRhdGVkIEV4YW1wbGUKClRoaXMgZmlsZSBoYXMgYmVlbiB1cGRhdGVkLg==" ,// Base64 encoded content
731
+ "branch" :"main" ,
732
+ "sha" :"abc123def456" ,
733
+ }).andThen (
734
+ mockResponse (t ,http .StatusOK ,mockFileResponse ),
735
+ ),
701
736
),
702
737
),
703
738
requestArgs :map [string ]interface {}{
@@ -819,7 +854,14 @@ func Test_CreateRepository(t *testing.T) {
819
854
Pattern :"/user/repos" ,
820
855
Method :"POST" ,
821
856
},
822
- mockResponse (t ,http .StatusCreated ,mockRepo ),
857
+ expectRequestBody (t ,map [string ]interface {}{
858
+ "name" :"test-repo" ,
859
+ "description" :"Test repository" ,
860
+ "private" :true ,
861
+ "auto_init" :true ,
862
+ }).andThen (
863
+ mockResponse (t ,http .StatusCreated ,mockRepo ),
864
+ ),
823
865
),
824
866
),
825
867
requestArgs :map [string ]interface {}{
@@ -839,7 +881,14 @@ func Test_CreateRepository(t *testing.T) {
839
881
Pattern :"/user/repos" ,
840
882
Method :"POST" ,
841
883
},
842
- mockResponse (t ,http .StatusCreated ,mockRepo ),
884
+ expectRequestBody (t ,map [string ]interface {}{
885
+ "name" :"test-repo" ,
886
+ "auto_init" :false ,
887
+ "description" :"" ,
888
+ "private" :false ,
889
+ }).andThen (
890
+ mockResponse (t ,http .StatusCreated ,mockRepo ),
891
+ ),
843
892
),
844
893
),
845
894
requestArgs :map [string ]interface {}{
@@ -980,19 +1029,48 @@ func Test_PushFiles(t *testing.T) {
980
1029
mockCommit ,
981
1030
),
982
1031
// Create tree
983
- mock .WithRequestMatch (
1032
+ mock .WithRequestMatchHandler (
984
1033
mock .PostReposGitTreesByOwnerByRepo ,
985
- mockTree ,
1034
+ expectRequestBody (t ,map [string ]interface {}{
1035
+ "base_tree" :"def456" ,
1036
+ "tree" : []interface {}{
1037
+ map [string ]interface {}{
1038
+ "path" :"README.md" ,
1039
+ "mode" :"100644" ,
1040
+ "type" :"blob" ,
1041
+ "content" :"# Updated README\n \n This is an updated README file." ,
1042
+ },
1043
+ map [string ]interface {}{
1044
+ "path" :"docs/example.md" ,
1045
+ "mode" :"100644" ,
1046
+ "type" :"blob" ,
1047
+ "content" :"# Example\n \n This is an example file." ,
1048
+ },
1049
+ },
1050
+ }).andThen (
1051
+ mockResponse (t ,http .StatusCreated ,mockTree ),
1052
+ ),
986
1053
),
987
1054
// Create commit
988
- mock .WithRequestMatch (
1055
+ mock .WithRequestMatchHandler (
989
1056
mock .PostReposGitCommitsByOwnerByRepo ,
990
- mockNewCommit ,
1057
+ expectRequestBody (t ,map [string ]interface {}{
1058
+ "message" :"Update multiple files" ,
1059
+ "tree" :"ghi789" ,
1060
+ "parents" : []interface {}{"abc123" },
1061
+ }).andThen (
1062
+ mockResponse (t ,http .StatusCreated ,mockNewCommit ),
1063
+ ),
991
1064
),
992
1065
// Update reference
993
- mock .WithRequestMatch (
1066
+ mock .WithRequestMatchHandler (
994
1067
mock .PatchReposGitRefsByOwnerByRepoByRef ,
995
- mockUpdatedRef ,
1068
+ expectRequestBody (t ,map [string ]interface {}{
1069
+ "sha" :"jkl012" ,
1070
+ "force" :false ,
1071
+ }).andThen (
1072
+ mockResponse (t ,http .StatusOK ,mockUpdatedRef ),
1073
+ ),
996
1074
),
997
1075
),
998
1076
requestArgs :map [string ]interface {}{