File: test_dependabot_v2.rs

package info (click to toggle)
rust-github-actions-models 0.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 432 kB
  • sloc: makefile: 4
file content (67 lines) | stat: -rw-r--r-- 2,337 bytes parent folder | download
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
use std::path::Path;

use github_actions_models::dependabot::v2::{
    Dependabot, Interval, PackageEcosystem, RebaseStrategy,
};
use indexmap::IndexSet;

fn load_dependabot(name: &str) -> Dependabot {
    let workflow_path = Path::new(env!("CARGO_MANIFEST_DIR"))
        .join("tests/sample-dependabot/v2")
        .join(name);
    let dependabot_contents = std::fs::read_to_string(workflow_path).unwrap();
    serde_yaml::from_str(&dependabot_contents).unwrap()
}

#[test]
fn test_load_all() {
    let sample_configs = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/sample-dependabot/v2");

    for sample_config in std::fs::read_dir(sample_configs).unwrap() {
        let sample_workflow = sample_config.unwrap().path();
        let contents = std::fs::read_to_string(sample_workflow).unwrap();
        serde_yaml::from_str::<Dependabot>(&contents).unwrap();
    }
}

#[test]
fn test_contents() {
    let dependabot = load_dependabot("sigstore-python.yml");

    assert_eq!(dependabot.version, 2);
    assert_eq!(dependabot.updates.len(), 3);

    let pip = &dependabot.updates[0];
    assert_eq!(pip.package_ecosystem, PackageEcosystem::Pip);
    assert_eq!(pip.directory, "/");
    assert_eq!(pip.schedule.interval, Interval::Daily);
    assert_eq!(pip.open_pull_requests_limit, 5); // default

    let github_actions = &dependabot.updates[1];
    assert_eq!(
        github_actions.package_ecosystem,
        PackageEcosystem::GithubActions
    );
    assert_eq!(github_actions.directory, "/");
    assert_eq!(github_actions.open_pull_requests_limit, 99);
    assert_eq!(github_actions.rebase_strategy, RebaseStrategy::Disabled);
    assert_eq!(github_actions.groups.len(), 1);
    assert_eq!(
        github_actions.groups["actions"].patterns,
        IndexSet::from(["*".to_string()])
    );

    let github_actions = &dependabot.updates[2];
    assert_eq!(
        github_actions.package_ecosystem,
        PackageEcosystem::GithubActions
    );
    assert_eq!(github_actions.directory, ".github/actions/upload-coverage/");
    assert_eq!(github_actions.open_pull_requests_limit, 99);
    assert_eq!(github_actions.rebase_strategy, RebaseStrategy::Disabled);
    assert_eq!(github_actions.groups.len(), 1);
    assert_eq!(
        github_actions.groups["actions"].patterns,
        IndexSet::from(["*".to_string()])
    );
}