fix(旧版本接口测试): 兼容新版本定义的环境

This commit is contained in:
fit2-zhao 2021-05-06 18:22:19 +08:00 committed by fit2-zhao
parent 7220882d7d
commit 9b110273bc
3 changed files with 56 additions and 11 deletions

View File

@ -9,7 +9,7 @@
<el-select :disabled="isReadOnly" v-model="scenario.environmentId" class="environment-select"
@change="environmentChange" clearable>
<el-option v-for="(environment, index) in environments" :key="index"
:label="environment.name + (environment.config.httpConfig.socket ? (': ' + environment.config.httpConfig.protocol + '://' + environment.config.httpConfig.socket) : '')"
:label="environment.name"
:value="environment.id"/>
<el-button class="environment-button" size="mini" type="primary" @click="openEnvironmentConfig">
{{ $t('api_test.environment.environment_config') }}

View File

@ -193,9 +193,24 @@ export default {
computed: {
displayUrl() {
return (this.scenario.environment && this.scenario.environment.config.httpConfig.socket) ?
this.scenario.environment.config.httpConfig.protocol + '://' + this.scenario.environment.config.httpConfig.socket + (this.request.path ? this.request.path : '')
: '';
let url = null;
if(this.scenario.environment && this.scenario.environment.config.httpConfig
&& this.scenario.environment.config.httpConfig.conditions && this.scenario.environment.config.httpConfig.conditions.length > 0){
for(let i in this.scenario.environment.config.httpConfig.conditions) {
if (this.scenario.environment.config.httpConfig.conditions[i]) {
let item = this.scenario.environment.config.httpConfig.conditions[i];
if (item && item.type === 'NONE') {
url = item.protocol + '://' + item.socket + (this.request.path ? this.request.path : '');
}
}
}
}
if(url === null) {
url = (this.scenario.environment && this.scenario.environment.config.httpConfig.socket) ?
this.scenario.environment.config.httpConfig.protocol + '://' + this.scenario.environment.config.httpConfig.socket + (this.request.path ? this.request.path : '')
: '';
}
return url;
}
}
}

View File

@ -379,7 +379,20 @@ export class HttpRequest extends Request {
info: 'api_test.request.please_configure_environment_in_scenario'
}
}
if (!environment.config.httpConfig.socket) {
let url = null;
if (environment && this.environment.config.httpConfig
&& environment.config.httpConfig.conditions && environment.config.httpConfig.conditions.length > 0) {
environment.config.httpConfig.conditions.forEach(item => {
if (item.type === 'NONE') {
url = item.protocol + '://' + item.socket;
}
})
}
if (url === null) {
url = (environment && environment.config.httpConfig.socket) ?
environment.config.httpConfig.protocol + '://' + environment.config.httpConfig.socket : null;
}
if (url === null) {
return {
isValid: false,
info: 'api_test.request.please_configure_socket_in_environment'
@ -1031,12 +1044,29 @@ class JMXHttpRequest {
this.protocol = url.protocol.split(":")[0];
this.path = this.getPostQueryParameters(request, decodeURIComponent(url.pathname));
} else {
this.domain = environment.config.httpConfig.domain;
this.port = environment.config.httpConfig.port;
this.protocol = environment.config.httpConfig.protocol;
let url = new URL(environment.config.httpConfig.protocol + "://" + environment.config.httpConfig.socket);
let envPath = url.pathname === '/' ? '' : url.pathname;
this.path = this.getPostQueryParameters(request, decodeURIComponent(envPath + (request.path ? request.path : '')));
let isNewEnv = false;
if (environment && environment.config.httpConfig
&& environment.config.httpConfig.conditions && environment.config.httpConfig.conditions.length > 0) {
environment.config.httpConfig.conditions.forEach(item => {
if (item.type === 'NONE') {
isNewEnv = true;
this.domain = item.domain;
this.port = item.port;
this.protocol = item.protocol;
let url = new URL(item.protocol + "://" + item.socket);
let envPath = url.pathname === '/' ? '' : url.pathname;
this.path = this.getPostQueryParameters(request, decodeURIComponent(envPath + (request.path ? request.path : '')));
}
})
}
if (!isNewEnv) {
this.domain = environment.config.httpConfig.domain;
this.port = environment.config.httpConfig.port;
this.protocol = environment.config.httpConfig.protocol;
let url = new URL(environment.config.httpConfig.protocol + "://" + environment.config.httpConfig.socket);
let envPath = url.pathname === '/' ? '' : url.pathname;
this.path = this.getPostQueryParameters(request, decodeURIComponent(envPath + (request.path ? request.path : '')));
}
}
this.connectTimeout = request.connectTimeout;
this.responseTimeout = request.responseTimeout;