Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions console/atest-ui/src/views/DataManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const loadingStores = ref(true)

const tablesTree = ref([])
watch(store, (s) => {
kind.value = ''
stores.value.forEach((e: Store) => {
if (e.name === s) {
kind.value = e.kind.name
Expand All @@ -39,6 +40,7 @@ watch(kind, (k) => {
switch (k) {
case 'atest-store-orm':
queryTip.value = 'Enter SQL query'
executeQuery()
break;
case 'atest-store-etcd':
case 'atest-store-redis':
Expand Down
17 changes: 17 additions & 0 deletions docs/site/content/zh/latest/tasks/mock/simple.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,20 @@ items:
proxies:
- path: /api/v1/{part}
target: http://atest.localhost:8080
- path: /open-apis/bot/v2/hook/{token}
target: https://open.feishu.cn/
requestAmend:
bodyPatch: |
[{
"op": "add",
"path": "/msg_type",
"value": "text"
}, {
"op": "add",
"path": "/content",
"value": {}
}, {
"op": "move",
"from": "/text",
"path": "/content/text"
}]
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ require (

require golang.org/x/mod v0.22.0

require github.com/evanphx/json-patch v0.5.2 // indirect

require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ github.com/cucumber/messages-go/v16 v16.0.1/go.mod h1:EJcyR5Mm5ZuDsKJnT2N9KRnBK3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/evanphx/json-patch v0.5.2 h1:xVCHIVMUu1wtM/VkR9jVZ45N3FhZfYMMYGorLCR8P3k=
github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMikGIFbs31qQ=
github.com/expr-lang/expr v1.15.6 h1:dQFgzj5DBu3wnUz8+PGLZdPMpefAvxaCFTNM3iSjkGA=
github.com/expr-lang/expr v1.15.6/go.mod h1:uCkhfG+x7fcZ5A5sXHKuQ07jGZRl6J0FCAaf2k4PtVQ=
github.com/flopp/go-findfont v0.1.0 h1:lPn0BymDUtJo+ZkV01VS3661HL6F4qFlkhcJN55u6mU=
Expand Down Expand Up @@ -98,6 +100,7 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/invopop/jsonschema v0.7.0 h1:2vgQcBz1n256N+FpX3Jq7Y17AjYt46Ig3zIWyy770So=
github.com/invopop/jsonschema v0.7.0/go.mod h1:O9uiLokuu0+MGFlyiaqtWxwqJm41/+8Nj0lD7A36YH0=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jhump/protoreflect v1.15.3 h1:6SFRuqU45u9hIZPJAoZ8c28T3nK64BNdp9w6jFonzls=
github.com/jhump/protoreflect v1.15.3/go.mod h1:4ORHmSBmlCW8fh3xHmJMGyul1zNqZK4Elxc8qKP+p1k=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
Expand Down
23 changes: 22 additions & 1 deletion pkg/mock/in_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"sync"
"time"

jsonpatch "github.com/evanphx/json-patch"
"github.com/swaggest/openapi-go/openapi3"
"github.com/swaggest/rest/gorillamux"

Expand Down Expand Up @@ -120,7 +121,26 @@ func (s *inMemoryServer) Load() (err error) {
}
memLogger.Info("redirect to", "target", api)

targetReq, err := http.NewRequestWithContext(req.Context(), req.Method, api, req.Body)
var requestBody []byte
if requestBody, err = io.ReadAll(req.Body); err != nil {
w.WriteHeader(http.StatusInternalServerError)
}

if proxy.RequestAmend.BodyPatch != "" && len(requestBody) > 0 {
var patch jsonpatch.Patch
if patch, err = jsonpatch.DecodePatch([]byte(proxy.RequestAmend.BodyPatch)); err != nil {
return
}

fmt.Println("before patch:", string(requestBody))
if requestBody, err = patch.Apply(requestBody); err != nil {
fmt.Println(err)
return
}
fmt.Println("after patch:", string(requestBody))
}

targetReq, err := http.NewRequestWithContext(req.Context(), req.Method, api, bytes.NewBuffer(requestBody))
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
memLogger.Error(err, "failed to create proxy request")
Expand All @@ -140,6 +160,7 @@ func (s *inMemoryServer) Load() (err error) {
memLogger.Error(err, "failed to read response body")
return
}
fmt.Println("received:", string(data))

for k, v := range resp.Header {
w.Header().Add(k, v[0])
Expand Down
63 changes: 34 additions & 29 deletions pkg/mock/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,54 +16,59 @@ limitations under the License.
package mock

type Object struct {
Name string `yaml:"name" json:"name"`
InitCount *int `yaml:"initCount" json:"initCount"`
Sample string `yaml:"sample" json:"sample"`
Name string `yaml:"name" json:"name"`
InitCount *int `yaml:"initCount" json:"initCount"`
Sample string `yaml:"sample" json:"sample"`
}

type Item struct {
Name string `yaml:"name" json:"name"`
Request Request `yaml:"request" json:"request"`
Response Response `yaml:"response" json:"response"`
Param map[string]string
Name string `yaml:"name" json:"name"`
Request Request `yaml:"request" json:"request"`
Response Response `yaml:"response" json:"response"`
Param map[string]string
}

type Request struct {
Path string `yaml:"path" json:"path"`
Method string `yaml:"method" json:"method"`
Header map[string]string `yaml:"header" json:"header"`
Body string `yaml:"body" json:"body"`
Path string `yaml:"path" json:"path"`
Method string `yaml:"method" json:"method"`
Header map[string]string `yaml:"header" json:"header"`
Body string `yaml:"body" json:"body"`
}

type RequestWithAuth struct {
Request `yaml:",inline"`
BearerAPI string `yaml:"bearerAPI" json:"bearerAPI"`
Username string `yaml:"username" json:"username"`
Password string `yaml:"password" json:"password"`
Request `yaml:",inline"`
BearerAPI string `yaml:"bearerAPI" json:"bearerAPI"`
Username string `yaml:"username" json:"username"`
Password string `yaml:"password" json:"password"`
}

type Response struct {
Encoder string `yaml:"encoder" json:"encoder"`
Body string `yaml:"body" json:"body"`
Header map[string]string `yaml:"header" json:"header"`
StatusCode int `yaml:"statusCode" json:"statusCode"`
BodyData []byte
Encoder string `yaml:"encoder" json:"encoder"`
Body string `yaml:"body" json:"body"`
Header map[string]string `yaml:"header" json:"header"`
StatusCode int `yaml:"statusCode" json:"statusCode"`
BodyData []byte
}

type Webhook struct {
Name string `yaml:"name" json:"name"`
Timer string `yaml:"timer" json:"timer"`
Request RequestWithAuth `yaml:"request" json:"request"`
Name string `yaml:"name" json:"name"`
Timer string `yaml:"timer" json:"timer"`
Request RequestWithAuth `yaml:"request" json:"request"`
}

type Proxy struct {
Path string `yaml:"path" json:"path"`
Target string `yaml:"target" json:"target"`
Path string `yaml:"path" json:"path"`
Target string `yaml:"target" json:"target"`
RequestAmend RequestAmend `yaml:"requestAmend" json:"requestAmend"`
}

type RequestAmend struct {
BodyPatch string `yaml:"bodyPatch" json:"bodyPatch"`
}

type Server struct {
Objects []Object `yaml:"objects" json:"objects"`
Items []Item `yaml:"items" json:"items"`
Proxies []Proxy `yaml:"proxies" json:"proxies"`
Webhooks []Webhook `yaml:"webhooks" json:"webhooks"`
Objects []Object `yaml:"objects" json:"objects"`
Items []Item `yaml:"items" json:"items"`
Proxies []Proxy `yaml:"proxies" json:"proxies"`
Webhooks []Webhook `yaml:"webhooks" json:"webhooks"`
}
Loading