Skip to content

Commit

Permalink
Added test for ghctl repo config get
Browse files Browse the repository at this point in the history
  • Loading branch information
aisrael committed Dec 30, 2024
1 parent bb88458 commit 97c5c04
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
21 changes: 21 additions & 0 deletions features/config.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Feature: Repository management features

Scenario: Fetch repository configuration as YAML

Given a valid GITHUB_TOKEN is set
When the following command is run:
```
ghctl repo config get gitsudo-io/ghctl
```
Then the output YAML should contain:
```
teams:
a-team: maintain
branch_protection_rules:
main:
require_pull_request:
required_approving_review_count: 1
dismiss_stale_reviews: false
require_code_owner_reviews: false
enforce_admins: false
```
13 changes: 13 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ async fn the_output_should_contain(world: &mut CliWorld, step: &Step) {
assert!(actual_output.contains(expected_output));
}

#[then(expr = "the output YAML should contain:")]
async fn the_output_should_contain_yaml(world: &mut CliWorld, step: &Step) {
assert!(world.command_output.is_some());
// For some reason, the output docstring has a leading newline
let docstring = step.docstring().unwrap();
let trimmed_docstring = docstring.strip_prefix('\n').unwrap();
let expected_output: serde_yaml::Value = serde_yaml::from_str(trimmed_docstring).unwrap();
let actual_output = world.command_output.as_ref().unwrap();
let actual_output_as_yaml: serde_yaml::Value = serde_yaml::from_str(actual_output).unwrap();
assert_eq!(expected_output, actual_output_as_yaml);
}

#[then(expr = "stderr should contain:")]
async fn stderr_should_contain(world: &mut CliWorld, step: &Step) {
assert!(world.command_stderr.is_some());
Expand Down Expand Up @@ -106,4 +118,5 @@ async fn main() {

CliWorld::run("features/cli.feature").await;
CliWorld::run("features/repos.feature").await;
CliWorld::run("features/config.feature").await;
}

0 comments on commit 97c5c04

Please sign in to comment.