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
1 change: 1 addition & 0 deletions console/atest-ui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"functionQuery": "Functions Query",
"output": "Output",
"proxy": "Proxy",
"logs": "Logs",
"secure": "Secure",
"data": "Data",
"setting": "Setting",
Expand Down
1 change: 1 addition & 0 deletions console/atest-ui/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"history": "测试历史",
"mock": "模拟",
"welcome": "欢迎",
"logs": "日志",
"secrets": "凭据",
"stores": "存储",
"parameter": "参数",
Expand Down
49 changes: 28 additions & 21 deletions console/atest-ui/src/views/MockManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ API.GetStream((stream) => {
try {
const data = JSON.parse(stream);
logOutput.value += `${data.result.message}`;
console.log('Received schema:', logOutput.value);
} catch (e) {}
});

Expand Down Expand Up @@ -105,26 +104,30 @@ items:
API Prefix:<EditButton :value="mockConfig.Prefix" @changed="prefixChanged"/>
Port:<EditButton :value="mockConfig.Port" @changed="portChanged"/>
</div>
<div>
<el-tabs v-model="tabActive">
<el-tab-pane label="YAML" name="yaml">
<Codemirror v-model="mockConfig.Config"
:extensions="[jsonComplete, headerComplete]" />
</el-tab-pane>
<el-tab-pane label="JSON" name="json">
<Codemirror v-model="mockConfig.ConfigAsJSON"
:extensions="[jsonSchema(mockschema), jsonComplete, headerComplete]" />
</el-tab-pane>
</el-tabs>
<el-card class="log-output" shadow="hover">
<template #header>
<span>{{ t('label.logs') }}</span>
</template>
<el-scrollbar height="200px" ref="logScrollbar">
<pre style="white-space: pre-wrap; word-break: break-all;">{{ logOutput }}</pre>
</el-scrollbar>
</el-card>
</div>
<el-splitter layout="vertical" style="height: calc(100vh - 100px);">
<el-splitter-panel size="70%">
<el-tabs v-model="tabActive">
<el-tab-pane label="YAML" name="yaml">
<Codemirror v-model="mockConfig.Config"
:extensions="[jsonComplete, headerComplete]" />
</el-tab-pane>
<el-tab-pane label="JSON" name="json">
<Codemirror v-model="mockConfig.ConfigAsJSON"
:extensions="[jsonSchema(mockschema), jsonComplete, headerComplete]" />
</el-tab-pane>
</el-tabs>
</el-splitter-panel>
<el-splitter-panel size="30%">
<el-card class="log-output" shadow="hover">
<template #header>
<span>{{ t('title.logs') }}</span>
</template>
<el-scrollbar ref="logScrollbar">
<pre style="white-space: pre-wrap; word-break: break-all;">{{ logOutput }}</pre>
</el-scrollbar>
</el-card>
</el-splitter-panel>
</el-splitter>
</template>

<style>
Expand All @@ -134,4 +137,8 @@ items:
align-items: center;
gap: 8px;
}
.log-output {
height: 100%;
overflow: auto;
}
</style>
270 changes: 185 additions & 85 deletions docs/api-testing-mock-schema.json
Original file line number Diff line number Diff line change
@@ -1,94 +1,194 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Mock Server Schema",
"type": "object",
"properties": {
"objects": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"initCount": {"type": "integer"},
"sample": {"type": "string"}
},
"required": ["name"]
}
},
"items": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"request": {
"type": "object",
"properties": {
"path": {"type": "string"},
"method": {"type": "string"},
"header": {
"type": "object",
"additionalProperties": {"type": "string"}
},
"body": {"type": "string"}
},
"required": ["path"]
},
"response": {
"type": "object",
"properties": {
"encoder": {"type": "string"},
"body": {"type": "string"},
"header": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Mock Server Schema",
"type": "object",
"properties": {
"objects": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {"type": "string"}
},
"statusCode": {"type": "integer"},
"bodyData": {"type": "string", "contentEncoding": "base64"}
"properties": {
"name": {
"type": "string"
},
"initCount": {
"type": "integer"
},
"sample": {
"type": "string"
}
},
"required": [
"name"
]
}
},
"param": {
"type": "object",
"additionalProperties": {"type": "string"}
}
},
"required": ["name", "request", "response"]
}
},
"proxies": {
"type": "array",
"items": {
"type": "object",
"properties": {
"path": {"type": "string"},
"target": {"type": "string"}
"items": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1
},
"request": {
"type": "object",
"properties": {
"path": {
"type": "string",
"minLength": 1
},
"method": {
"type": "string"
},
"header": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"body": {
"type": "string"
}
},
"required": [
"path"
]
},
"response": {
"type": "object",
"properties": {
"encoder": {
"type": "string"
},
"body": {
"type": "string"
},
"header": {
"type": "object",
"description": "HTTP response headers. Common headers include 'Content-Type', 'Cache-Control', 'Set-Cookie', etc.",
"properties": {
"Content-Type": {
"type": "string",
"description": "The MIME type of the response body"
},
"Cache-Control": {
"type": "string",
"description": "Directives for caching mechanisms in both requests and responses"
},
"Set-Cookie": {
"type": "string",
"description": "Used to send cookies from the server to the user agent"
}
},
"additionalProperties": {
"type": "string"
}
},
"statusCode": {
"type": "integer"
},
"bodyData": {
"type": "string",
"contentEncoding": "base64"
}
}
},
"param": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"required": [
"name",
"request",
"response"
]
}
},
"required": ["path", "target"]
}
},
"webhooks": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"timer": {"type": "string"},
"request": {
"type": "object",
"properties": {
"path": {"type": "string"},
"method": {"type": "string"},
"header": {
"proxies": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": {"type": "string"}
},
"body": {"type": "string"}
},
"required": ["path"]
}
"properties": {
"path": {
"type": "string"
},
"target": {
"type": "string"
}
},
"required": [
"path",
"target"
]
}
},
"required": ["name", "timer", "request"]
}
"webhooks": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1
},
"timer": {
"type": "string",
"pattern": "^[0-9].*"
},
"request": {
"type": "object",
"properties": {
"path": {
"type": "string"
},
"method": {
"type": "string"
},
"header": {
"type": "object",
"description": "HTTP request headers. Common headers include 'Content-Type', 'Authorization', 'Accept', 'User-Agent', etc.",
"properties": {
"Content-Type": {
"type": "string",
"description": "The MIME type of the request body"
},
"Authorization": {
"type": "string",
"description": "Authentication credentials for HTTP authentication"
},
"Accept": {
"type": "string",
"description": "Media types that are acceptable for the response"
},
"User-Agent": {
"type": "string",
"description": "Information about the user agent originating the request"
}
},
"additionalProperties": {
"type": "string"
}
},
"body": {
"type": "string"
}
},
"required": [
"path"
]
}
},
"required": [
"name",
"timer",
"request"
]
}
}
}
}
}
1 change: 1 addition & 0 deletions docs/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package docs
import (
_ "embed"
"fmt"

yamlconv "github.com/ghodss/yaml"
"github.com/xeipuuv/gojsonschema"
)
Expand Down
4 changes: 4 additions & 0 deletions pkg/server/remote_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,10 @@ func (s *mockServerController) GetConfig(ctx context.Context, in *Empty) (reply
return
}
func (s *mockServerController) LogWatch(e *Empty, logServer Mock_LogWatchServer) (err error) {
logServer.Send(&CommonResult{
Success: true,
Message: "Mock server log watch started\n",
})
for msg := range s.logData {
logServer.Send(&CommonResult{
Success: true,
Expand Down
Loading