-
-
Notifications
You must be signed in to change notification settings - Fork 15
test(stackable-versioned): Add snapshot testing #881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
313d441
test: Add default snapshot testing
Techassi 59b98ed
Merge branch 'main' into test/crd-versioning-snapshot
Techassi 94eb913
chore: Accept snapshots
Techassi cd18ac6
test: Rename basic snapshot test
Techassi 18068e8
Update crates/stackable-versioned-macros/fixtures/README.md
Techassi a61a48d
Merge branch 'main' into test/crd-versioning-snapshot
Techassi cf1ec21
chore: Update snapshot testing README
Techassi 64c04c2
chore: Mark .snap files as generated
Techassi 882d8fa
chore: Add k8s snapshot test, rework test utils
Techassi ff2fd24
chore: Move compile-fail tests
Techassi 58b03e7
test: Add k8s feature gate
Techassi de30b50
test: Update stderr output files
Techassi 4546044
chore: Mark .stderr files as generated
Techassi 7dbd4d0
chore: Add changelog entry
Techassi 7bebb3a
chore: Partial revert of ff2fd24
Techassi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.stderr linguist-generated | ||
*.snap linguist-generated |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Snapshot Testing | ||
|
||
> [!NOTE] | ||
> Also see the compile-fail tests, described [here](../tests/README.md). | ||
|
||
This folder contains fixtures for snapshot testing the `#[versioned()]` macro. Snapshot testing is | ||
done using the [insta] crate. It provides a [CLI tool][insta-cli] called `cargo-insta` and a | ||
[VS Code extension][insta-ext]. | ||
|
||
Test inputs and snapshots of the expected output are located in the `fixtures` folder. There are two | ||
inputs to the `#[versioned()]` macro because it is an attribute macro: | ||
|
||
> The first TokenStream is the delimited token tree following the attribute’s name, not including | ||
> the outer delimiters. If the attribute is written as a bare attribute name, the attribute | ||
> TokenStream is empty. The second TokenStream is the rest of the item including other attributes on | ||
> the item. | ||
> | ||
> _(Taken from the [Rust reference][rust-ref])_ | ||
|
||
Because of that, a special delimiter is used in the input files which separates the two inputs while | ||
still enabling developers to write valid Rust code. The delimiter is `// ---\n`. Most of the inner | ||
workings are located in [this file](../src/test_utils.rs). | ||
|
||
```rust | ||
#[versioned( | ||
version(name = "v1alpha1"), | ||
version(name = "v1beta1"), | ||
version(name = "v1") | ||
)] | ||
// --- <- See here! | ||
pub(crate) struct Foo { | ||
#[versioned( | ||
changed(since = "v1beta1", from_name = "jjj", from_type = "u8"), | ||
changed(since = "v1", from_type = "u16"), | ||
)] | ||
bar: usize, | ||
baz: bool, | ||
} | ||
``` | ||
|
||
## Recommended Workflow | ||
|
||
First, add new input files (which automatically get picked up by `insta`) to the `fixtures/inputs` | ||
folder. Make sure the delimiter is placed correctly between the attribute and the container | ||
definition. Doc comments on the container have to be placed after the delimiter. Next, generate the | ||
snapshot files (initially not accepted) by running | ||
|
||
```shell | ||
cargo insta test -p stackable-versioned-macros | ||
``` | ||
|
||
This command will place the new snapshot files (with a `.new` extension) in the `fixtures/snapshots` | ||
folder. These new snapshot files must not appear on `main`, but can be shared on branches for | ||
collaboration. To review them, run the `cargo insta review` command, then accept or fix the | ||
snapshots. Once all are accepted (ie: no `.new` files remaining), check in the files. | ||
|
||
[rust-ref]: https://doc.rust-lang.org/reference/procedural-macros.html#attribute-macros | ||
[insta-ext]: https://insta.rs/docs/vscode/ | ||
[insta-cli]: https://insta.rs/docs/cli/ | ||
[insta]: https://insta.rs/ |
38 changes: 38 additions & 0 deletions
38
crates/stackable-versioned-macros/fixtures/inputs/default/attribute_enum.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#[versioned( | ||
version(name = "v1alpha1"), | ||
version( | ||
name = "v1beta1", | ||
doc = r#" | ||
Additional docs for this version which are purposefully long to | ||
show how manual line wrapping works. \ | ||
Multi-line docs are also supported, as per regular doc-comments. | ||
"# | ||
), | ||
version(name = "v1beta2"), | ||
version(name = "v1"), | ||
version(name = "v2"), | ||
options(skip(from)) | ||
)] | ||
// --- | ||
#[derive(Default)] | ||
enum Foo { | ||
/// This variant is available in every version (so far). | ||
#[default] | ||
Foo, | ||
|
||
/// Keep the main field docs the same, even after the field is | ||
/// deprecated. | ||
#[versioned(deprecated(since = "v1beta1", note = "gone"))] | ||
DeprecatedBar, | ||
|
||
/// This is for baz | ||
#[versioned(added(since = "v1beta1"))] | ||
// Just to check stackable-versioned deprecation warning appears. | ||
// #[deprecated] | ||
Baz, | ||
|
||
/// This is will keep changing over time. | ||
#[versioned(changed(since = "v1beta1", from_name = "Qoox"))] | ||
#[versioned(changed(since = "v1", from_name = "Qaax"))] | ||
Quux, | ||
} |
35 changes: 35 additions & 0 deletions
35
crates/stackable-versioned-macros/fixtures/inputs/default/attribute_struct.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#[versioned( | ||
version(name = "v1alpha1"), | ||
version( | ||
name = "v1beta1", | ||
doc = r#" | ||
Additional docs for this version which are purposefully long to | ||
show how manual line wrapping works. \ | ||
Multi-line docs are also supported, as per regular doc-comments. | ||
"# | ||
), | ||
version(name = "v1beta2"), | ||
version(name = "v1"), | ||
version(name = "v2"), | ||
options(skip(from)) | ||
)] | ||
// --- | ||
/// Test | ||
#[derive(Default)] | ||
struct Foo { | ||
/// This field is available in every version (so far). | ||
foo: String, | ||
|
||
/// Keep the main field docs the same, even after the field is deprecated. | ||
#[versioned(deprecated(since = "v1beta1", note = "gone"))] | ||
deprecated_bar: String, | ||
|
||
/// This is for baz | ||
#[versioned(added(since = "v1beta1"))] | ||
baz: String, | ||
|
||
/// This is will keep changing over time. | ||
#[versioned(changed(since = "v1beta1", from_name = "qoox"))] | ||
#[versioned(changed(since = "v1", from_name = "qaax"))] | ||
quux: String, | ||
} |
18 changes: 18 additions & 0 deletions
18
crates/stackable-versioned-macros/fixtures/inputs/default/basic_struct.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#[versioned( | ||
version(name = "v1alpha1", deprecated), | ||
version(name = "v1beta1"), | ||
version(name = "v1"), | ||
version(name = "v2"), | ||
version(name = "v3") | ||
)] | ||
// --- | ||
pub(crate) struct Foo { | ||
#[versioned( | ||
changed(since = "v1beta1", from_name = "jjj", from_type = "u8"), | ||
changed(since = "v1", from_type = "u16"), | ||
deprecated(since = "v2", note = "not empty") | ||
)] | ||
/// Test | ||
deprecated_bar: usize, | ||
baz: bool, | ||
} |
13 changes: 13 additions & 0 deletions
13
crates/stackable-versioned-macros/fixtures/inputs/default/deprecate_enum.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#[versioned( | ||
version(name = "v1alpha1"), | ||
version(name = "v1beta1"), | ||
version(name = "v1"), | ||
version(name = "v2"), | ||
version(name = "v3") | ||
)] | ||
// --- | ||
enum Foo { | ||
#[versioned(deprecated(since = "v1"))] | ||
DeprecatedBar, | ||
Baz, | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.