@@ -6,6 +6,32 @@ import (
66 "github.com/ntsk/gh-issue-bulk-create/pkg/models"
77)
88
9+ // MockClient provides a mock GitHub client for testing
10+ type MockClient struct {
11+ CreateIssueFunc func (issue * models.Issue , repo string ) (* models.IssueResponse , error )
12+ GetCurrentRepoFunc func () (string , error )
13+ CreatedIssues []* models.Issue
14+ GetCurrentRepoCounter int
15+ }
16+
17+ // CreateIssue implements the ClientInterface for testing
18+ func (m * MockClient ) CreateIssue (issue * models.Issue , repo string ) (* models.IssueResponse , error ) {
19+ m .CreatedIssues = append (m .CreatedIssues , issue )
20+ if m .CreateIssueFunc != nil {
21+ return m .CreateIssueFunc (issue , repo )
22+ }
23+ return & models.IssueResponse {Number : 1 , URL : "https://github.com/mock/repo/issues/1" }, nil
24+ }
25+
26+ // GetCurrentRepository implements the ClientInterface for testing
27+ func (m * MockClient ) GetCurrentRepository () (string , error ) {
28+ m .GetCurrentRepoCounter ++
29+ if m .GetCurrentRepoFunc != nil {
30+ return m .GetCurrentRepoFunc ()
31+ }
32+ return "mock/repo" , nil
33+ }
34+
935func TestMockClient (t * testing.T ) {
1036 // Create mock client
1137 mockClient := & MockClient {}
@@ -70,3 +96,33 @@ func TestMockClient(t *testing.T) {
7096 t .Errorf ("Expected custom repo 'custom/repo', got '%s'" , repo )
7197 }
7298}
99+
100+ // TestClientInterface demonstrates that MockClient implements ClientInterface
101+ func TestClientInterface (t * testing.T ) {
102+ // Verify that MockClient implements the interface by using it
103+ var client ClientInterface = & MockClient {}
104+
105+ // Test that we can call interface methods
106+ issue := & models.Issue {
107+ Title : "Interface Test" ,
108+ Body : "Testing interface implementation" ,
109+ }
110+
111+ response , err := client .CreateIssue (issue , "test/repo" )
112+ if err != nil {
113+ t .Errorf ("Expected no error, got: %v" , err )
114+ }
115+
116+ if response .Number != 1 {
117+ t .Errorf ("Expected issue number 1, got %d" , response .Number )
118+ }
119+
120+ repo , err := client .GetCurrentRepository ()
121+ if err != nil {
122+ t .Errorf ("Expected no error, got: %v" , err )
123+ }
124+
125+ if repo != "mock/repo" {
126+ t .Errorf ("Expected repo 'mock/repo', got '%s'" , repo )
127+ }
128+ }
0 commit comments