Skip to content

Commit 490a735

Browse files
authored
chore: improve the mock log output (#782)
Co-authored-by: rick <[email protected]>
1 parent b10916f commit 490a735

File tree

6 files changed

+220
-106
lines changed

6 files changed

+220
-106
lines changed

console/atest-ui/src/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"functionQuery": "Functions Query",
5555
"output": "Output",
5656
"proxy": "Proxy",
57+
"logs": "Logs",
5758
"secure": "Secure",
5859
"data": "Data",
5960
"setting": "Setting",

console/atest-ui/src/locales/zh.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"history": "测试历史",
4545
"mock": "模拟",
4646
"welcome": "欢迎",
47+
"logs": "日志",
4748
"secrets": "凭据",
4849
"stores": "存储",
4950
"parameter": "参数",

console/atest-ui/src/views/MockManager.vue

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ API.GetStream((stream) => {
2626
try {
2727
const data = JSON.parse(stream);
2828
logOutput.value += `${data.result.message}`;
29-
console.log('Received schema:', logOutput.value);
3029
} catch (e) {}
3130
});
3231
@@ -105,26 +104,30 @@ items:
105104
API Prefix:<EditButton :value="mockConfig.Prefix" @changed="prefixChanged"/>
106105
Port:<EditButton :value="mockConfig.Port" @changed="portChanged"/>
107106
</div>
108-
<div>
109-
<el-tabs v-model="tabActive">
110-
<el-tab-pane label="YAML" name="yaml">
111-
<Codemirror v-model="mockConfig.Config"
112-
:extensions="[jsonComplete, headerComplete]" />
113-
</el-tab-pane>
114-
<el-tab-pane label="JSON" name="json">
115-
<Codemirror v-model="mockConfig.ConfigAsJSON"
116-
:extensions="[jsonSchema(mockschema), jsonComplete, headerComplete]" />
117-
</el-tab-pane>
118-
</el-tabs>
119-
<el-card class="log-output" shadow="hover">
120-
<template #header>
121-
<span>{{ t('label.logs') }}</span>
122-
</template>
123-
<el-scrollbar height="200px" ref="logScrollbar">
124-
<pre style="white-space: pre-wrap; word-break: break-all;">{{ logOutput }}</pre>
125-
</el-scrollbar>
126-
</el-card>
127-
</div>
107+
<el-splitter layout="vertical" style="height: calc(100vh - 100px);">
108+
<el-splitter-panel size="70%">
109+
<el-tabs v-model="tabActive">
110+
<el-tab-pane label="YAML" name="yaml">
111+
<Codemirror v-model="mockConfig.Config"
112+
:extensions="[jsonComplete, headerComplete]" />
113+
</el-tab-pane>
114+
<el-tab-pane label="JSON" name="json">
115+
<Codemirror v-model="mockConfig.ConfigAsJSON"
116+
:extensions="[jsonSchema(mockschema), jsonComplete, headerComplete]" />
117+
</el-tab-pane>
118+
</el-tabs>
119+
</el-splitter-panel>
120+
<el-splitter-panel size="30%">
121+
<el-card class="log-output" shadow="hover">
122+
<template #header>
123+
<span>{{ t('title.logs') }}</span>
124+
</template>
125+
<el-scrollbar ref="logScrollbar">
126+
<pre style="white-space: pre-wrap; word-break: break-all;">{{ logOutput }}</pre>
127+
</el-scrollbar>
128+
</el-card>
129+
</el-splitter-panel>
130+
</el-splitter>
128131
</template>
129132

130133
<style>
@@ -134,4 +137,8 @@ items:
134137
align-items: center;
135138
gap: 8px;
136139
}
140+
.log-output {
141+
height: 100%;
142+
overflow: auto;
143+
}
137144
</style>

docs/api-testing-mock-schema.json

