aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/tests/repository/repository_factory_test.rs
blob: c018c453aba85e6be9aa6dbf3391cb4179b204fd (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//! ref: composer/tests/Composer/Test/Repository/RepositoryFactoryTest.php

use std::cell::RefCell;
use std::rc::Rc;

use indexmap::IndexMap;
use shirabe::config::Config;
use shirabe::io::IOInterface;
use shirabe::io::null_io::NullIO;
use shirabe::repository::RepositoryFactory;
use shirabe::util::http_downloader::HttpDownloader;
use shirabe_php_shim::PhpMixed;

#[test]
#[ignore]
fn test_manager_with_all_repository_types() {
    let io: Rc<RefCell<dyn IOInterface>> = Rc::new(RefCell::new(NullIO::new()));
    let config = Rc::new(RefCell::new(Config::new(false, None)));
    let http_downloader = Rc::new(RefCell::new(HttpDownloader::new(
        io.clone(),
        config.clone(),
        IndexMap::new(),
        true,
    )));

    let manager =
        RepositoryFactory::manager(io, &config, Some(http_downloader), None, None).unwrap();

    let repository_classes: Vec<&str> = manager
        .__repository_classes()
        .keys()
        .map(|k| k.as_str())
        .collect();

    assert_eq!(
        vec![
            "composer",
            "vcs",
            "package",
            "pear",
            "git",
            "bitbucket",
            "git-bitbucket",
            "github",
            "gitlab",
            "svn",
            "fossil",
            "perforce",
            "hg",
            "artifact",
            "path",
        ],
        repository_classes
    );
}

fn generate_repository_name_provider() -> Vec<(
    PhpMixed,
    Vec<(&'static str, PhpMixed)>,
    Vec<&'static str>,
    &'static str,
)> {
    vec![
        (PhpMixed::Int(0), vec![], vec![], "0"),
        (PhpMixed::Int(0), vec![], vec!["0"], "02"),
        (
            PhpMixed::Int(0),
            vec![("url", PhpMixed::String("https://example.org".to_string()))],
            vec![],
            "example.org",
        ),
        (
            PhpMixed::Int(0),
            vec![("url", PhpMixed::String("https://example.org".to_string()))],
            vec!["example.org"],
            "example.org2",
        ),
        (
            PhpMixed::String("example.org".to_string()),
            vec![(
                "url",
                PhpMixed::String("https://example.org/repository".to_string()),
            )],
            vec![],
            "example.org",
        ),
        (
            PhpMixed::String("example.org".to_string()),
            vec![(
                "url",
                PhpMixed::String("https://example.org/repository".to_string()),
            )],
            vec!["example.org"],
            "example.org2",
        ),
    ]
}

#[test]
#[ignore]
fn test_generate_repository_name() {
    for (index, repo_pairs, existing_keys, expected) in generate_repository_name_provider() {
        let repo: IndexMap<String, PhpMixed> = repo_pairs
            .into_iter()
            .map(|(k, v)| (k.to_string(), v))
            .collect();
        let existing_repos: IndexMap<String, ()> = existing_keys
            .into_iter()
            .map(|k| (k.to_string(), ()))
            .collect();

        assert_eq!(
            expected,
            RepositoryFactory::generate_repository_name(&index, &repo, &existing_repos)
        );
    }
}