1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use super::common::*;
/// Where can we find the volume we want to map into a container?
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct Volume {
/// The name of the Docker volume driver to use. Defaults to
/// `"local"`.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub driver: Option<RawOr<String>>,
/// Key-value options to pass to the volume driver.
///
/// TODO LOW: We probably shouldn't allow the "list" variant here, but
/// we're lazy and we want the reset of the machinery provided by
/// deserialize_map_or_key_value_list.
///
/// TODO LOW: Clear on merge if `driver` changes, like we do for
/// `Logging` options.
#[serde(
default,
skip_serializing_if = "BTreeMap::is_empty",
deserialize_with = "deserialize_map_or_key_value_list"
)]
pub driver_opts: BTreeMap<String, RawOr<String>>,
/// If this is true, then the volume was created outside of
/// `docker-compose`. This option is mutually exclusive with the
/// `driver` options.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub external: Option<bool>,
/// Docker labels for this volume, specifying various sorts of
/// custom metadata.
#[serde(
default,
skip_serializing_if = "BTreeMap::is_empty",
deserialize_with = "deserialize_map_or_key_value_list"
)]
pub labels: BTreeMap<String, RawOr<String>>,
/// PRIVATE. Mark this struct as having unknown fields for future
/// compatibility. This prevents direct construction and exhaustive
/// matching. This needs to be be public because of
/// http://stackoverflow.com/q/39277157/12089
#[doc(hidden)]
#[serde(default, skip_serializing, skip_deserializing)]
pub _hidden: (),
}
derive_standard_impls_for!(Volume, {
driver, driver_opts, external, labels, _hidden
});
#[test]
fn empty_volume_can_be_converted_from_and_to_yaml() {
let yaml = r#"---
{}"#;
assert_roundtrip!(Volume, yaml);
}
#[test]
fn volume_with_driver_can_be_converted_from_and_to_yaml() {
let yaml = r#"---
driver: sample
driver_opts:
file_share: myshare
labels:
com.example: foo
"#;
assert_roundtrip!(Volume, yaml);
}
#[test]
fn external_volume_can_be_converted_from_and_to_yaml() {
let yaml = r#"---
external: true
"#;
assert_roundtrip!(Volume, yaml);
}