@@ -12,19 +12,20 @@ import (
12
12
type EndpointPattern = * regexp.Regexp
13
13
14
14
// Users
15
- var UsersGetEndpoint EndpointPattern = regexp .MustCompile (`^/users/[a-z ]+` )
15
+ var UsersGetEndpoint EndpointPattern = regexp .MustCompile (`^\ /users\ /[a-zA-Z ]+` )
16
16
17
17
// Orgs
18
18
var OrgsListEndpoint = regexp .MustCompile (`^\/users\/([a-z]+\/orgs|orgs)$` )
19
- var OrgsGetEndpoint = regexp .MustCompile (`^/orgs/[a-z]+` )
19
+ var OrgsGetEndpoint = regexp .MustCompile (`^\ /orgs\ /[a-z]+` )
20
20
21
21
type RequestMatch struct {
22
22
EndpointPattern EndpointPattern
23
23
Method string // GET or POST
24
24
}
25
25
26
26
func (rm * RequestMatch ) Match (r * http.Request ) bool {
27
- if r .Method == rm .Method && rm .EndpointPattern .MatchString (r .URL .Path ) {
27
+ if (r .Method == rm .Method ) &&
28
+ r .URL .Path == rm .EndpointPattern .FindString (r .URL .Path ) {
28
29
return true
29
30
}
30
31
@@ -49,6 +50,35 @@ type MockRoundTripper struct {
49
50
func (mrt * MockRoundTripper ) RoundTrip (r * http.Request ) (* http.Response , error ) {
50
51
for requestMatch , respBodies := range mrt .RequestMocks {
51
52
if requestMatch .Match (r ) {
53
+ if len (respBodies ) == 0 {
54
+ fmt .Printf (
55
+ "no more available mocked responses for endpoit %s\n " ,
56
+ r .URL .Path ,
57
+ )
58
+
59
+ fmt .Println ("please add the required RequestMatch to the MockHttpClient. Eg." )
60
+ fmt .Println (`
61
+ mockedHttpClient := NewMockHttpClient(
62
+ WithRequestMatch(
63
+ RequestMatchUsersGet,
64
+ MustMarshall(github.User{
65
+ Name: github.String("foobar"),
66
+ }),
67
+ ),
68
+ WithRequestMatch(
69
+ RequestMatchOrganizationsList,
70
+ MustMarshall([]github.Organization{
71
+ {
72
+ Name: github.String("foobar123"),
73
+ },
74
+ }),
75
+ ),
76
+ )
77
+ ` )
78
+
79
+ panic (nil )
80
+ }
81
+
52
82
resp := respBodies [0 ]
53
83
54
84
defer func (mrt * MockRoundTripper , rm RequestMatch ) {
0 commit comments