fix(接口测试): 支持接口定义和用例添加步骤时继承当前请求的环境和数据源
This commit is contained in:
parent
63dc1ec502
commit
2e3705f6af
|
@ -100,11 +100,12 @@ export default {
|
||||||
api: {},
|
api: {},
|
||||||
envMap: new Map,
|
envMap: new Map,
|
||||||
maintainerOptions: [],
|
maintainerOptions: [],
|
||||||
|
environments: []
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
'$store.state.useEnvironment': function () {
|
'$store.state.useEnvironment': function () {
|
||||||
this.environment = this.$store.state.useEnvironment;
|
this.setEnvironment(this.$store.state.useEnvironment);
|
||||||
},
|
},
|
||||||
refreshSign() {
|
refreshSign() {
|
||||||
this.api = this.currentApi;
|
this.api = this.currentApi;
|
||||||
|
@ -289,13 +290,43 @@ export default {
|
||||||
refreshModule() {
|
refreshModule() {
|
||||||
this.$emit('refreshModule');
|
this.$emit('refreshModule');
|
||||||
},
|
},
|
||||||
setEnvironments(obj) {
|
setNewSource(environment, obj) {
|
||||||
this.$get('/api/environment/list/' + this.projectId, response => {
|
if (environment.config && environment.config.databaseConfigs) {
|
||||||
let environments = response.data;
|
let dataSources = environment.config.databaseConfigs.filter(item => item.name === obj.targetDataSourceName);
|
||||||
this.getTargetSource(environments, obj);
|
if (dataSources && dataSources.length > 0) {
|
||||||
});
|
obj.dataSourceId = dataSources[0].id;
|
||||||
|
} else {
|
||||||
|
obj.dataSourceId = environment.config.databaseConfigs[0].id;
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
getTargetSource(environments, obj) {
|
getEnvironments(obj, env) {
|
||||||
|
if (this.environments.length === 0) {
|
||||||
|
this.$get('/api/environment/list/' + this.projectId, response => {
|
||||||
|
this.environments = response.data;
|
||||||
|
// 获取原数据源名称
|
||||||
|
this.getTargetSourceName(this.environments, obj);
|
||||||
|
// 设置新环境
|
||||||
|
obj.environmentId = env;
|
||||||
|
// 设置新数据源
|
||||||
|
let envs = this.environments.filter(tab => tab.id === env);
|
||||||
|
if (envs && envs.length > 0) {
|
||||||
|
this.setNewSource(envs[0], obj);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 获取原数据源名称
|
||||||
|
this.getTargetSourceName(this.environments, obj);
|
||||||
|
// 设置新环境
|
||||||
|
obj.environmentId = env;
|
||||||
|
// 设置新数据源
|
||||||
|
let envs = this.environments.filter(tab => tab.id === env);
|
||||||
|
if (envs && envs.length > 0) {
|
||||||
|
this.setNewSource(envs[0], obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getTargetSourceName(environments, obj) {
|
||||||
environments.forEach(environment => {
|
environments.forEach(environment => {
|
||||||
parseEnvironment(environment);
|
parseEnvironment(environment);
|
||||||
// 找到原始环境和数据源名称
|
// 找到原始环境和数据源名称
|
||||||
|
@ -314,8 +345,7 @@ export default {
|
||||||
for (let i in scenarioDefinition) {
|
for (let i in scenarioDefinition) {
|
||||||
let typeArray = ["JDBCPostProcessor", "JDBCSampler", "JDBCPreProcessor"]
|
let typeArray = ["JDBCPostProcessor", "JDBCSampler", "JDBCPreProcessor"]
|
||||||
if (typeArray.indexOf(scenarioDefinition[i].type) !== -1) {
|
if (typeArray.indexOf(scenarioDefinition[i].type) !== -1) {
|
||||||
this.setEnvironments(scenarioDefinition[i]);
|
this.getEnvironments(scenarioDefinition[i], env);
|
||||||
scenarioDefinition[i].environmentId = env;
|
|
||||||
}
|
}
|
||||||
if (scenarioDefinition[i].hashTree !== undefined && scenarioDefinition[i].hashTree.length > 0) {
|
if (scenarioDefinition[i].hashTree !== undefined && scenarioDefinition[i].hashTree.length > 0) {
|
||||||
this.setOwnEnvironment(scenarioDefinition[i].hashTree, env);
|
this.setOwnEnvironment(scenarioDefinition[i].hashTree, env);
|
||||||
|
|
|
@ -249,9 +249,22 @@ export default {
|
||||||
} else {
|
} else {
|
||||||
this.addAssertions();
|
this.addAssertions();
|
||||||
}
|
}
|
||||||
|
// 继承请求中的环境和数据源
|
||||||
|
if (this.request.hashTree && this.request.hashTree.length > 0) {
|
||||||
|
this.setOwnEnvironment(this.request.hashTree);
|
||||||
|
}
|
||||||
this.sort();
|
this.sort();
|
||||||
this.reload();
|
this.reload();
|
||||||
},
|
},
|
||||||
|
setOwnEnvironment(scenarioDefinition) {
|
||||||
|
for (let i in scenarioDefinition) {
|
||||||
|
let typeArray = ["JDBCPostProcessor", "JDBCSampler", "JDBCPreProcessor"]
|
||||||
|
if (typeArray.indexOf(scenarioDefinition[i].type) !== -1) {
|
||||||
|
scenarioDefinition[i].environmentId = this.request.environmentId;
|
||||||
|
scenarioDefinition[i].dataSourceId = this.request.dataSourceId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
filterNode(value, data) {
|
filterNode(value, data) {
|
||||||
if (data.type && value.indexOf(data.type) !== -1) {
|
if (data.type && value.indexOf(data.type) !== -1) {
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue