Skip to content

Commit eb80cee

Browse files
authored
fix: Semver version pre field doesn't contain dash (-) (#156)
This fixes the helm repo selection based on the parsed version. The old code had several short-comings: - The `pre` field doesn't include the dash used to separate version from pre. The matching however included this dash, resulting in wrong repo selection. - Versions where `pre` starts with `pr` didn't probably select the Helm test repo.
1 parent 37ca850 commit eb80cee

File tree

4 files changed

+82
-5
lines changed

4 files changed

+82
-5
lines changed

Cargo.lock

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ phf_codegen = "0.11"
3636
rand = "0.8"
3737
regex = "1.9"
3838
reqwest = { version = "0.11", default-features = false, features = ["rustls-tls"] }
39+
rstest = "0.18"
3940
semver = { version = "1.0", features = ["serde"] }
4041
serde = { version = "1.0", features = ["derive"] }
4142
serde_json = "1.0"

rust/stackable-cockpit/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ tracing.workspace = true
3434
url.workspace = true
3535
utoipa = { workspace = true, optional = true }
3636
which.workspace = true
37+
38+
[dev-dependencies]
39+
rstest.workspace = true

rust/stackable-cockpit/src/platform/operator/mod.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,17 @@ impl OperatorSpec {
158158
/// Returns the repo used by Helm based on the specified version
159159
pub fn helm_repo_name(&self) -> String {
160160
match &self.version {
161-
Some(version) if version.pre.as_str() == "-nightly" => HELM_REPO_NAME_DEV,
162-
Some(version) if version.pre.as_str() == "-dev" => HELM_REPO_NAME_DEV,
163-
Some(version) if version.pre.as_str() == "-pr" => HELM_REPO_NAME_TEST,
164-
Some(_) => HELM_REPO_NAME_STABLE,
161+
Some(version) => match version.pre.as_str() {
162+
"nightly" => HELM_REPO_NAME_DEV,
163+
"dev" => HELM_REPO_NAME_DEV,
164+
v => {
165+
if v.starts_with("pr") {
166+
HELM_REPO_NAME_TEST
167+
} else {
168+
HELM_REPO_NAME_STABLE
169+
}
170+
}
171+
},
165172
None => HELM_REPO_NAME_DEV,
166173
}
167174
.into()
@@ -211,9 +218,13 @@ impl OperatorSpec {
211218

212219
#[cfg(test)]
213220
mod test {
221+
use rstest::rstest;
214222
use semver::Version;
215223

216-
use crate::platform::operator::{OperatorSpec, SpecParseError};
224+
use crate::{
225+
constants::{HELM_REPO_NAME_DEV, HELM_REPO_NAME_STABLE, HELM_REPO_NAME_TEST},
226+
platform::operator::{OperatorSpec, SpecParseError},
227+
};
217228

218229
#[test]
219230
fn simple_operator_spec() {
@@ -260,4 +271,15 @@ mod test {
260271
Err(err) => assert!(matches!(err, SpecParseError::InvalidEqualSignCount)),
261272
}
262273
}
274+
275+
#[rstest]
276+
#[case("airflow=0.0.0-nightly", HELM_REPO_NAME_DEV)]
277+
#[case("airflow=0.0.0-pr123", HELM_REPO_NAME_TEST)]
278+
#[case("airflow=0.0.0-dev", HELM_REPO_NAME_DEV)]
279+
#[case("airflow=1.2.3", HELM_REPO_NAME_STABLE)]
280+
#[case("airflow", HELM_REPO_NAME_DEV)]
281+
fn repo_name(#[case] input: &str, #[case] repo: &str) {
282+
let spec = OperatorSpec::try_from(input).unwrap();
283+
assert_eq!(spec.helm_repo_name(), repo);
284+
}
263285
}

0 commit comments

Comments
 (0)