Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Jul 18, 2024
1 parent fc4aaef commit b709a04
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

#### 🚀 Updates

- Added a new setting to `.prototools`, `settings.builtin-plugins`, that can be used to disable all built-in plugins, or only allow a few select plugins.
- Supports a boolean or list of plugin names.
- All are enabled by default for backwards compatibility.
- Merged `proto use` and `proto install` commands. If no arguments are provided to `proto install`, it will install all configured tools.

## 0.38.3
Expand Down
21 changes: 21 additions & 0 deletions crates/cli/tests/plugins_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use proto_core::{
load_tool_from_locator, Id, PluginLocator, ProtoEnvironment, Tool, UnresolvedVersionSpec,
};
use starbase_sandbox::assert_snapshot;
use starbase_sandbox::predicates::prelude::*;
use std::env;
use std::fs;
use std::future::Future;
Expand Down Expand Up @@ -331,5 +332,25 @@ mod plugins {

// Doesn't create shims
}

#[test]
fn errors_if_disabled() {
let sandbox = create_empty_proto_sandbox();
sandbox.create_file(
".prototools",
r#"
[settings]
builtin-plugins = false
"#,
);

let assert = sandbox
.run_bin(|cmd| {
cmd.arg("install").arg("go");
})
.failure();

assert.stderr(predicate::str::contains("Unable to proceed, go"));
}
}
}
98 changes: 98 additions & 0 deletions crates/core/tests/proto_config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,104 @@ foo = "file://./test.toml"
);
}

mod builtins {
use super::*;
use proto_core::BuiltinPlugins;
use schematic::Config;

#[test]
fn can_enable() {
let sandbox = create_empty_sandbox();
sandbox.create_file(
".prototools",
r#"
[settings]
builtin-plugins = true
"#,
);

let config =
ProtoConfig::from_partial(ProtoConfig::load_from(sandbox.path(), false).unwrap());

assert_eq!(
config.settings.builtin_plugins,
BuiltinPlugins::Enabled(true)
);

assert_eq!(config.builtin_plugins().len(), 10);
}

#[test]
fn can_enable_with_list() {
let sandbox = create_empty_sandbox();
sandbox.create_file(
".prototools",
r#"
[settings]
builtin-plugins = ["node", "go"]
"#,
);

let config =
ProtoConfig::from_partial(ProtoConfig::load_from(sandbox.path(), false).unwrap());

assert_eq!(
config.settings.builtin_plugins,
BuiltinPlugins::Allowed(vec!["node".into(), "go".into()])
);

assert_eq!(config.builtin_plugins().len(), 3);
assert_eq!(
config.builtin_plugins().keys().collect::<Vec<_>>(),
["go", "internal-schema", "node"]
);
}

#[test]
fn can_disable() {
let sandbox = create_empty_sandbox();
sandbox.create_file(
".prototools",
r#"
[settings]
builtin-plugins = false
"#,
);

let config =
ProtoConfig::from_partial(ProtoConfig::load_from(sandbox.path(), false).unwrap());

assert_eq!(
config.settings.builtin_plugins,
BuiltinPlugins::Enabled(false)
);

assert_eq!(config.builtin_plugins().len(), 1);
}

#[test]
fn can_disable_with_list() {
let sandbox = create_empty_sandbox();
sandbox.create_file(
".prototools",
r#"
[settings]
builtin-plugins = []
"#,
);

let config =
ProtoConfig::from_partial(ProtoConfig::load_from(sandbox.path(), false).unwrap());

assert_eq!(
config.settings.builtin_plugins,
BuiltinPlugins::Allowed(vec![])
);

assert_eq!(config.builtin_plugins().len(), 1);
}
}

mod tool_config {
use super::*;
use rustc_hash::FxHashMap;
Expand Down

0 comments on commit b709a04

Please sign in to comment.