in packages/autorest.gotest/src/generator/mockTestGenerator.ts [53:163]
protected fillExampleOutput(example: GoExampleModel): void {
const op = example.operation;
example.opName = op.language.go.name;
if (isPageableOperation(op) && !isLROOperation(op)) {
example.opName = `New${example.opName}Pager`;
}
if (isLROOperation(<any>op)) {
example.opName = 'Begin' + example.opName;
example.isLRO = true;
example.pollerType = example.operation.language.go.responseEnv.language.go.name;
} else {
example.isLRO = false;
}
example.isPageable = isPageableOperation(<any>op);
this.skipPropertyFunc = (exampleValue: ExampleValue): boolean => {
// skip any null value
if (exampleValue.rawValue === null) {
return true;
}
return false;
};
this.replaceValueFunc = (rawValue: any): any => {
return rawValue;
};
const factoryGatherAllParamsFlag = this.context.testConfig.getValue(Config.factoryGatherAllParams, true);
if (factoryGatherAllParamsFlag) {
this.clientFactoryParams = this.getAllClientParameters();
} else {
this.clientFactoryParams = this.getCommonClientParameters();
}
const factoryClientParameters = new Array<Parameter>();
for (const clientParam of values(<Array<Parameter>>(example.operationGroup.language.go?.clientParams || []))) {
if (this.clientFactoryParams.filter((cp) => cp.language.go!.name === clientParam.language.go!.name).length > 0) {
continue;
}
factoryClientParameters.push(clientParam);
}
example.methodParametersOutput = this.toParametersOutput(getAPIParametersSig(op), example.methodParameters);
example.clientParametersOutput = this.toParametersOutput(getClientParametersSig(example.operationGroup), example.clientParameters, true);
example.factoryClientParametersOutput = this.toParametersOutput(getParametersSig(factoryClientParameters), example.clientParameters, true);
example.returnInfo = generateReturnsInfo(op, 'op');
const schemaResponse = getSchemaResponse(<any>op);
if (example.isPageable) {
const valueName = op.extensions['x-ms-pageable'].itemName === undefined ? 'value' : op.extensions['x-ms-pageable'].itemName;
for (const property of schemaResponse.schema['properties']) {
if (property.serializedName === valueName) {
example.pageableItemName = property.language.go.name;
if (schemaResponse.schema.language.go.name === property.language.go.name) {
example.pageableItemName = `${property.language.go.name}.${example.pageableItemName}`;
}
break;
}
}
}
example.checkResponse =
schemaResponse !== undefined && schemaResponse.protocol.http.statusCodes[0] === '200' && example.responses[schemaResponse.protocol.http.statusCodes[0]]?.body !== undefined;
example.isMultiRespOperation = isMultiRespOperation(op);
if (example.checkResponse && this.context.testConfig.getValue(Config.verifyResponse)) {
this.context.importManager.add('encoding/json');
this.context.importManager.add('reflect');
this.skipPropertyFunc = (exampleValue: ExampleValue): boolean => {
// mock-test will remove all NextLink param
// skip any null value
if (exampleValue.language?.go?.name.includes('NextLink') || (exampleValue.rawValue === null && exampleValue.language?.go?.name !== 'ProvisioningState')) {
return true;
}
return false;
};
this.replaceValueFunc = (rawValue: any, exampleValue: ExampleValue): any => {
// mock-test will change all ProvisioningState to Succeeded
if (exampleValue.language?.go?.name === 'ProvisioningState') {
if (exampleValue.schema.type !== SchemaType.SealedChoice || (<ChoiceSchema>exampleValue.schema).choices.filter((choice) => choice.value === 'Succeeded').length > 0) {
return 'Succeeded';
} else {
return (<ChoiceSchema>exampleValue.schema).choices[0].value;
}
}
return rawValue;
};
example.responseOutput = this.exampleValueToString(example.responses[schemaResponse.protocol.http.statusCodes[0]].body, false);
if (isMultiRespOperation(op)) {
example.responseTypePointer = false;
example.responseType = 'Value';
} else {
const responseEnv = op.language.go.responseEnv;
if (responseEnv.language.go?.resultProp.schema.serialization?.xml?.name) {
example.responseTypePointer = !responseEnv.language.go?.resultProp.schema.language.go?.byValue;
example.responseType = responseEnv.language.go?.resultProp.schema.language.go?.name;
if (responseEnv.language.go?.resultProp.schema.isDiscriminator === true) {
example.responseIsDiscriminator = true;
example.responseType = responseEnv.language.go.resultProp.schema.language.go?.discriminatorInterface;
example.responseOutput = `${this.context.packageName}.${responseEnv.language.go.name}{
${example.responseType}: &${example.responseOutput},
}`;
}
} else {
example.responseTypePointer = !responseEnv.language.go?.resultProp.language.go?.byValue;
example.responseType = responseEnv.language.go?.resultProp.language.go?.name;
if (responseEnv.language.go?.resultProp.isDiscriminator === true) {
example.responseIsDiscriminator = true;
example.responseType = responseEnv.language.go.resultProp.schema.language.go?.discriminatorInterface;
example.responseOutput = `${this.context.packageName}.${responseEnv.language.go.name}{
${example.responseType}: &${example.responseOutput},
}`;
}
}
}
}
}