Я недавно начал изучать балерину не может издеваться над graphql: Client. репо и пр: https://github.com/zero-hack-org/module-zerohack-github/pull/1
@test:Config {
dataProvider: testExecuteDataProvider
}
function testExecute(string query) returns error? {
GraphQlClient|error graphqlClient = new;
if graphqlClient is error {
test:assertFail("Unexpected: GraphQlClient is error");
}
final graphql:Client mockedClient = test:mock(graphql:Client);
record {|anydata...;|} res = {"username": "test"};
test:prepare(mockedClient).when("execute").thenReturn(res);
graphql:GenericResponseWithErrors|record {|anydata...;|}|json|graphql:ClientError result = check graphqlClient.execute(query = query);
if result is graphql:GenericResponseWithErrors {
test:assertFail("Unexpected: executed response is graphql:GenericResponseWithErrors");
}
if result is json {
test:assertFail("Unexpected: executed response is json");
}
if result is graphql:ClientError {
test:assertFail("Unexpected: executed response is graphql:ClientError");
}
}
ошибка:
[HttpError из-за неработающего макета] ошибка {ballerina/test:0}ExecutionError ("ошибка {ballerina/graphql:1}HttpError&{ballerina/graphql:1}RequestError&{ballerina/graphql:1}ClientError("Ошибка клиента GraphQL",body = {"message": "Неверные учетные данные","documentation_url":"https://docs.github.com/graphql"})





Из данной тестовой функции трудно понять ваше требование.
Я предполагаю, что вы пытаетесь издеваться над внешним клиентом githubClient, используемым в GraphQlClient, который вы определили. https://github.com/zero-hack-org/module-zerohack-github/blob/main/graphql.bal#L11
Если это так, есть несколько подходов, которые вы можете предпринять. Пожалуйста, обратитесь к приведенным ниже руководствам по тестированию.
https://ballerina.io/learn/test-ballerina-code/test-services-and-clients/https://ballerina.io/learn/test-ballerina-code/mocking/
Спасибо!! Затем я хотел бы изменить реализацию, чтобы она была тестируемым кодом.