Browse Source

TestingMockParams

Volodymyr Tkach 2 years ago
parent
commit
7b28b21457
1 changed files with 4 additions and 0 deletions
  1. 4 0
      utils/http/apiserv/apiserv.go

+ 4 - 0
utils/http/apiserv/apiserv.go

@@ -9,6 +9,7 @@ import (
 )
 )
 
 
 var mParam = regexp.MustCompile(`\{([^/]*)}`)
 var mParam = regexp.MustCompile(`\{([^/]*)}`)
+var TestingMockParams func() []Param = nil
 
 
 var mParams = &Params{
 var mParams = &Params{
 	list: map[*http.Request][]Param{},
 	list: map[*http.Request][]Param{},
@@ -28,6 +29,9 @@ func NewServeMux() *ServeMux {
 }
 }
 
 
 func GetParams(r *http.Request) []Param {
 func GetParams(r *http.Request) []Param {
+	if TestingMockParams != nil {
+		return TestingMockParams()
+	}
 	mParams.Lock()
 	mParams.Lock()
 	defer mParams.Unlock()
 	defer mParams.Unlock()
 	if v, ok := mParams.list[r]; ok {
 	if v, ok := mParams.list[r]; ok {