Skip to content

Commit

Permalink
add another test
Browse files Browse the repository at this point in the history
Signed-off-by: Luke Swithenbank <[email protected]>
  • Loading branch information
lswith authored and flavio committed Sep 26, 2023
1 parent 842701b commit 3859c33
Showing 1 changed file with 87 additions and 13 deletions.
100 changes: 87 additions & 13 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,19 +366,6 @@ mod tests {
]
}"#;

const MINIMAL_CONFIG: &str = r#"
{
"architecture": "amd64",
"os": "linux",
"rootfs": {
"diff_ids": [
"sha256:c6f988f4874bb0add23a778f753c65efe992244e148a1d2ec2a8b664fb66bbd1",
"sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef"
],
"type": "layers"
}
}"#;

fn example_config() -> ConfigFile {
let config = Config {
user: Some("alice".into()),
Expand Down Expand Up @@ -447,6 +434,19 @@ mod tests {
}
}

const MINIMAL_CONFIG: &str = r#"
{
"architecture": "amd64",
"os": "linux",
"rootfs": {
"diff_ids": [
"sha256:c6f988f4874bb0add23a778f753c65efe992244e148a1d2ec2a8b664fb66bbd1",
"sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef"
],
"type": "layers"
}
}"#;

fn minimal_config() -> ConfigFile {
let rootfs = Rootfs {
r#type: "layers".into(),
Expand All @@ -467,6 +467,66 @@ mod tests {
}
}

const MINIMAL_CONFIG2: &str = r#"
{
"architecture":"arm64",
"config":{
"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],
"WorkingDir":"/"
},
"created":"2023-04-21T11:53:28.176613804Z",
"history":[{
"created":"2023-04-21T11:53:28.176613804Z",
"created_by":"COPY ./src/main.rs / # buildkit",
"comment":"buildkit.dockerfile.v0"
}],
"os":"linux",
"rootfs":{
"type":"layers",
"diff_ids":[
"sha256:267fbf1f5a9377e40a2dc65b355000111e000a35ac77f7b19a59f587d4dd778e"
]
}
}"#;

fn minimal_config2() -> ConfigFile {
let config = Some(Config {
env: vec!["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin".into()],
working_dir: Some("/".into()),
..Config::default()
});
let history = Some(vec![History {
created: Some(
Utc.datetime_from_str("2023-04-21T11:53:28.176613804Z", "%+")
.expect("parse time failed"),
),
author: None,
created_by: Some("COPY ./src/main.rs / # buildkit".into()),
comment: Some("buildkit.dockerfile.v0".into()),
empty_layer: None,
}]);

let rootfs = Rootfs {
r#type: "layers".into(),
diff_ids: vec![
"sha256:267fbf1f5a9377e40a2dc65b355000111e000a35ac77f7b19a59f587d4dd778e".into(),
],
};

ConfigFile {
architecture: Architecture::Arm64,
os: Os::Linux,
config,
rootfs,
history,
created: Some(
Utc.datetime_from_str("2023-04-21T11:53:28.176613804Z", "%+")
.expect("parse time failed"),
),
author: None,
}
}

#[test]
fn deserialize_example() {
let example = example_config();
Expand All @@ -481,6 +541,13 @@ mod tests {
assert_eq!(example, parsed);
}

#[test]
fn deserialize_minimal2() {
let example = minimal_config2();
let parsed: ConfigFile = serde_json::from_str(MINIMAL_CONFIG2).expect("parsed failed");
assert_eq!(example, parsed);
}

#[test]
fn serialize_example() {
let serialized = serde_json::to_value(&example_config()).expect("serialize failed");
Expand All @@ -494,4 +561,11 @@ mod tests {
let parsed: Value = serde_json::from_str(MINIMAL_CONFIG).expect("parsed failed");
assert_json_eq!(serialized, parsed);
}

#[test]
fn serialize_minimal2() {
let serialized = serde_json::to_value(&minimal_config2()).expect("serialize failed");
let parsed: Value = serde_json::from_str(MINIMAL_CONFIG2).expect("parsed failed");
assert_json_eq!(serialized, parsed);
}
}

0 comments on commit 3859c33

Please sign in to comment.