Search in sources :

Example 1 with DoctorEndpointResponse

use of com.facebook.buck.doctor.config.DoctorEndpointResponse in project buck by facebook.

the class DoctorCommand method runWithoutHelp.

@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
    ProjectFilesystem filesystem = params.getCell().getFilesystem();
    BuildLogHelper buildLogHelper = new BuildLogHelper(filesystem, params.getObjectMapper());
    UserInput userInput = new UserInput(params.getConsole().getStdOut(), new BufferedReader(new InputStreamReader(params.getStdIn())));
    DoctorReportHelper helper = new DoctorReportHelper(params.getCell().getFilesystem(), userInput, params.getConsole(), params.getObjectMapper(), params.getBuckConfig().getView(DoctorConfig.class));
    Optional<BuildLogEntry> entry = helper.promptForBuild(new ArrayList<>(buildLogHelper.getBuildLogs()));
    if (!entry.isPresent()) {
        params.getConsole().getStdOut().println("No interesting commands found in buck-out/log.");
        return 0;
    }
    Optional<DefectSubmitResult> rageResult = generateRageReport(params, userInput, entry.get());
    if (!rageResult.isPresent()) {
        params.getConsole().printErrorText("Failed to generate report to send.");
        return 1;
    }
    DoctorEndpointRequest request = helper.generateEndpointRequest(entry.get(), rageResult.get());
    DoctorEndpointResponse response = helper.uploadRequest(request);
    helper.presentResponse(response);
    helper.presentRageResult(rageResult);
    return 0;
}
Also used : InputStreamReader(java.io.InputStreamReader) DoctorEndpointRequest(com.facebook.buck.doctor.config.DoctorEndpointRequest) DoctorReportHelper(com.facebook.buck.doctor.DoctorReportHelper) BuildLogHelper(com.facebook.buck.rage.BuildLogHelper) UserInput(com.facebook.buck.rage.UserInput) DoctorConfig(com.facebook.buck.doctor.config.DoctorConfig) BuildLogEntry(com.facebook.buck.rage.BuildLogEntry) DefectSubmitResult(com.facebook.buck.rage.DefectSubmitResult) BufferedReader(java.io.BufferedReader) DoctorEndpointResponse(com.facebook.buck.doctor.config.DoctorEndpointResponse) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem)

Example 2 with DoctorEndpointResponse

use of com.facebook.buck.doctor.config.DoctorEndpointResponse in project buck by facebook.

the class DoctorCommandIntegrationTest method testEndpointUrl.

@Test
public void testEndpointUrl() throws Exception {
    DoctorReportHelper helper = createDoctorHelper((new UserInputFixture("0")).getUserInput(), DoctorConfig.of(FakeBuckConfig.builder().build()));
    BuildLogHelper buildLogHelper = new BuildLogHelper(workspace.asCell().getFilesystem(), objectMapper);
    Optional<BuildLogEntry> entry = helper.promptForBuild(new ArrayList<>(buildLogHelper.getBuildLogs()));
    DoctorEndpointRequest request = helper.generateEndpointRequest(entry.get(), rageResult);
    DoctorEndpointResponse response = helper.uploadRequest(request);
    assertEquals("Please define URL", response.getErrorMessage().get(), "Doctor endpoint URL is not set. Please set [doctor] endpoint_url on your .buckconfig");
}
Also used : BuildLogEntry(com.facebook.buck.rage.BuildLogEntry) UserInputFixture(com.facebook.buck.rage.UserInputFixture) DoctorEndpointRequest(com.facebook.buck.doctor.config.DoctorEndpointRequest) BuildLogHelper(com.facebook.buck.rage.BuildLogHelper) DoctorEndpointResponse(com.facebook.buck.doctor.config.DoctorEndpointResponse) Test(org.junit.Test)

Example 3 with DoctorEndpointResponse

use of com.facebook.buck.doctor.config.DoctorEndpointResponse in project buck by facebook.

the class DoctorReportHelperTest method testNoAvailableSuggestions.

@Test
public void testNoAvailableSuggestions() throws Exception {
    TestConsole console = new TestConsole();
    DoctorConfig doctorConfig = DoctorConfig.of(FakeBuckConfig.builder().setSections(ImmutableMap.of(DoctorConfig.DOCTOR_SECTION, ImmutableMap.of(DoctorConfig.URL_FIELD, "url"))).build());
    DoctorReportHelper helper = new DoctorReportHelper(workspace.asCell().getFilesystem(), (new UserInputFixture("0")).getUserInput(), console, objectMapper, doctorConfig);
    DoctorEndpointResponse response = DoctorEndpointResponse.of(Optional.empty(), ImmutableList.of());
    helper.presentResponse(response);
    assertEquals("\n:: No available suggestions right now.\n\n", console.getTextWrittenToStdOut());
}
Also used : UserInputFixture(com.facebook.buck.rage.UserInputFixture) DoctorEndpointResponse(com.facebook.buck.doctor.config.DoctorEndpointResponse) TestConsole(com.facebook.buck.testutil.TestConsole) DoctorConfig(com.facebook.buck.doctor.config.DoctorConfig) Test(org.junit.Test)

