fix(接口测试): 修复接口或用例同名数据源匹配错误问题
--bug=1012653 --user=赵勇 【接口测试】接口定义-接口case-添加前后置sql-切换运行环境-未使用同名的数据源 https://www.tapd.cn/55049933/s/1146978
This commit is contained in:
parent
26c47c15fa
commit
3edaefef08
|
@ -117,9 +117,6 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
if (!this.scenarioId) {
|
|
||||||
this.request.environmentId = this.$store.state.useEnvironment;
|
|
||||||
}
|
|
||||||
this.getEnvironments();
|
this.getEnvironments();
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -128,16 +125,23 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
// 场景环境监听
|
||||||
'$store.state.scenarioEnvMap': {
|
'$store.state.scenarioEnvMap': {
|
||||||
handler(v) {
|
handler(v) {
|
||||||
this.getEnvironments();
|
this.getEnvironments();
|
||||||
},
|
},
|
||||||
deep: true
|
deep: true
|
||||||
},
|
},
|
||||||
|
// 接口/用例 右上角公共环境监听
|
||||||
'$store.state.useEnvironment': function () {
|
'$store.state.useEnvironment': function () {
|
||||||
if (!this.scenarioId) {
|
if (!this.scenarioId) {
|
||||||
this.request.environmentId = this.$store.state.useEnvironment;
|
this.getEnvironments(this.$store.state.useEnvironment);
|
||||||
this.getEnvironments();
|
}
|
||||||
|
},
|
||||||
|
// 接口/用例 自身环境监听
|
||||||
|
'request.environmentId': function () {
|
||||||
|
if (!this.scenarioId) {
|
||||||
|
this.initDataSource(undefined, undefined, this.request.targetDataSourceName);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -173,29 +177,40 @@ export default {
|
||||||
runTest() {
|
runTest() {
|
||||||
|
|
||||||
},
|
},
|
||||||
itselfEnvironment() {
|
itselfEnvironment(environmentId) {
|
||||||
let id = this.request.projectId ? this.request.projectId : this.projectId;
|
let id = this.request.projectId ? this.request.projectId : this.projectId;
|
||||||
this.result = this.$get('/api/environment/list/' + id, response => {
|
this.result = this.$get('/api/environment/list/' + id, response => {
|
||||||
this.environments = response.data;
|
this.environments = response.data;
|
||||||
|
let targetDataSourceName = undefined;
|
||||||
this.environments.forEach(environment => {
|
this.environments.forEach(environment => {
|
||||||
parseEnvironment(environment);
|
parseEnvironment(environment);
|
||||||
|
// 找到原始环境和数据源名称
|
||||||
|
if (environment.id === this.request.environmentId) {
|
||||||
|
if (environment.config && environment.config.databaseConfigs) {
|
||||||
|
environment.config.databaseConfigs.forEach(item => {
|
||||||
|
if (item.id === this.request.dataSourceId) {
|
||||||
|
targetDataSourceName = item.name;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
this.initDataSource();
|
if (environmentId) {
|
||||||
|
this.request.environmentId = environmentId;
|
||||||
|
}
|
||||||
|
this.initDataSource(undefined, undefined, targetDataSourceName);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getEnvironments() {
|
getEnvironments(environmentId) {
|
||||||
let envId = "";
|
let envId = "";
|
||||||
let id = this.request.projectId ? this.request.projectId : this.projectId;
|
let id = this.request.projectId ? this.request.projectId : this.projectId;
|
||||||
let scenarioEnvId = this.scenarioId ? (this.scenarioId + "_" + id) : id;
|
let scenarioEnvId = this.scenarioId !== "" ? (this.scenarioId + "_" + id) : id;
|
||||||
if (this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map
|
if (this.$store.state.scenarioEnvMap && this.$store.state.scenarioEnvMap instanceof Map
|
||||||
&& this.$store.state.scenarioEnvMap.has(scenarioEnvId)) {
|
&& this.$store.state.scenarioEnvMap.has(scenarioEnvId)) {
|
||||||
envId = this.$store.state.scenarioEnvMap.get(scenarioEnvId);
|
envId = this.$store.state.scenarioEnvMap.get(scenarioEnvId);
|
||||||
}
|
}
|
||||||
if (this.request.referenced === 'Created' && this.scenarioId && !this.request.isRefEnvironment) {
|
if (!this.scenarioId && !this.request.customizeReq) {
|
||||||
this.itselfEnvironment();
|
this.itselfEnvironment(environmentId);
|
||||||
return;
|
|
||||||
} else if (!this.scenarioId && !this.request.customizeReq) {
|
|
||||||
this.itselfEnvironment();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.environments = [];
|
this.environments = [];
|
||||||
|
@ -292,7 +307,6 @@ export default {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.databaseConfigsOptions = [];
|
this.databaseConfigsOptions = [];
|
||||||
if (environment.config && environment.config.databaseConfigs) {
|
if (environment.config && environment.config.databaseConfigs) {
|
||||||
environment.config.databaseConfigs.forEach(item => {
|
environment.config.databaseConfigs.forEach(item => {
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
:project-id="projectId"
|
:project-id="projectId"
|
||||||
:is-read-only="isReadOnly"
|
:is-read-only="isReadOnly"
|
||||||
:useEnvironment='useEnvironment'
|
:useEnvironment='useEnvironment'
|
||||||
@setEnvironment="setEnvironment" ref="environmentSelect" v-if="api.protocol==='HTTP'"/>
|
@setEnvironment="setEnvironment" ref="environmentSelect" v-if="api.protocol==='HTTP' || api.protocol ==='TCP'"/>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="2">
|
<el-col :span="2">
|
||||||
<!-- 保存操作 -->
|
<!-- 保存操作 -->
|
||||||
|
@ -100,10 +100,9 @@ export default {
|
||||||
setEnvironment(data) {
|
setEnvironment(data) {
|
||||||
if (data) {
|
if (data) {
|
||||||
this.$emit('setEnvironment', data.id);
|
this.$emit('setEnvironment', data.id);
|
||||||
this.$store.state.scenarioEnvMap = new Map();
|
|
||||||
this.$store.state.scenarioEnvMap.set(getCurrentProjectID(), data.id);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
open() {
|
open() {
|
||||||
this.$refs.searchBar.open();
|
this.$refs.searchBar.open();
|
||||||
},
|
},
|
||||||
|
|
|
@ -58,6 +58,7 @@ import {getCurrentProjectID, getUUID} from "@/common/js/utils";
|
||||||
import MsDrawer from "../../../../common/components/MsDrawer";
|
import MsDrawer from "../../../../common/components/MsDrawer";
|
||||||
import {CASE_ORDER} from "../../model/JsonData";
|
import {CASE_ORDER} from "../../model/JsonData";
|
||||||
import {API_CASE_CONFIGS} from "@/business/components/common/components/search/search-components";
|
import {API_CASE_CONFIGS} from "@/business/components/common/components/search/search-components";
|
||||||
|
import {parseEnvironment} from "@/business/components/api/definition/model/EnvironmentModel";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ApiCaseList',
|
name: 'ApiCaseList',
|
||||||
|
@ -223,6 +224,13 @@ export default {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
setEnvironment(environment) {
|
setEnvironment(environment) {
|
||||||
|
if (this.environment !== environment) {
|
||||||
|
if (this.apiCaseList && this.apiCaseList.length > 0) {
|
||||||
|
if (this.apiCaseList[0].request && this.apiCaseList[0].request.hashTree) {
|
||||||
|
this.setOwnEnvironment(this.apiCaseList[0].request.hashTree, environment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
this.environment = environment;
|
this.environment = environment;
|
||||||
},
|
},
|
||||||
sysAddition(apiCase) {
|
sysAddition(apiCase) {
|
||||||
|
@ -281,6 +289,39 @@ export default {
|
||||||
refreshModule() {
|
refreshModule() {
|
||||||
this.$emit('refreshModule');
|
this.$emit('refreshModule');
|
||||||
},
|
},
|
||||||
|
setEnvironments(obj) {
|
||||||
|
this.$get('/api/environment/list/' + this.projectId, response => {
|
||||||
|
let environments = response.data;
|
||||||
|
this.getTargetSource(environments, obj);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getTargetSource(environments, obj) {
|
||||||
|
environments.forEach(environment => {
|
||||||
|
parseEnvironment(environment);
|
||||||
|
// 找到原始环境和数据源名称
|
||||||
|
if (environment.id === obj.environmentId) {
|
||||||
|
if (environment.config && environment.config.databaseConfigs) {
|
||||||
|
environment.config.databaseConfigs.forEach(item => {
|
||||||
|
if (item.id === obj.dataSourceId) {
|
||||||
|
obj.targetDataSourceName = item.name;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
setOwnEnvironment(scenarioDefinition, env) {
|
||||||
|
for (let i in scenarioDefinition) {
|
||||||
|
let typeArray = ["JDBCPostProcessor", "JDBCSampler", "JDBCPreProcessor"]
|
||||||
|
if (typeArray.indexOf(scenarioDefinition[i].type) !== -1) {
|
||||||
|
this.setEnvironments(scenarioDefinition[i]);
|
||||||
|
scenarioDefinition[i].environmentId = env;
|
||||||
|
}
|
||||||
|
if (scenarioDefinition[i].hashTree !== undefined && scenarioDefinition[i].hashTree.length > 0) {
|
||||||
|
this.setOwnEnvironment(scenarioDefinition[i].hashTree, env);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
runRefresh(data) {
|
runRefresh(data) {
|
||||||
this.batchLoadingIds = [];
|
this.batchLoadingIds = [];
|
||||||
this.singleLoading = false;
|
this.singleLoading = false;
|
||||||
|
|
|
@ -92,11 +92,45 @@
|
||||||
this.currentData.environmentId = value;
|
this.currentData.environmentId = value;
|
||||||
if (this.currentData.request) {
|
if (this.currentData.request) {
|
||||||
this.currentData.request.useEnvironment = value;
|
this.currentData.request.useEnvironment = value;
|
||||||
|
// 更改当前步骤中含SQL前后置步骤对应的数据源
|
||||||
|
if(this.currentData.request.hashTree) {
|
||||||
|
// 找到原始环境和数据源名称
|
||||||
|
let environment = this.environments[i];
|
||||||
|
this.setOwnEnvironment(this.currentData.request.hashTree, environment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
getTargetSource(obj){
|
||||||
|
this.environments.forEach(environment => {
|
||||||
|
parseEnvironment(environment);
|
||||||
|
// 找到原始环境和数据源名称
|
||||||
|
if (environment.id === obj.environmentId) {
|
||||||
|
if (environment.config && environment.config.databaseConfigs) {
|
||||||
|
environment.config.databaseConfigs.forEach(item => {
|
||||||
|
if (item.id === obj.dataSourceId) {
|
||||||
|
obj.targetDataSourceName = item.name;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
setOwnEnvironment(scenarioDefinition,env) {
|
||||||
|
for (let i in scenarioDefinition) {
|
||||||
|
let typeArray = ["JDBCPostProcessor", "JDBCSampler", "JDBCPreProcessor"]
|
||||||
|
if (typeArray.indexOf(scenarioDefinition[i].type) !== -1) {
|
||||||
|
// 找到原始数据源名称
|
||||||
|
this.getTargetSource(scenarioDefinition[i])
|
||||||
|
scenarioDefinition[i].environmentId = env.id;
|
||||||
|
}
|
||||||
|
if (scenarioDefinition[i].hashTree !== undefined && scenarioDefinition[i].hashTree.length > 0) {
|
||||||
|
this.setOwnEnvironment(scenarioDefinition[i].hashTree,env);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
openEnvironmentConfig() {
|
openEnvironmentConfig() {
|
||||||
if (!this.projectId) {
|
if (!this.projectId) {
|
||||||
this.$error(this.$t('api_test.select_project'));
|
this.$error(this.$t('api_test.select_project'));
|
||||||
|
@ -104,10 +138,10 @@
|
||||||
}
|
}
|
||||||
this.$refs.environmentConfig.open(this.projectId);
|
this.$refs.environmentConfig.open(this.projectId);
|
||||||
},
|
},
|
||||||
setEnvironment(enviromentId){
|
setEnvironment(environmentId){
|
||||||
this.currentData.environmentId = enviromentId;
|
this.currentData.environmentId = environmentId;
|
||||||
if (this.currentData.request) {
|
if (this.currentData.request) {
|
||||||
this.currentData.request.useEnvironment = enviromentId;
|
this.currentData.request.useEnvironment = environmentId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,9 +176,8 @@ export default {
|
||||||
deep: true
|
deep: true
|
||||||
},
|
},
|
||||||
'$store.state.useEnvironment': function () {
|
'$store.state.useEnvironment': function () {
|
||||||
if (!this.scenarioId) {
|
if (this.scenarioId !== "") {
|
||||||
this.request.environmentId = this.$store.state.useEnvironment;
|
this.getEnvironments(this.$store.state.useEnvironment);
|
||||||
this.getEnvironments();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'$store.state.scenarioEnvMap': {
|
'$store.state.scenarioEnvMap': {
|
||||||
|
@ -263,17 +262,32 @@ export default {
|
||||||
runTest() {
|
runTest() {
|
||||||
|
|
||||||
},
|
},
|
||||||
itselfEnvironment() {
|
itselfEnvironment(environmentId) {
|
||||||
let id = this.request.projectId ? this.request.projectId : this.projectId;
|
let id = this.request.projectId ? this.request.projectId : this.projectId;
|
||||||
this.result = this.$get('/api/environment/list/' + id, response => {
|
this.result = this.$get('/api/environment/list/' + id, response => {
|
||||||
this.environments = response.data;
|
this.environments = response.data;
|
||||||
|
let targetDataSourceName = undefined;
|
||||||
|
let currentEnvironment = undefined;
|
||||||
this.environments.forEach(environment => {
|
this.environments.forEach(environment => {
|
||||||
parseEnvironment(environment);
|
parseEnvironment(environment);
|
||||||
|
// 找到原始环境和数据源名称
|
||||||
|
if (environment.id === environmentId) {
|
||||||
|
currentEnvironment = environment;
|
||||||
|
}
|
||||||
|
if (environment.id === this.request.environmentId) {
|
||||||
|
if (environment.config && environment.config.databaseConfigs) {
|
||||||
|
environment.config.databaseConfigs.forEach(item => {
|
||||||
|
if (item.id === this.request.dataSourceId) {
|
||||||
|
targetDataSourceName = item.name;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
this.initDataSource();
|
this.initDataSource(environmentId, currentEnvironment, targetDataSourceName);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getEnvironments() {
|
getEnvironments(environmentId) {
|
||||||
let envId = "";
|
let envId = "";
|
||||||
let id = this.request.projectId ? this.request.projectId : this.projectId;
|
let id = this.request.projectId ? this.request.projectId : this.projectId;
|
||||||
let scenarioEnvId = this.request.currentScenarioId ? (this.request.currentScenarioId + "_" + id) : id;
|
let scenarioEnvId = this.request.currentScenarioId ? (this.request.currentScenarioId + "_" + id) : id;
|
||||||
|
@ -281,13 +295,11 @@ export default {
|
||||||
&& this.$store.state.scenarioEnvMap.has(scenarioEnvId)) {
|
&& this.$store.state.scenarioEnvMap.has(scenarioEnvId)) {
|
||||||
envId = this.$store.state.scenarioEnvMap.get(scenarioEnvId);
|
envId = this.$store.state.scenarioEnvMap.get(scenarioEnvId);
|
||||||
}
|
}
|
||||||
if (this.request.referenced === 'Created' && this.scenarioId && !this.request.isRefEnvironment) {
|
if (this.request.referenced === 'Created' && this.scenarioId !== "" && !this.request.isRefEnvironment) {
|
||||||
alert(2222)
|
this.itselfEnvironment(environmentId);
|
||||||
this.itselfEnvironment();
|
|
||||||
return;
|
return;
|
||||||
} else if (!this.scenarioId && !this.request.customizeReq) {
|
} else if (!this.scenarioId && !this.request.customizeReq) {
|
||||||
alert(333)
|
this.itselfEnvironment(environmentId);
|
||||||
this.itselfEnvironment();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.environments = [];
|
this.environments = [];
|
||||||
|
@ -384,10 +396,41 @@ export default {
|
||||||
this.environments[i].config.databaseConfigs.forEach(item => {
|
this.environments[i].config.databaseConfigs.forEach(item => {
|
||||||
this.databaseConfigsOptions.push(item);
|
this.databaseConfigsOptions.push(item);
|
||||||
})
|
})
|
||||||
|
if (this.request.hashTree && !this.scenarioId) {
|
||||||
|
this.setOwnEnvironment(this.request.hashTree, value)
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
setOwnEnvironment(scenarioDefinition, env) {
|
||||||
|
for (let i in scenarioDefinition) {
|
||||||
|
let typeArray = ["JDBCPostProcessor", "JDBCSampler", "JDBCPreProcessor"]
|
||||||
|
if (typeArray.indexOf(scenarioDefinition[i].type) !== -1) {
|
||||||
|
// 找到原始数据源名称
|
||||||
|
this.getTargetSource(scenarioDefinition[i])
|
||||||
|
scenarioDefinition[i].environmentId = env;
|
||||||
|
}
|
||||||
|
if (scenarioDefinition[i].hashTree !== undefined && scenarioDefinition[i].hashTree.length > 0) {
|
||||||
|
this.setOwnEnvironment(scenarioDefinition[i].hashTree, env);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getTargetSource(obj) {
|
||||||
|
this.environments.forEach(environment => {
|
||||||
|
parseEnvironment(environment);
|
||||||
|
// 找到原始环境和数据源名称
|
||||||
|
if (environment.id === obj.environmentId) {
|
||||||
|
if (environment.config && environment.config.databaseConfigs) {
|
||||||
|
environment.config.databaseConfigs.forEach(item => {
|
||||||
|
if (item.id === obj.dataSourceId) {
|
||||||
|
obj.targetDataSourceName = item.name;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
environmentConfigClose() {
|
environmentConfigClose() {
|
||||||
this.getEnvironments();
|
this.getEnvironments();
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue