8000 make ci less flakey by figsoda · Pull Request #870 · nix-community/nix-init · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ jobs:
name: nix-community

- name: Cargo test
run: nix develop -c cargo test e2e
run: |
mkdir -p ~/.config/nix-init
echo "access-tokens.'github.com' = '$GITHUB_TOKEN'" > ~/.config/nix-init/config.toml
nix develop -c cargo test e2e
env:
GITHUB_TOKEN: ${{ github.token }}
20 changes: 17 additions & 3 deletions tests/e2e.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::{
fs::{File, create_dir_all},
fs::{File, create_dir_all, read_to_string},
io::Write,
};

use tempfile::TempDir;
use toml::{Table, Value};
use trycmd::TestCases;
use which::which;
use xdg::BaseDirectories;

#[test]
fn e2e() {
Expand All @@ -14,15 +16,27 @@ fn e2e() {
let dir = tmp.join("nix-init");

create_dir_all(&dir).unwrap();

let mut cfg: Table = toml::from_str(include_str!("default-config.toml")).unwrap();
if let Some(tokens) = access_tokens() {
cfg.insert("access-tokens".into(), tokens);
}
File::create(dir.join("config.toml"))
.unwrap()
.write_all(include_bytes!("default-config.toml"))
.write_all(toml::to_string(&cfg).unwrap().as_bytes())
.unwrap();

TestCases::new()
.default_bin_name("nix-init")
.register_bin("mv", which("mv"))
.env("XDG_CONFIG_DIRS", tmp.to_str().unwrap())
.env("XDG_CONFIG_HOME", tmp.to_str().unwrap())
.case("tests/cmd/**/*.md")
.case("tests/cmd/**/*.toml");
}

fn access_tokens() -> Option<Value> {
let path = BaseDirectories::with_prefix("nix-init").find_config_file("config.toml")?;
toml::from_str::<Table>(&read_to_string(path).ok()?)
.ok()?
.remove("access-tokens")
}
0