Skip to content

Commit 6acd8fc

Browse files
committed
Add tests.
1 parent 7cb7c83 commit 6acd8fc

3 files changed

Lines changed: 68 additions & 1 deletion

File tree

crates/config/tests/project_config_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ mod project_config {
2424

2525
#[test]
2626
#[should_panic(
27-
expected = "unknown field `unknown`, expected one of `$schema`, `dependsOn`, `deps`, `docker`, `env`, `fileGroups`, `id`, `language`, `layer`, `owners`, `project`, `stack`, `tags`, `tasks`, `toolchains`, `workspace`"
27+
expected = "unknown field `unknown`, expected one of `$schema`, `dependsOn`, `deps`, `docker`, `env`, `fileGroups`, `id`, `language`, `layer`, `owners`, `project`, `stack`, `tags`, `tasks`, `taskOptions`, `toolchains`, `workspace`"
2828
)]
2929
fn error_unknown_field() {
3030
test_load_config("moon.yml", "unknown: 123", |path| {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
language: javascript
2+
layer: library
3+
4+
taskOptions:
5+
retryCount: 7
6+
cache: false
7+
8+
tasks:
9+
inherits: {}
10+
overrides:
11+
options:
12+
retryCount: 2
13+
overrides-cache:
14+
options:
15+
cache: true

crates/task-builder/tests/tasks_builder_test.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,58 @@ tasks:
11901190
}
11911191
}
11921192

1193+
mod shared_task_options {
1194+
use super::*;
1195+
1196+
#[tokio::test(flavor = "multi_thread")]
1197+
async fn inherits_project_shared_options() {
1198+
let sandbox = create_sandbox("builder");
1199+
let container = TasksBuilderContainer::new(sandbox.path()).with_all_toolchains();
1200+
1201+
let tasks = container.build_tasks("task-options").await;
1202+
1203+
let task = tasks.get("inherits").unwrap();
1204+
1205+
assert_eq!(task.options.retry_count, 7);
1206+
assert_eq!(task.options.cache, TaskOptionCache::Enabled(false));
1207+
}
1208+
1209+
#[tokio::test(flavor = "multi_thread")]
1210+
async fn project_shared_options_override_global() {
1211+
let sandbox = create_sandbox("builder");
1212+
let container = TasksBuilderContainer::new(sandbox.path()).with_all_toolchains();
1213+
1214+
let tasks = container.build_tasks("task-options").await;
1215+
1216+
// Global `taskOptions` set `retryCount: 10`, the project lowers it to 7.
1217+
let task = tasks.get("inherits").unwrap();
1218+
1219+
assert_eq!(task.options.retry_count, 7);
1220+
}
1221+
1222+
#[tokio::test(flavor = "multi_thread")]
1223+
async fn task_can_override_project_shared_options() {
1224+
let sandbox = create_sandbox("builder");
1225+
let container = TasksBuilderContainer::new(sandbox.path()).with_all_toolchains();
1226+
1227+
let tasks = container.build_tasks("task-options").await;
1228+
1229+
let task = tasks.get("overrides").unwrap();
1230+
1231+
// Overridden by the task itself.
1232+
assert_eq!(task.options.retry_count, 2);
1233+
// Still inherited from the project.
1234+
assert_eq!(task.options.cache, TaskOptionCache::Enabled(false));
1235+
1236+
let task = tasks.get("overrides-cache").unwrap();
1237+
1238+
// Inherited from the project.
1239+
assert_eq!(task.options.retry_count, 7);
1240+
// Overridden by the task itself.
1241+
assert_eq!(task.options.cache, TaskOptionCache::Enabled(true));
1242+
}
1243+
}
1244+
11931245
mod presets {
11941246
use super::*;
11951247

0 commit comments

Comments
 (0)