aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/command/diagnose_command_test.rs
blob: 1bd0c6ac5fb93dc0275841206c96e757e15fb6cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//! ref: composer/tests/Composer/Test/Command/DiagnoseCommandTest.php

use crate::test_case::{RunOptions, get_application_tester, init_temp_composer};
use serial_test::serial;
use shirabe::util::platform::Platform;
use shirabe_php_shim::PhpMixed;

#[test]
#[serial]
#[ignore = "diagnose checks live http/https connectivity to packagist and the github.com rate \
            limit, so it requires real network access"]
fn test_cmd_fail() {
    let tear_down = init_temp_composer(
        Some(&serde_json::json!({ "name": "foo/bar", "description": "test pkg" })),
        None,
        None,
        false,
    );

    let mut app_tester = get_application_tester();
    app_tester
        .run(
            vec![(PhpMixed::from("command"), PhpMixed::from("diagnose"))],
            RunOptions::default(),
        )
        .unwrap();

    if Platform::get_env("COMPOSER_LOWEST_DEPS_TEST").as_deref() == Some("1") {
        assert!(app_tester.get_status_code() >= 1);
    } else {
        assert_eq!(1, app_tester.get_status_code());
    }

    let output = app_tester.get_display();
    assert!(output.contains(
        "Checking composer.json: <warning>WARNING</warning>
<warning>No license specified, it is recommended to do so. For closed-source software you may use \"proprietary\" as license.</warning>"
    ));

    assert!(output.contains(
        "Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: "
    ));

    drop(tear_down);
}

#[test]
#[serial]
#[ignore = "diagnose checks live http/https connectivity to packagist and the github.com rate \
            limit, so it requires real network access"]
fn test_cmd_success() {
    let tear_down = init_temp_composer(
        Some(&serde_json::json!({
            "name": "foo/bar",
            "description": "test pkg",
            "license": "MIT",
        })),
        None,
        None,
        false,
    );

    let mut app_tester = get_application_tester();
    app_tester
        .run(
            vec![(PhpMixed::from("command"), PhpMixed::from("diagnose"))],
            RunOptions::default(),
        )
        .unwrap();

    if Platform::get_env("COMPOSER_LOWEST_DEPS_TEST").as_deref() != Some("1") {
        // assertCommandIsSuccessful
        assert_eq!(
            0,
            app_tester.get_status_code(),
            "{}",
            app_tester.get_display()
        );
    }

    let output = app_tester.get_display();
    assert!(output.contains("Checking composer.json: OK"));

    assert!(output.contains(
        "Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: "
    ));

    drop(tear_down);
}