mod infra;
use indoc::indoc;
use infra::TestWorld;
use insta::assert_snapshot;
use protofetch::LockMode;
use toml::toml;
#[test]
fn fetch_single_file_dep() {
let mut world = TestWorld::new();
world.create_repo(
"org/repo1",
&[(
"proto/hello.proto",
indoc! {r#"
syntax = "proto3";
message Hello {}
"#},
)],
);
let result = world.fetch(toml! {
name = "e2e-test"
[repo1]
url = "org/repo1"
branch = "main"
});
assert_snapshot!("single_file_dep_output", result.snapshot_tree());
assert_snapshot!("single_file_dep_lockfile", result.snapshot_lockfile());
}
#[test]
fn fetch_two_repos_transitive_dep() {
let mut world = TestWorld::new();
world
.create_repo(
"org/repo1",
&[(
"proto/v1.proto",
indoc! {r#"
syntax = "proto3";
message V1 {}
"#},
)],
)
.add_commit(
"v2",
&[(
"proto/v2.proto",
indoc! {r#"
syntax = "proto3";
message V2 {}
"#},
)],
);
world.create_repo(
"org/repo2",
&[
(
"protofetch.toml",
indoc! {r#"
name = "repo2"
[repo1]
url = "<base>/org/repo1"
protocol = "file"
branch = "v2"
"#},
),
(
"proto/b.proto",
indoc! {r#"
syntax = "proto3";
message B {}
"#},
),
],
);
let result = world.fetch(toml! {
name = "e2e-test"
[repo1]
url = "org/repo1"
branch = "main"
[repo2]
url = "org/repo2"
branch = "main"
});
assert_snapshot!("two_repos_output", result.snapshot_tree());
assert_snapshot!("two_repos_lockfile", result.snapshot_lockfile());
}
#[test]
fn fetch_transitive_dep_only() {
let mut world = TestWorld::new();
world.create_repo(
"org/repo1",
&[(
"proto/a.proto",
indoc! {r#"
syntax = "proto3";
message A {}
"#},
)],
);
world.create_repo(
"org/repo2",
&[
(
"protofetch.toml",
indoc! {r#"
name = "repo2"
[repo1]
url = "<base>/org/repo1"
protocol = "file"
branch = "main"
"#},
),
(
"proto/b.proto",
indoc! {r#"
syntax = "proto3";
message B {}
"#},
),
],
);
let result = world.fetch(toml! {
name = "e2e-test"
[repo2]
url = "org/repo2"
branch = "main"
});
assert_snapshot!("transitive_only_output", result.snapshot_tree());
assert_snapshot!("transitive_only_lockfile", result.snapshot_lockfile());
}
#[test]
fn fetch_locked_mode_uses_pinned_commit() {
let mut world = TestWorld::new();
world
.create_repo(
"org/repo1",
&[(
"proto/v1.proto",
indoc! {r#"
syntax = "proto3";
message V1 {}
"#},
)],
)
.add_commit(
"main",
&[(
"proto/v2.proto",
indoc! {r#"
syntax = "proto3";
message V2 {}
"#},
)],
);
let result = world.fetch_with_initial_lock(
toml! {
name = "e2e-test"
[repo1]
url = "org/repo1"
branch = "main"
},
LockMode::Locked,
toml! {
version = 2
[[dependencies]]
name = "repo1"
url = "<base>/org/repo1"
protocol = "file"
branch = "main"
commit_hash = "<commit:main:1>"
},
);
assert_snapshot!("locked_mode_output", result.snapshot_tree());
assert_snapshot!("locked_mode_lockfile", result.snapshot_lockfile());
}
#[test]
fn fetch_allow_policies() {
let mut world = TestWorld::new();
world.create_repo(
"org/repo1",
&[
(
"public/service.proto",
indoc! {r#"
syntax = "proto3";
message Service {}
"#},
),
(
"internal/admin.proto",
indoc! {r#"
syntax = "proto3";
message Admin {}
"#},
),
],
);
let result = world.fetch(toml! {
name = "e2e-test"
[repo1]
url = "org/repo1"
branch = "main"
allow_policies = ["public/*"]
});
assert_snapshot!("allow_policies_output", result.snapshot_tree());
}
#[test]
fn fetch_content_roots() {
let mut world = TestWorld::new();
world.create_repo(
"org/repo1",
&[
(
"api/proto/service.proto",
indoc! {r#"
syntax = "proto3";
message Service {}
"#},
),
(
"api/proto/model.proto",
indoc! {r#"
syntax = "proto3";
message Model {}
"#},
),
(
"internal/secret.proto",
indoc! {r#"
syntax = "proto3";
message Secret {}
"#},
),
],
);
let result = world.fetch(toml! {
name = "e2e-test"
[repo1]
url = "org/repo1"
branch = "main"
content_roots = ["api/proto"]
});
assert_snapshot!("content_roots_output", result.snapshot_tree());
}
#[test]
fn fetch_deny_policies() {
let mut world = TestWorld::new();
world.create_repo(
"org/repo1",
&[
(
"public/service.proto",
indoc! {r#"
syntax = "proto3";
message Service {}
"#},
),
(
"internal/admin.proto",
indoc! {r#"
syntax = "proto3";
message Admin {}
"#},
),
],
);
let result = world.fetch(toml! {
name = "e2e-test"
[repo1]
url = "org/repo1"
branch = "main"
deny_policies = ["internal/*"]
});
assert_snapshot!("deny_policies_output", result.snapshot_tree());
}
#[test]
fn fetch_prune() {
let mut world = TestWorld::new();
world.create_repo(
"org/repo1",
&[
(
"imported.proto",
indoc! {r#"
syntax = "proto3";
message Imported {}
"#},
),
(
"extra.proto",
indoc! {r#"
syntax = "proto3";
message Extra {}
"#},
),
],
);
world.create_repo(
"org/repo2",
&[
(
"protofetch.toml",
indoc! {r#"
name = "repo2"
[repo1]
url = "<base>/org/repo1"
protocol = "file"
branch = "main"
"#},
),
(
"service.proto",
indoc! {r#"
syntax = "proto3";
import "imported.proto";
message Service {}
"#},
),
],
);
let result = world.fetch(toml! {
name = "e2e-test"
[repo2]
url = "org/repo2"
branch = "main"
prune = true
});
assert_snapshot!("prune_output", result.snapshot_tree());
}
#[test]
fn fetch_revision_pin() {
let mut world = TestWorld::new();
world
.create_repo(
"org/repo1",
&[(
"proto/v1.proto",
indoc! {r#"
syntax = "proto3";
message V1 {}
"#},
)],
)
.add_commit(
"main",
&[(
"proto/v2.proto",
indoc! {r#"
syntax = "proto3";
message V2 {}
"#},
)],
);
let result = world.fetch(toml! {
name = "e2e-test"
[repo1]
url = "org/repo1"
revision = "<commit:main:1>"
});
assert_snapshot!("revision_pin_output", result.snapshot_tree());
assert_snapshot!("revision_pin_lockfile", result.snapshot_lockfile());
}
#[test]
fn fetch_transitive_flag() {
let mut world = TestWorld::new();
world.create_repo(
"org/repo_shared",
&[(
"shared.proto",
indoc! {r#"
syntax = "proto3";
message Shared {}
"#},
)],
);
world.create_repo(
"org/repo_a",
&[(
"a.proto",
indoc! {r#"
syntax = "proto3";
import "shared.proto";
message A {}
"#},
)],
);
let result = world.fetch(toml! {
name = "e2e-test"
[repo_a]
url = "org/repo_a"
branch = "main"
prune = true
[repo_shared]
url = "org/repo_shared"
branch = "main"
transitive = true
});
assert_snapshot!("transitive_flag_output", result.snapshot_tree());
assert_snapshot!("transitive_flag_lockfile", result.snapshot_lockfile());
}
#[test]
fn fetch_regex_policy() {
let mut world = TestWorld::new();
world.create_repo(
"org/repo1",
&[
(
"service.proto",
indoc! {r#"
syntax = "proto3";
message Service {}
"#},
),
(
"internal.proto",
indoc! {r#"
syntax = "proto3";
message Internal {}
"#},
),
],
);
let result = world.fetch(toml! {
name = "e2e-test"
[repo1]
url = "org/repo1"
branch = "main"
allow_policies = ["re://service"]
});
assert_snapshot!("regex_policy_output", result.snapshot_tree());
}
#[test]
fn fetch_partial_lock_update() {
let mut world = TestWorld::new();
world
.create_repo(
"org/repo1",
&[(
"proto/v1.proto",
indoc! {r#"
syntax = "proto3";
message V1 {}
"#},
)],
)
.add_commit(
"main",
&[(
"proto/v2.proto",
indoc! {r#"
syntax = "proto3";
message V2 {}
"#},
)],
);
world.create_repo(
"org/repo2",
&[(
"proto/b.proto",
indoc! {r#"
syntax = "proto3";
message B {}
"#},
)],
);
let result = world.fetch_with_initial_lock(
toml! {
name = "e2e-test"
[repo1]
url = "org/repo1"
branch = "main"
[repo2]
url = "org/repo2"
branch = "main"
},
LockMode::Update,
toml! {
version = 2
[[dependencies]]
name = "repo1"
url = "<base>/org/repo1"
protocol = "file"
branch = "main"
commit_hash = "<commit:main:1>"
},
);
assert_snapshot!("partial_update_output", result.snapshot_tree());
assert_snapshot!("partial_update_lockfile", result.snapshot_lockfile());
}
#[test]
fn fetch_prune_mixed_true_and_false_rules() {
let mut world = TestWorld::new();
world.create_repo(
"org/dep_inner",
&[
(
"imported.proto",
indoc! {r#"
syntax = "proto3";
message Imported {}
"#},
),
(
"extra.proto",
indoc! {r#"
syntax = "proto3";
message Extra {}
"#},
),
],
);
world.create_repo(
"org/dep_mixed",
&[
(
"protofetch.toml",
indoc! {r#"
name = "dep_mixed"
[dep_inner]
url = "<base>/org/dep_inner"
protocol = "file"
branch = "main"
"#},
),
(
"service.proto",
indoc! {r#"
syntax = "proto3";
import "imported.proto";
message Service {}
"#},
),
],
);
world.create_repo(
"org/dep_ref",
&[
(
"protofetch.toml",
indoc! {r#"
name = "dep_ref"
[dep_mixed]
url = "<base>/org/dep_mixed"
protocol = "file"
branch = "main"
"#},
),
(
"other.proto",
indoc! {r#"
syntax = "proto3";
message Other {}
"#},
),
],
);
let result = world.fetch(toml! {
name = "e2e-test"
[dep_mixed]
url = "org/dep_mixed"
branch = "main"
prune = true
[dep_ref]
url = "org/dep_ref"
branch = "main"
});
assert_snapshot!("prune_mixed_rules_output", result.snapshot_tree());
}
#[test]
fn fetch_transitive_flag_mixed_with_normal_transitive_dep() {
let mut world = TestWorld::new();
world.create_repo(
"org/shared",
&[(
"shared.proto",
indoc! {r#"
syntax = "proto3";
message Shared {}
"#},
)],
);
world.create_repo(
"org/dep_consumer",
&[
(
"protofetch.toml",
indoc! {r#"
name = "dep_consumer"
[shared]
url = "<base>/org/shared"
protocol = "file"
branch = "main"
"#},
),
(
"consumer.proto",
indoc! {r#"
syntax = "proto3";
message Consumer {}
"#},
),
],
);
let result = world.fetch(toml! {
name = "e2e-test"
[dep_consumer]
url = "org/dep_consumer"
branch = "main"
[shared]
url = "org/shared"
branch = "main"
transitive = true
});
assert_snapshot!("transitive_mixed_rules_output", result.snapshot_tree());
}
#[test]
fn fetch_allow_policies_merged_across_duplicate_deps() {
let mut world = TestWorld::new();
world.create_repo(
"org/shared",
&[
(
"from_root/service.proto",
indoc! {r#"
syntax = "proto3";
message Service {}
"#},
),
(
"from_foo/model.proto",
indoc! {r#"
syntax = "proto3";
message Model {}
"#},
),
],
);
world.create_repo(
"org/foo",
&[
(
"protofetch.toml",
indoc! {r#"
name = "foo"
[shared]
url = "<base>/org/shared"
protocol = "file"
branch = "main"
allow_policies = ["from_foo/*"]
"#},
),
(
"foo.proto",
indoc! {r#"
syntax = "proto3";
message Foo {}
"#},
),
],
);
let result = world.fetch(toml! {
name = "e2e-test"
[shared]
url = "org/shared"
branch = "main"
allow_policies = ["from_root/*"]
[foo]
url = "org/foo"
branch = "main"
});
assert_snapshot!("allow_policies_merged_output", result.snapshot_tree());
}