Skip to content

Commit

Permalink
tests: add yare for parameterised testing (#25)
Browse files Browse the repository at this point in the history
* tests: add yare

* tests: reorganise `pull_request`

* tests: reorganise `repository`

* chore: rename variable

* tests: reorganise `issues`

* tests: reorganise `discussion`

* tests: reorganise `issue_comment`

* tests: reorganise `pull_request_review`

* tests: reorganise `membership`

* chore: reformat
  • Loading branch information
sgoudham authored Sep 22, 2024
1 parent ae23947 commit 5eed400
Show file tree
Hide file tree
Showing 30 changed files with 157 additions and 284 deletions.
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ pr-run-mode = "plan"

[dev-dependencies]
insta = { version = "1.40.0", features = ["yaml"] }
yare = "3.0.0"
2 changes: 1 addition & 1 deletion snapshots/issue_comment/created.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: src/main.rs
source: src/events/issue_comment.rs
info:
author_name_length: 8
colour_hex: "#A6E3A1"
Expand Down
2 changes: 1 addition & 1 deletion snapshots/issue_comment/created_on_pull_request.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: src/main.rs
source: src/events/issue_comment.rs
info:
author_name_length: 7
colour_hex: "#89B4FA"
Expand Down
3 changes: 1 addition & 2 deletions snapshots/issues/closed.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: src/main.rs
assertion_line: 728
source: src/events/issues.rs
info:
author_name_length: 8
colour_hex: "#A6E3A1"
Expand Down
3 changes: 1 addition & 2 deletions snapshots/issues/opened.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: src/main.rs
assertion_line: 741
source: src/events/issues.rs
info:
author_name_length: 8
colour_hex: "#A6E3A1"
Expand Down
3 changes: 1 addition & 2 deletions snapshots/issues/reopened.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: src/main.rs
assertion_line: 773
source: src/events/issues.rs
info:
author_name_length: 8
colour_hex: "#A6E3A1"
Expand Down
2 changes: 1 addition & 1 deletion snapshots/membership/added.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: src/main.rs
source: src/events/membership.rs
info:
author_name_length: 8
colour_hex: "#1E1E2E"
Expand Down
2 changes: 1 addition & 1 deletion snapshots/membership/removed.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: src/main.rs
source: src/events/membership.rs
info:
author_name_length: 8
colour_hex: "#1E1E2E"
Expand Down
3 changes: 1 addition & 2 deletions snapshots/pull_request/closed.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: src/main.rs
assertion_line: 673
source: src/events/pull_request.rs
info:
author_name_length: 8
colour_hex: "#89B4FA"
Expand Down
3 changes: 1 addition & 2 deletions snapshots/pull_request/opened.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: src/main.rs
assertion_line: 641
source: src/events/pull_request.rs
info:
author_name_length: 8
colour_hex: "#89B4FA"
Expand Down
3 changes: 1 addition & 2 deletions snapshots/pull_request/opened_by_bot.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: src/main.rs
assertion_line: 657
source: src/events/pull_request.rs
info:
author_name_length: 13
colour_hex: "#89B4FA"
Expand Down
2 changes: 1 addition & 1 deletion snapshots/pull_request/reopened.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: src/main.rs
source: src/events/pull_request.rs
info:
author_name_length: 8
colour_hex: "#89B4FA"
Expand Down
2 changes: 1 addition & 1 deletion snapshots/pull_request_review/approved.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: src/main.rs
source: src/events/pull_request_review.rs
info:
author_name_length: 8
colour_hex: "#89B4FA"
Expand Down
2 changes: 1 addition & 1 deletion snapshots/pull_request_review/changes_requested.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: src/main.rs
source: src/events/pull_request_review.rs
info:
author_name_length: 8
colour_hex: "#89B4FA"
Expand Down
2 changes: 1 addition & 1 deletion snapshots/pull_request_review/commented.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: src/main.rs
source: src/events/pull_request_review.rs
info:
author_name_length: 8
colour_hex: "#89B4FA"
Expand Down
2 changes: 1 addition & 1 deletion snapshots/repository/created.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: src/main.rs
source: src/events/repository.rs
info:
author_name_length: 8
colour_hex: "#F9E2AF"
Expand Down
2 changes: 1 addition & 1 deletion snapshots/repository/renamed.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: src/main.rs
source: src/events/repository.rs
info:
author_name_length: 8
colour_hex: "#F9E2AF"
Expand Down
2 changes: 1 addition & 1 deletion snapshots/repository/transferred.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: src/main.rs
source: src/events/repository.rs
info:
author_name_length: 8
colour_hex: "#F5C2E7"
Expand Down
2 changes: 1 addition & 1 deletion src/events/commit_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mod tests {
fn created() {
let payload = include_str!("../../fixtures/commit_comment/created.json");
let TestConfig {
event,
webhook_event: event,
mut settings,
} = TestConfig::new("commit_comment", payload);

Expand Down
55 changes: 16 additions & 39 deletions src/events/discussion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,48 +74,25 @@ mod tests {
make_embed,
tests::{embed_context, TestConfig},
};

#[test]
fn created() {
let payload = include_str!("../../fixtures/discussion/created.json");
let TestConfig {
event,
mut settings,
} = TestConfig::new("discussion", payload);

let embed = make_embed(event)
.expect("make_embed should succeed")
.expect("event fixture can be turned into an embed");

settings.set_info(&embed_context(&embed));
settings.bind(|| insta::assert_yaml_snapshot!(embed));
}

#[test]
fn closed() {
let payload = include_str!("../../fixtures/discussion/closed.json");
let TestConfig {
event,
mut settings,
} = TestConfig::new("discussion", payload);

let embed = make_embed(event)
.expect("make_embed should succeed")
.expect("event fixture can be turned into an embed");

settings.set_info(&embed_context(&embed));
settings.bind(|| insta::assert_yaml_snapshot!(embed));
}

#[test]
fn reopened() {
let payload = include_str!("../../fixtures/discussion/reopened.json");
use std::fs;
use yare::parameterized;

#[parameterized(
created = { "created" },
closed = { "closed" },
reopened = { "reopened" }
)]
fn snapshot(event_type: &str) {
let event = "discussion";
let root = env!("CARGO_MANIFEST_DIR");
let filename = format!("{root}/fixtures/{event}/{event_type}.json");
let payload = fs::read_to_string(&filename).expect("fixture exists");
let TestConfig {
event,
webhook_event,
mut settings,
} = TestConfig::new("discussion", payload);
} = TestConfig::new(event, &payload);

let embed = make_embed(event)
let embed = make_embed(webhook_event)
.expect("make_embed should succeed")
.expect("event fixture can be turned into an embed");

Expand Down
2 changes: 1 addition & 1 deletion src/events/discussion_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ mod tests {
fn created() {
let payload = include_str!("../../fixtures/discussion_comment/created.json");
let TestConfig {
event,
webhook_event: event,
mut settings,
} = TestConfig::new("discussion_comment", payload);

Expand Down
38 changes: 15 additions & 23 deletions src/events/issue_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,24 @@ mod tests {
make_embed,
tests::{embed_context, TestConfig},
};

#[test]
fn created() {
let payload = include_str!("../../fixtures/issue_comment/created.json");
let TestConfig {
event,
mut settings,
} = TestConfig::new("issue_comment", payload);

let embed = make_embed(event)
.expect("make_embed should succeed")
.expect("event fixture can be turned into an embed");

settings.set_info(&embed_context(&embed));
settings.bind(|| insta::assert_yaml_snapshot!(embed));
}

#[test]
fn created_on_pull_request() {
let payload = include_str!("../../fixtures/issue_comment/created_on_pull_request.json");
use std::fs;
use yare::parameterized;

#[parameterized(
created = { "created" },
created_on_pull_request = { "created_on_pull_request" },
)]
fn snapshot(event_type: &str) {
let event = "issue_comment";
let root = env!("CARGO_MANIFEST_DIR");
let filename = format!("{root}/fixtures/{event}/{event_type}.json");
let payload = fs::read_to_string(&filename).expect("fixture exists");
let TestConfig {
event,
webhook_event,
mut settings,
} = TestConfig::new("issue_comment", payload);
} = TestConfig::new(event, &payload);

let embed = make_embed(event)
let embed = make_embed(webhook_event)
.expect("make_embed should succeed")
.expect("event fixture can be turned into an embed");

Expand Down
55 changes: 16 additions & 39 deletions src/events/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,48 +65,25 @@ mod tests {
make_embed,
tests::{embed_context, TestConfig},
};

#[test]
fn opened() {
let payload = include_str!("../../fixtures/issues/opened.json");
let TestConfig {
event,
mut settings,
} = TestConfig::new("issues", payload);

let embed = make_embed(event)
.expect("make_embed should succeed")
.expect("event fixture can be turned into an embed");

settings.set_info(&embed_context(&embed));
settings.bind(|| insta::assert_yaml_snapshot!(embed));
}

#[test]
fn closed() {
let payload = include_str!("../../fixtures/issues/closed.json");
let TestConfig {
event,
mut settings,
} = TestConfig::new("issues", payload);

let embed = make_embed(event)
.expect("make_embed should succeed")
.expect("event fixture can be turned into an embed");

settings.set_info(&embed_context(&embed));
settings.bind(|| insta::assert_yaml_snapshot!(embed));
}

#[test]
fn reopened() {
let payload = include_str!("../../fixtures/issues/reopened.json");
use std::fs;
use yare::parameterized;

#[parameterized(
opened = { "opened" },
closed = { "closed" },
reopened = { "reopened" }
)]
fn snapshot(event_type: &str) {
let event = "issues";
let root = env!("CARGO_MANIFEST_DIR");
let filename = format!("{root}/fixtures/{event}/{event_type}.json");
let payload = fs::read_to_string(&filename).expect("fixture exists");
let TestConfig {
event,
webhook_event,
mut settings,
} = TestConfig::new("issues", payload);
} = TestConfig::new(event, &payload);

let embed = make_embed(event)
let embed = make_embed(webhook_event)
.expect("make_embed should succeed")
.expect("event fixture can be turned into an embed");

Expand Down
Loading

0 comments on commit 5eed400

Please sign in to comment.