Example 4 with DoctorEndpointResponse

use of com.facebook.buck.doctor.config.DoctorEndpointResponse in project buck by facebook.

the class DoctorCommandIntegrationTest method testPromptWithoutRageReport.

@Test
public void testPromptWithoutRageReport() throws Exception {
    assumeThat(Platform.detect(), Matchers.not(Matchers.is(Platform.WINDOWS)));
    DoctorReportHelper helper = createDoctorHelper((new UserInputFixture("0")).getUserInput(), createDoctorConfig(httpd));
    BuildLogHelper buildLogHelper = new BuildLogHelper(workspace.asCell().getFilesystem(), objectMapper);
    Optional<BuildLogEntry> entry = helper.promptForBuild(new ArrayList<>(buildLogHelper.getBuildLogs()));
    DoctorEndpointRequest request = helper.generateEndpointRequest(entry.get(), rageResult);
    DoctorEndpointResponse response = helper.uploadRequest(request);
    helper.presentResponse(response);
    assertEquals(response, doctorResponse);
    assertEquals("\n:: Suggestions\n- [Error] Suggestion no1\n- [Warning][Area] Suggestion no2\n\n", ((TestConsole) helper.getConsole()).getTextWrittenToStdOut());
}
Also used : BuildLogEntry(com.facebook.buck.rage.BuildLogEntry) UserInputFixture(com.facebook.buck.rage.UserInputFixture) DoctorEndpointRequest(com.facebook.buck.doctor.config.DoctorEndpointRequest) BuildLogHelper(com.facebook.buck.rage.BuildLogHelper) DoctorEndpointResponse(com.facebook.buck.doctor.config.DoctorEndpointResponse) Test(org.junit.Test)

Example 5 with DoctorEndpointResponse

use of com.facebook.buck.doctor.config.DoctorEndpointResponse in project buck by facebook.

the class DoctorReportHelperTest method testErrorMessage.

@Test
public void testErrorMessage() throws Exception {
    TestConsole console = new TestConsole();
    DoctorConfig doctorConfig = DoctorConfig.of(FakeBuckConfig.builder().setSections(ImmutableMap.of(DoctorConfig.DOCTOR_SECTION, ImmutableMap.of(DoctorConfig.URL_FIELD, "url"))).build());
    DoctorReportHelper helper = new DoctorReportHelper(workspace.asCell().getFilesystem(), (new UserInputFixture("0")).getUserInput(), console, objectMapper, doctorConfig);
    String errorMessage = "This is an error message.";
    DoctorEndpointResponse response = DoctorEndpointResponse.of(Optional.of(errorMessage), ImmutableList.of());
    helper.presentResponse(response);
    assertEquals("=> " + errorMessage + "\n", console.getTextWrittenToStdOut());
}
Also used : UserInputFixture(com.facebook.buck.rage.UserInputFixture) DoctorEndpointResponse(com.facebook.buck.doctor.config.DoctorEndpointResponse) TestConsole(com.facebook.buck.testutil.TestConsole) DoctorConfig(com.facebook.buck.doctor.config.DoctorConfig) Test(org.junit.Test)

Aggregations

DoctorEndpointResponse (com.facebook.buck.doctor.config.DoctorEndpointResponse)6 DoctorEndpointRequest (com.facebook.buck.doctor.config.DoctorEndpointRequest)4 UserInputFixture (com.facebook.buck.rage.UserInputFixture)4 Test (org.junit.Test)4 DoctorConfig (com.facebook.buck.doctor.config.DoctorConfig)3 BuildLogEntry (com.facebook.buck.rage.BuildLogEntry)3 BuildLogHelper (com.facebook.buck.rage.BuildLogHelper)3 TestConsole (com.facebook.buck.testutil.TestConsole)2 DoctorReportHelper (com.facebook.buck.doctor.DoctorReportHelper)1 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 DefectSubmitResult (com.facebook.buck.rage.DefectSubmitResult)1 UserInput (com.facebook.buck.rage.UserInput)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Map (java.util.Map)1 FormBody (okhttp3.FormBody)1 OkHttpClient (okhttp3.OkHttpClient)1