Skip to content
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

feat: adds null migrator #31

Merged
merged 2 commits into from
Dec 12, 2023

Conversation

sam-berning
Copy link
Contributor

Issue #, if available: #30

Description of changes:

Adds a NullMigrator that can be used with settings with only one version. This removes some of the boilerplate when developing a new extension.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link
Contributor

@cbgbt cbgbt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Just a few nits.

Comment on lines 33 to 35
if models.len() != 1 {
return Err(NullMigratorError::TooManyModelVersions);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if models.len() != 1 {
return Err(NullMigratorError::TooManyModelVersions);
}
snafu::ensure!(models.len() == 1, NullMigratorError::TooManyModelVersionsSnafu);

Comment on lines 11 to 12
define_model!(NullModelB, "v2");
#[test]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would separate these with some whitespace as a readability thing.

Comment on lines 6 to 8
use serde::{Deserialize, Serialize};

use super::common::define_model;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We tend not to separate use statements with whitespace, and let rustfmt handle ordering.

The exception to this is pub use statements for shaping the interface.

@cbgbt
Copy link
Contributor

cbgbt commented Dec 7, 2023

We'll want to increment the version and tag the repo appropriately so that we can pull this change into Bottlerocket. Here's the commit where that was done in the last version bump.

@sam-berning
Copy link
Contributor Author

We'll want to increment the version and tag the repo appropriately so that we can pull this change into Bottlerocket. Here's the commit where that was done in the last version bump.

New version should be 0.1.0-alpha.2, right?

@sam-berning sam-berning force-pushed the null-migrator branch 3 times, most recently from 66c4a65 to 4915376 Compare December 8, 2023 01:09
@cbgbt
Copy link
Contributor

cbgbt commented Dec 8, 2023

New version should be 0.1.0-alpha.2, right?

Yes!

Copy link
Contributor

@cbgbt cbgbt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work 🚀

Comment on lines +76 to +77
#[snafu(visibility(pub))]
pub enum NullMigratorError {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cbgbt We should strongly consider not using Snafu for pub errors. The long-and-short of it is that we are exposing a library and its traits in our public interface and it might be impossible to avoid a major version break if the Snafu library changes in some way. Can discuss.

For this PR it's fine, but I would recommend a backlog item to convert away from pub Snafu errors in favor of hand-rolled errors (they're simple, it's not a lot of boilerplate).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion. I've cut #32 to track this idea.

@@ -0,0 +1,201 @@
use anyhow::Result;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of these filenames, I would go with

bottlerocket-settings-sdk/tests/migration_validation/linear.rs
bottlerocket-settings-sdk/tests/migration_validation/null.rs

Comment on lines 14 to 19
assert!(matches!(
NullMigratorExtensionBuilder::with_name("null-migrator")
.with_models(vec![BottlerocketSetting::<NullModelA>::model()])
.build(),
Ok(_)
));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or

Suggested change
assert!(matches!(
NullMigratorExtensionBuilder::with_name("null-migrator")
.with_models(vec![BottlerocketSetting::<NullModelA>::model()])
.build(),
Ok(_)
));
assert!(
NullMigratorExtensionBuilder::with_name("null-migrator")
.with_models(vec![BottlerocketSetting::<NullModelA>::model()])
.build()
.is_ok()
);

Or (this is probably best because the Error is shown in the panic text)

        NullMigratorExtensionBuilder::with_name("null-migrator")
            .with_models(vec![BottlerocketSetting::<NullModelA>::model()])
            .build()
            .unwrap();


#[test]
fn test_multiple_models() {
assert!(matches!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, can use is_err()

Signed-off-by: Sam Berning <bernings@amazon.com>
Signed-off-by: Sam Berning <bernings@amazon.com>
@sam-berning sam-berning merged commit 7a138e9 into bottlerocket-os:develop Dec 12, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants