Skip to content

Commit a1b7585

Browse files
author
Nichol Yip
committed
Fixed issue where no default source spec if found when no source provided
Fixed issue with the default values for the meta struct when no values are provided Reverted du command tests back as it was related to the issue with the source spec. Signed-off-by: Nichol Yip <[email protected]>
1 parent 7eb16f6 commit a1b7585

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

crates/spk-cli/cmd-du/src/cmd_du_test.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async fn test_du_trivially_works() {
7272

7373
let mut expected_output = vec![
7474
"2local/my-pkg/1.0.0/3I42H3S6/:build/spk/pkg/my-pkg/1.0.0/3I42H3S6/options.json",
75-
"82local/my-pkg/1.0.0/3I42H3S6/:build/spk/pkg/my-pkg/1.0.0/3I42H3S6/spec.yaml",
75+
"160local/my-pkg/1.0.0/3I42H3S6/:build/spk/pkg/my-pkg/1.0.0/3I42H3S6/spec.yaml",
7676
"0local/my-pkg/1.0.0/3I42H3S6/:build/spk/pkg/my-pkg/1.0.0/3I42H3S6/build.cmpt",
7777
"17local/my-pkg/1.0.0/3I42H3S6/:build/spk/pkg/my-pkg/1.0.0/3I42H3S6/build.sh",
7878
"0local/my-pkg/1.0.0/3I42H3S6/:run/spk/pkg/my-pkg/1.0.0/3I42H3S6/options.json",
@@ -343,7 +343,7 @@ async fn test_du_summarize_output_enabled() {
343343
let mut opt = Opt::try_parse_from(["du", "local/my-pkg", "-s"]).unwrap();
344344
opt.du.run().await.unwrap();
345345

346-
let expected_output = format!("101local/my-pkg/{}", "".red());
346+
let expected_output = format!("179local/my-pkg/{}", "".red());
347347
let mut generated_output = opt.du.output.vec.lock().unwrap()[0].clone();
348348
generated_output.retain(|c| !c.is_whitespace());
349349

@@ -382,7 +382,7 @@ async fn test_du_summarize_output_is_not_enabled() {
382382
"2local/my-pkg/1.0.0/3I42H3S6/:build/spk/pkg/my-pkg/1.0.0/3I42H3S6/options.json",
383383
"0local/my-pkg/1.0.0/3I42H3S6/:build/spk/pkg/my-pkg/1.0.0/3I42H3S6/build.cmpt",
384384
"17local/my-pkg/1.0.0/3I42H3S6/:build/spk/pkg/my-pkg/1.0.0/3I42H3S6/build.sh",
385-
"82local/my-pkg/1.0.0/3I42H3S6/:build/spk/pkg/my-pkg/1.0.0/3I42H3S6/spec.yaml",
385+
"160local/my-pkg/1.0.0/3I42H3S6/:build/spk/pkg/my-pkg/1.0.0/3I42H3S6/spec.yaml",
386386
"0local/my-pkg/1.0.0/3I42H3S6/:run/spk/pkg/my-pkg/1.0.0/3I42H3S6/spec.yaml",
387387
"0local/my-pkg/1.0.0/3I42H3S6/:run/spk/pkg/my-pkg/1.0.0/3I42H3S6/options.json",
388388
"0local/my-pkg/1.0.0/3I42H3S6/:run/spk/pkg/my-pkg/1.0.0/3I42H3S6/run.cmpt",
@@ -440,7 +440,7 @@ async fn test_deprecate_flag() {
440440

441441
let mut opt_with_deprecate_flag = Opt::try_parse_from(["du", "local/my-pkg", "-ds"]).unwrap();
442442
opt_with_deprecate_flag.du.run().await.unwrap();
443-
let expected_output = format!("118local/my-pkg/{}", "DEPRECATED".red());
443+
let expected_output = format!("196local/my-pkg/{}", "DEPRECATED".red());
444444
let mut generated_output = opt_with_deprecate_flag.du.output.vec.lock().unwrap()[0].clone();
445445
generated_output.retain(|c| !c.is_whitespace());
446446
assert_eq!(expected_output, generated_output);

crates/spk-schema/src/meta.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ impl Meta {
5353
struct MetaVisitor {
5454
description: Option<String>,
5555
homepage: Option<String>,
56-
license: String,
57-
labels: BTreeMap<String, String>,
56+
license: Option<String>,
57+
labels: Option<BTreeMap<String, String>>,
5858
#[field_names_as_array(skip)]
5959
lints: Vec<String>,
6060
}
@@ -70,8 +70,8 @@ impl From<MetaVisitor> for Meta {
7070
Self {
7171
description: value.description,
7272
homepage: value.homepage,
73-
license: value.license,
74-
labels: value.labels,
73+
license: value.license.unwrap_or(Meta::default_license()),
74+
labels: value.labels.unwrap_or_default(),
7575
}
7676
}
7777
}
@@ -107,10 +107,10 @@ impl<'de> serde::de::Visitor<'de> for MetaVisitor {
107107
{
108108
while let Some(key) = map.next_key::<Stringified>()? {
109109
match key.as_str() {
110-
"description" => self.description = map.next_value::<Option<String>>()?,
111-
"homepage" => self.homepage = map.next_value::<Option<String>>()?,
112-
"license" => self.license = map.next_value::<Stringified>()?.0,
113-
"labels" => self.labels = map.next_value::<BTreeMap<String, String>>()?,
110+
"description" => self.description = Some(map.next_value::<Stringified>()?.0),
111+
"homepage" => self.homepage = Some(map.next_value::<Stringified>()?.0),
112+
"license" => self.license = Some(map.next_value::<Stringified>()?.0),
113+
"labels" => self.labels = Some(map.next_value::<BTreeMap<String, String>>()?),
114114
unknown_key => {
115115
let lint =
116116
UnknownKey::new(unknown_key, MetaVisitor::FIELD_NAMES_AS_ARRAY.to_vec());

crates/spk-schema/src/v0/spec.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -889,13 +889,17 @@ where
889889
meta: value.meta.take().unwrap_or_default().item,
890890
compat: value.compat.take().unwrap_or_default(),
891891
deprecated: value.deprecated.take().unwrap_or_default(),
892-
sources: value
893-
.sources
894-
.take()
895-
.unwrap_or_default()
896-
.iter()
897-
.map(|l| l.item.clone())
898-
.collect_vec(),
892+
sources: if value.sources.is_none() {
893+
vec![SourceSpec::default()]
894+
} else {
895+
value
896+
.sources
897+
.take()
898+
.expect("list of sources")
899+
.iter()
900+
.map(|l| l.item.clone())
901+
.collect_vec()
902+
},
899903
build: match value.build.take() {
900904
Some(build_spec) if !value.check_build_spec => {
901905
// Safety: see the SpecVisitor::package constructor

crates/spk-schema/src/v0/spec_test.rs

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ fn test_sources_relative_to_spec_file(tmpdir: tempfile::TempDir) {
4343
.unwrap()
4444
.generate_source_build(&spec_dir)
4545
.unwrap();
46+
println!("{:?}", spec);
4647
if let Some(super::SourceSpec::Local(local)) = spec.sources.get(0) {
4748
assert_eq!(local.path, spec_dir);
4849
} else {

0 commit comments

Comments
 (0)