diff options
author | Matan Kushner <hello@matchai.me> | 2019-04-28 13:34:46 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-28 13:34:46 -0400 |
commit | 0872d524caa91005c696a6904bd6987df8b0e509 (patch) | |
tree | 9788e935ba251475c68cbf11d469a3f4cafc1248 /tests | |
parent | 5980a0a845e78ffbcc0b0da243a01ffa42d3643b (diff) |
Add docker for integration tests (#37)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Dockerfile | 36 | ||||
-rw-r--r-- | tests/directory.rs | 20 | ||||
-rw-r--r-- | tests/nodejs.rs | 56 |
3 files changed, 105 insertions, 7 deletions
diff --git a/tests/Dockerfile b/tests/Dockerfile new file mode 100644 index 000000000..992e31ea3 --- /dev/null +++ b/tests/Dockerfile @@ -0,0 +1,36 @@ +FROM rust:latest + +# Install Node.js +ENV NODE_VERSION 12.0.0 +RUN curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash \ + && . $HOME/.nvm/nvm.sh \ + && nvm install $NODE_VERSION \ + && nvm alias default $NODE_VERSION \ + && nvm use default +ENV PATH /root/.nvm/versions/node/v$NODE_VERSION/bin:$PATH +# Check that Node.js was correctly installed +RUN node --version + +# Create blank project +RUN USER=root cargo new --bin starship +WORKDIR /starship + +# We want dependencies cached, so copy those first +COPY ./Cargo.lock ./Cargo.lock +COPY ./Cargo.toml ./Cargo.toml + +# Cargo.toml will fail to parse without my_benchmark +RUN mkdir benches +RUN touch benches/my_benchmark.rs + +# This is a dummy build to get dependencies cached +RUN cargo build --release + +# Delete the dummy build +RUN rm -rf /starship + +# Create the directory for the real source files +RUN mkdir starship +WORKDIR /starship + +CMD [ "cargo", "test", "--", "--ignored"] diff --git a/tests/directory.rs b/tests/directory.rs index e7c0d1cd0..2eb20f486 100644 --- a/tests/directory.rs +++ b/tests/directory.rs @@ -1,4 +1,5 @@ use ansi_term::Color; +use dirs::home_dir; use git2::Repository; use starship::segment::Segment; use std::fs; @@ -25,7 +26,8 @@ fn home_directory() -> io::Result<()> { #[test] #[ignore] fn directory_in_home() -> io::Result<()> { - let dir = Path::new("~/starship/engine"); + let dir = home_dir().unwrap().join("starship/engine"); + fs::create_dir_all(&dir)?; let expected = Segment::new("dir") .set_value("~/starship/engine") @@ -40,7 +42,8 @@ fn directory_in_home() -> io::Result<()> { #[test] #[ignore] fn truncated_directory_in_home() -> io::Result<()> { - let dir = Path::new("~/starship/engine/schematics"); + let dir = home_dir().unwrap().join("starship/engine/schematics"); + fs::create_dir_all(&dir)?; let expected = Segment::new("dir") .set_value("starship/engine/schematics") @@ -67,12 +70,11 @@ fn root_directory() -> io::Result<()> { } #[test] -#[ignore] fn directory_in_root() -> io::Result<()> { - let dir = Path::new("/private"); + let dir = Path::new("/opt"); let expected = Segment::new("dir") - .set_value("/private") + .set_value("/opt") .set_style(Color::Cyan.bold()) .output(); let actual = common::render_segment("dir", &dir); @@ -84,10 +86,11 @@ fn directory_in_root() -> io::Result<()> { #[test] #[ignore] fn truncated_directory_in_root() -> io::Result<()> { - let dir = Path::new("/private/var/folders/3s"); + let dir = Path::new("/opt/starship/thrusters/rocket"); + fs::create_dir_all(&dir)?; let expected = Segment::new("dir") - .set_value("var/folders/3s") + .set_value("starship/thrusters/rocket") .set_style(Color::Cyan.bold()) .output(); let actual = common::render_segment("dir", &dir); @@ -97,6 +100,7 @@ fn truncated_directory_in_root() -> io::Result<()> { } #[test] +#[ignore] fn git_repo_root() -> io::Result<()> { let tmp_dir = TempDir::new()?; let repo_dir = tmp_dir.path().join("rocket-controls"); @@ -115,6 +119,7 @@ fn git_repo_root() -> io::Result<()> { } #[test] +#[ignore] fn directory_in_git_repo() -> io::Result<()> { let tmp_dir = TempDir::new()?; let repo_dir = tmp_dir.path().join("rocket-controls"); @@ -134,6 +139,7 @@ fn directory_in_git_repo() -> io::Result<()> { } #[test] +#[ignore] fn truncated_directory_in_git_repo() -> io::Result<()> { let tmp_dir = TempDir::new()?; let repo_dir = tmp_dir.path().join("rocket-controls"); diff --git a/tests/nodejs.rs b/tests/nodejs.rs new file mode 100644 index 000000000..fe07a0cd4 --- /dev/null +++ b/tests/nodejs.rs @@ -0,0 +1,56 @@ +use ansi_term::Color; +use starship::segment::Segment; +use std::fs::{self, File}; +use std::io; +use tempfile::TempDir; + +mod common; + +#[test] +#[ignore] +fn folder_with_package_json() -> io::Result<()> { + let dir = TempDir::new()?; + File::create(dir.path().join("package.json"))?; + + let expected = Segment::new("node") + .set_value("⬢ v12.0.0") + .set_style(Color::Green.bold()) + .output(); + let actual = common::render_segment("nodejs", &dir.path()); + assert_eq!(expected, actual); + + Ok(()) +} + +#[test] +#[ignore] +fn folder_with_js_file() -> io::Result<()> { + let dir = TempDir::new()?; + File::create(dir.path().join("index.js"))?; + + let expected = Segment::new("node") + .set_value("⬢ v12.0.0") + .set_style(Color::Green.bold()) + .output(); + let actual = common::render_segment("nodejs", &dir.path()); + assert_eq!(expected, actual); + + Ok(()) +} + +#[test] +#[ignore] +fn folder_with_node_modules() -> io::Result<()> { + let dir = TempDir::new()?; + let node_modules = dir.path().join("node_modules"); + fs::create_dir_all(&node_modules)?; + + let expected = Segment::new("node") + .set_value("⬢ v12.0.0") + .set_style(Color::Green.bold()) + .output(); + let actual = common::render_segment("nodejs", &dir.path()); + assert_eq!(expected, actual); + + Ok(()) +} |