Merge "aconfig: add dump --format=textproto"
This commit is contained in:
@@ -203,6 +203,7 @@ pub enum DumpFormat {
|
||||
Text,
|
||||
Debug,
|
||||
Protobuf,
|
||||
Textproto,
|
||||
}
|
||||
|
||||
pub fn dump_parsed_flags(mut input: Vec<Input>, format: DumpFormat) -> Result<Vec<u8>> {
|
||||
@@ -234,6 +235,10 @@ pub fn dump_parsed_flags(mut input: Vec<Input>, format: DumpFormat) -> Result<Ve
|
||||
DumpFormat::Protobuf => {
|
||||
parsed_flags.write_to_vec(&mut output)?;
|
||||
}
|
||||
DumpFormat::Textproto => {
|
||||
let s = protobuf::text_format::print_to_string_pretty(&parsed_flags);
|
||||
output.extend_from_slice(s.as_bytes());
|
||||
}
|
||||
}
|
||||
Ok(output)
|
||||
}
|
||||
@@ -314,85 +319,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_dump_protobuf_format() {
|
||||
let text_proto = r#"
|
||||
parsed_flag {
|
||||
package: "com.android.aconfig.test"
|
||||
name: "disabled_ro"
|
||||
namespace: "aconfig_test"
|
||||
description: "This flag is DISABLED + READ_ONLY"
|
||||
state: DISABLED
|
||||
permission: READ_ONLY
|
||||
trace {
|
||||
source: "tests/test.aconfig"
|
||||
state: DISABLED
|
||||
permission: READ_WRITE
|
||||
}
|
||||
trace {
|
||||
source: "tests/first.values"
|
||||
state: DISABLED
|
||||
permission: READ_ONLY
|
||||
}
|
||||
bug: "123"
|
||||
}
|
||||
parsed_flag {
|
||||
package: "com.android.aconfig.test"
|
||||
name: "disabled_rw"
|
||||
namespace: "aconfig_test"
|
||||
description: "This flag is DISABLED + READ_WRITE"
|
||||
state: DISABLED
|
||||
permission: READ_WRITE
|
||||
trace {
|
||||
source: "tests/test.aconfig"
|
||||
state: DISABLED
|
||||
permission: READ_WRITE
|
||||
}
|
||||
bug: "456"
|
||||
}
|
||||
parsed_flag {
|
||||
package: "com.android.aconfig.test"
|
||||
name: "enabled_ro"
|
||||
namespace: "aconfig_test"
|
||||
description: "This flag is ENABLED + READ_ONLY"
|
||||
state: ENABLED
|
||||
permission: READ_ONLY
|
||||
trace {
|
||||
source: "tests/test.aconfig"
|
||||
state: DISABLED
|
||||
permission: READ_WRITE
|
||||
}
|
||||
trace {
|
||||
source: "tests/first.values"
|
||||
state: DISABLED
|
||||
permission: READ_WRITE
|
||||
}
|
||||
trace {
|
||||
source: "tests/second.values"
|
||||
state: ENABLED
|
||||
permission: READ_ONLY
|
||||
}
|
||||
bug: "789"
|
||||
bug: "abc"
|
||||
}
|
||||
parsed_flag {
|
||||
package: "com.android.aconfig.test"
|
||||
name: "enabled_rw"
|
||||
namespace: "aconfig_test"
|
||||
description: "This flag is ENABLED + READ_WRITE"
|
||||
state: ENABLED
|
||||
permission: READ_WRITE
|
||||
trace {
|
||||
source: "tests/test.aconfig"
|
||||
state: DISABLED
|
||||
permission: READ_WRITE
|
||||
}
|
||||
trace {
|
||||
source: "tests/first.values"
|
||||
state: ENABLED
|
||||
permission: READ_WRITE
|
||||
}
|
||||
}
|
||||
"#;
|
||||
let expected = protobuf::text_format::parse_from_str::<ProtoParsedFlags>(text_proto)
|
||||
let expected = protobuf::text_format::parse_from_str::<ProtoParsedFlags>(
|
||||
crate::test::TEST_FLAGS_TEXTPROTO,
|
||||
)
|
||||
.unwrap()
|
||||
.write_to_bytes()
|
||||
.unwrap();
|
||||
@@ -403,6 +332,14 @@ parsed_flag {
|
||||
assert_eq!(expected, actual);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dump_textproto_format() {
|
||||
let input = parse_test_flags_as_input();
|
||||
let bytes = dump_parsed_flags(vec![input], DumpFormat::Textproto).unwrap();
|
||||
let text = std::str::from_utf8(&bytes).unwrap();
|
||||
assert_eq!(crate::test::TEST_FLAGS_TEXTPROTO.trim(), text.trim());
|
||||
}
|
||||
|
||||
fn parse_test_flags_as_input() -> Input {
|
||||
let parsed_flags = crate::test::parse_test_flags();
|
||||
let binary_proto = parsed_flags.write_to_bytes().unwrap();
|
||||
|
@@ -22,6 +22,85 @@ pub mod test_utils {
|
||||
|
||||
pub const TEST_PACKAGE: &str = "com.android.aconfig.test";
|
||||
|
||||
pub const TEST_FLAGS_TEXTPROTO: &str = r#"
|
||||
parsed_flag {
|
||||
package: "com.android.aconfig.test"
|
||||
name: "disabled_ro"
|
||||
namespace: "aconfig_test"
|
||||
description: "This flag is DISABLED + READ_ONLY"
|
||||
bug: "123"
|
||||
state: DISABLED
|
||||
permission: READ_ONLY
|
||||
trace {
|
||||
source: "tests/test.aconfig"
|
||||
state: DISABLED
|
||||
permission: READ_WRITE
|
||||
}
|
||||
trace {
|
||||
source: "tests/first.values"
|
||||
state: DISABLED
|
||||
permission: READ_ONLY
|
||||
}
|
||||
}
|
||||
parsed_flag {
|
||||
package: "com.android.aconfig.test"
|
||||
name: "disabled_rw"
|
||||
namespace: "aconfig_test"
|
||||
description: "This flag is DISABLED + READ_WRITE"
|
||||
bug: "456"
|
||||
state: DISABLED
|
||||
permission: READ_WRITE
|
||||
trace {
|
||||
source: "tests/test.aconfig"
|
||||
state: DISABLED
|
||||
permission: READ_WRITE
|
||||
}
|
||||
}
|
||||
parsed_flag {
|
||||
package: "com.android.aconfig.test"
|
||||
name: "enabled_ro"
|
||||
namespace: "aconfig_test"
|
||||
description: "This flag is ENABLED + READ_ONLY"
|
||||
bug: "789"
|
||||
bug: "abc"
|
||||
state: ENABLED
|
||||
permission: READ_ONLY
|
||||
trace {
|
||||
source: "tests/test.aconfig"
|
||||
state: DISABLED
|
||||
permission: READ_WRITE
|
||||
}
|
||||
trace {
|
||||
source: "tests/first.values"
|
||||
state: DISABLED
|
||||
permission: READ_WRITE
|
||||
}
|
||||
trace {
|
||||
source: "tests/second.values"
|
||||
state: ENABLED
|
||||
permission: READ_ONLY
|
||||
}
|
||||
}
|
||||
parsed_flag {
|
||||
package: "com.android.aconfig.test"
|
||||
name: "enabled_rw"
|
||||
namespace: "aconfig_test"
|
||||
description: "This flag is ENABLED + READ_WRITE"
|
||||
state: ENABLED
|
||||
permission: READ_WRITE
|
||||
trace {
|
||||
source: "tests/test.aconfig"
|
||||
state: DISABLED
|
||||
permission: READ_WRITE
|
||||
}
|
||||
trace {
|
||||
source: "tests/first.values"
|
||||
state: ENABLED
|
||||
permission: READ_WRITE
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
pub fn parse_test_flags() -> ProtoParsedFlags {
|
||||
let bytes = crate::commands::parse_flags(
|
||||
"com.android.aconfig.test",
|
||||
|
Reference in New Issue
Block a user