Skip to content

Commit deb49e4

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 09608c3 commit deb49e4

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
@@ -870,13 +870,17 @@ where
870870
meta: value.meta.take().unwrap_or_default().item,
871871
compat: value.compat.take().unwrap_or_default(),
872872
deprecated: value.deprecated.take().unwrap_or_default(),
873-
sources: value
874-
.sources
875-
.take()
876-
.unwrap_or_default()
877-
.iter()
878-
.map(|l| l.item.clone())
879-
.collect_vec(),
873+
sources: if value.sources.is_none() {
874+
vec![SourceSpec::default()]
875+
} else {
876+
value
877+
.sources
878+
.take()
879+
.expect("list of sources")
880+
.iter()
881+
.map(|l| l.item.clone())
882+
.collect_vec()
883+
},
880884
build: match value.build.take() {
881885
Some(build_spec) if !value.check_build_spec => {
882886
// Safety: see the SpecVisitor::package constructor

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

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

0 commit comments

Comments
 (0)