39 lines
1,019 B
Go
39 lines
1,019 B
Go
package testutils
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"path/filepath"
|
|
"regexp"
|
|
"runtime"
|
|
"strings"
|
|
|
|
"github.com/jarcoal/httpmock"
|
|
)
|
|
|
|
func TestName() string {
|
|
pc, _, _, _ := runtime.Caller(1)
|
|
nameFull := runtime.FuncForPC(pc).Name()
|
|
nameEnd := filepath.Ext(nameFull)
|
|
name := strings.TrimPrefix(nameEnd, ".")
|
|
return name
|
|
}
|
|
|
|
func ActivateEnvironmentHttpMocks() {
|
|
httpmock.RegisterNoResponder(
|
|
func(req *http.Request) (*http.Response, error) {
|
|
return nil, fmt.Errorf("no responder found for %s %s, please check your http mocks", req.Method, req.URL)
|
|
},
|
|
)
|
|
|
|
httpmock.RegisterRegexpResponder(
|
|
"GET",
|
|
regexp.MustCompile(`^https://api\.bap\.microsoft\.com/providers/Microsoft\.BusinessAppPlatform/locations/(europe|unitedstates)/environmentLanguages\?api-version=2023-06-01$`),
|
|
func(_ *http.Request) (*http.Response, error) {
|
|
return httpmock.NewStringResponse(
|
|
http.StatusOK,
|
|
httpmock.File("../../services/languages/tests/datasource/Validate_Read/get_languages.json").String(),
|
|
), nil
|
|
},
|
|
)
|
|
}
|