Lines changed: 185 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,194 @@
11
{
2-
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"title": "Mock Server Schema",
4-
"type": "object",
5-
"properties": {
6-
"objects": {
7-
"type": "array",
8-
"items": {
9-
"type": "object",
10-
"properties": {
11-
"name": {"type": "string"},
12-
"initCount": {"type": "integer"},
13-
"sample": {"type": "string"}
14-
},
15-
"required": ["name"]
16-
}
17-
},
18-
"items": {
19-
"type": "array",
20-
"items": {
21-
"type": "object",
22-
"properties": {
23-
"name": {"type": "string"},
24-
"request": {
25-
"type": "object",
26-
"properties": {
27-
"path": {"type": "string"},
28-
"method": {"type": "string"},
29-
"header": {
30-
"type": "object",
31-
"additionalProperties": {"type": "string"}
32-
},
33-
"body": {"type": "string"}
34-
},
35-
"required": ["path"]
36-
},
37-
"response": {
38-
"type": "object",
39-
"properties": {
40-
"encoder": {"type": "string"},
41-
"body": {"type": "string"},
42-
"header": {
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"title": "Mock Server Schema",
4+
"type": "object",
5+
"properties": {
6+
"objects": {
7+
"type": "array",
8+
"items": {
439
"type": "object",
44-
"additionalProperties": {"type": "string"}
45-
},
46-
"statusCode": {"type": "integer"},
47-
"bodyData": {"type": "string", "contentEncoding": "base64"}
10+
"properties": {
11+
"name": {
12+
"type": "string"
13+
},
14+
"initCount": {
15+
"type": "integer"
16+
},
17+
"sample": {
18+
"type": "string"
19+
}
20+
},
21+
"required": [
22+
"name"
23+
]
4824
}
49-
},
50-
"param": {
51-
"type": "object",
52-
"additionalProperties": {"type": "string"}
53-
}
5425
},
55-
"required": ["name", "request", "response"]
56-
}
57-
},
58-
"proxies": {
59-
"type": "array",
60-
"items": {
61-
"type": "object",
62-
"properties": {
63-
"path": {"type": "string"},
64-
"target": {"type": "string"}
26+
"items": {
27+
"type": "array",
28+
"items": {
29+
"type": "object",
30+
"properties": {
31+
"name": {
32+
"type": "string",
33+
"minLength": 1
34+
},
35+
"request": {
36+
"type": "object",
37+
"properties": {
38+
"path": {
39+
"type": "string",
40+
"minLength": 1
41+
},
42+
"method": {
43+
"type": "string"
44+
},
45+
"header": {
46+
"type": "object",
47+
"additionalProperties": {
48+
"type": "string"
49+
}
50+
},
51+
"body": {
52+
"type": "string"
53+
}
54+
},
55+
"required": [
56+
"path"
57+
]
58+
},
59+
"response": {
60+
"type": "object",
61+
"properties": {
62+
"encoder": {
63+
"type": "string"
64+
},
65+
"body": {
66+
"type": "string"
67+
},
68+
"header": {
69+
"type": "object",
70+
"description": "HTTP response headers. Common headers include 'Content-Type', 'Cache-Control', 'Set-Cookie', etc.",
71+
"properties": {
72+
"Content-Type": {
73+
"type": "string",
74+
"description": "The MIME type of the response body"
75+
},
76+
"Cache-Control": {
77+
"type": "string",
78+
"description": "Directives for caching mechanisms in both requests and responses"
79+
},
80+
"Set-Cookie": {
81+
"type": "string",
82+
"description": "Used to send cookies from the server to the user agent"
83+
}
84+
},
85+
"additionalProperties": {
86+
"type": "string"
87+
}
88+
},
89+
"statusCode": {
90+
"type": "integer"
91+
},
92+
"bodyData": {
93+
"type": "string",
94+
"contentEncoding": "base64"
95+
}
96+
}
97+
},
98+
"param": {
99+
"type": "object",
100+
"additionalProperties": {
101+
"type": "string"
102+
}
103+
}
104+
},
105+
"required": [
106+
"name",
107+
"request",
108+
"response"
109+
]
110+
}
65111
},
66-
"required": ["path", "target"]
67-
}
68-
},
69-
"webhooks": {
70-
"type": "array",
71-
"items": {
72-
"type": "object",
73-
"properties": {
74-
"name": {"type": "string"},
75-
"timer": {"type": "string"},
76-
"request": {
77-
"type": "object",
78-
"properties": {
79-
"path": {"type": "string"},
80-
"method": {"type": "string"},
81-
"header": {
112+
"proxies": {
113+
"type": "array",
114+
"items": {
82115
"type": "object",
83-
"additionalProperties": {"type": "string"}
84-
},
85-
"body": {"type": "string"}
86-
},
87-
"required": ["path"]
88-
}
116+
"properties": {
117+
"path": {
118+
"type": "string"
119+
},
120+
"target": {
121+
"type": "string"
122+
}
123+
},
124+
"required": [
125+
"path",
126+
"target"
127+
]
128+
}
89129
},
90-
"required": ["name", "timer", "request"]
91-
}
130+
"webhooks": {
131+
"type": "array",
132+
"items": {
133+
"type": "object",
134+
"properties": {
135+
"name": {
136+
"type": "string",
137+
"minLength": 1
138+
},
139+
"timer": {
140+
"type": "string",
141+
"pattern": "^[0-9].*"
142+
},
143+
"request": {
144+
"type": "object",
145+
"properties": {
146+
"path": {
147+
"type": "string"
148+
},
149+
"method": {
150+
"type": "string"
151+
},
152+
"header": {
153+
"type": "object",
154+
"description": "HTTP request headers. Common headers include 'Content-Type', 'Authorization', 'Accept', 'User-Agent', etc.",
155+
"properties": {
156+
"Content-Type": {
157+
"type": "string",
158+
"description": "The MIME type of the request body"
159+
},
160+
"Authorization": {
161+
"type": "string",
162+
"description": "Authentication credentials for HTTP authentication"
163+
},
164+
"Accept": {
165+
"type": "string",
166+
"description": "Media types that are acceptable for the response"
167+
},
168+
"User-Agent": {
169+
"type": "string",
170+
"description": "Information about the user agent originating the request"
171+
}
172+
},
173+
"additionalProperties": {
174+
"type": "string"
175+
}
176+
},
177+
"body": {
178+
"type": "string"
179+
}
180+
},
181+
"required": [
182+
"path"
183+
]
184+
}
185+
},
186+
"required": [
187+
"name",
188+
"timer",
189+
"request"
190+
]
191+
}
192+
}
92193
}
93-
}
94194
}

docs/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package docs
1818
import (
1919
_ "embed"
2020
"fmt"
21+
2122
yamlconv "github.com/ghodss/yaml"
2223
"github.com/xeipuuv/gojsonschema"
2324
)

pkg/server/remote_server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,10 @@ func (s *mockServerController) GetConfig(ctx context.Context, in *Empty) (reply
14251425
return
14261426
}
14271427
func (s *mockServerController) LogWatch(e *Empty, logServer Mock_LogWatchServer) (err error) {
1428+
logServer.Send(&CommonResult{
1429+
Success: true,
1430+
Message: "Mock server log watch started\n",
1431+
})
14281432
for msg := range s.logData {
14291433
logServer.Send(&CommonResult{
14301434
Success: true,

0 commit comments

Comments
 (0)