LCOV - code coverage report
Current view: top level - compute_tools/tests - pg_helpers_tests.rs (source / functions) Coverage Total Hit
Test: e5024a5c05016c30dec7897aca22d1040a340f63.info Lines: 100.0 % 81 81
Test Date: 2024-11-20 11:45:54 Functions: 100.0 % 5 5

            Line data    Source code
       1              : #[cfg(test)]
       2              : mod pg_helpers_tests {
       3              :     use std::fs::File;
       4              : 
       5              :     use compute_api::spec::{ComputeSpec, GenericOption, GenericOptions, PgIdent};
       6              :     use compute_tools::pg_helpers::*;
       7              : 
       8              :     #[test]
       9            1 :     fn params_serialize() {
      10            1 :         let file = File::open("../libs/compute_api/tests/cluster_spec.json").unwrap();
      11            1 :         let spec: ComputeSpec = serde_json::from_reader(file).unwrap();
      12            1 : 
      13            1 :         assert_eq!(
      14            1 :             spec.cluster.databases.first().unwrap().to_pg_options(),
      15            1 :             "LC_COLLATE 'C' LC_CTYPE 'C' TEMPLATE template0 OWNER \"alexk\""
      16            1 :         );
      17            1 :         assert_eq!(
      18            1 :             spec.cluster.roles.first().unwrap().to_pg_options(),
      19            1 :             " LOGIN PASSWORD 'md56b1d16b78004bbd51fa06af9eda75972'"
      20            1 :         );
      21            1 :     }
      22              : 
      23              :     #[test]
      24            1 :     fn settings_serialize() {
      25            1 :         let file = File::open("../libs/compute_api/tests/cluster_spec.json").unwrap();
      26            1 :         let spec: ComputeSpec = serde_json::from_reader(file).unwrap();
      27            1 : 
      28            1 :         assert_eq!(
      29            1 :             spec.cluster.settings.as_pg_settings(),
      30            1 :             r#"fsync = off
      31            1 : wal_level = logical
      32            1 : hot_standby = on
      33            1 : neon.safekeepers = '127.0.0.1:6502,127.0.0.1:6503,127.0.0.1:6501'
      34            1 : wal_log_hints = on
      35            1 : log_connections = on
      36            1 : shared_buffers = 32768
      37            1 : port = 55432
      38            1 : max_connections = 100
      39            1 : max_wal_senders = 10
      40            1 : listen_addresses = '0.0.0.0'
      41            1 : wal_sender_timeout = 0
      42            1 : password_encryption = md5
      43            1 : maintenance_work_mem = 65536
      44            1 : max_parallel_workers = 8
      45            1 : max_worker_processes = 8
      46            1 : neon.tenant_id = 'b0554b632bd4d547a63b86c3630317e8'
      47            1 : max_replication_slots = 10
      48            1 : neon.timeline_id = '2414a61ffc94e428f14b5758fe308e13'
      49            1 : shared_preload_libraries = 'neon'
      50            1 : synchronous_standby_names = 'walproposer'
      51            1 : neon.pageserver_connstring = 'host=127.0.0.1 port=6400'
      52            1 : test.escaping = 'here''s a backslash \\ and a quote '' and a double-quote " hooray'
      53            1 : "#
      54            1 :         );
      55            1 :     }
      56              : 
      57              :     #[test]
      58            1 :     fn ident_pg_quote() {
      59            1 :         let ident: PgIdent = PgIdent::from("\"name\";\\n select 1;");
      60            1 : 
      61            1 :         assert_eq!(ident.pg_quote(), "\"\"\"name\"\";\\n select 1;\"");
      62            1 :     }
      63              : 
      64              :     #[test]
      65            1 :     fn generic_options_search() {
      66            1 :         let generic_options: GenericOptions = Some(vec![
      67            1 :             GenericOption {
      68            1 :                 name: "present_value".into(),
      69            1 :                 value: Some("value".into()),
      70            1 :                 vartype: "string".into(),
      71            1 :             },
      72            1 :             GenericOption {
      73            1 :                 name: "missed_value".into(),
      74            1 :                 value: None,
      75            1 :                 vartype: "int".into(),
      76            1 :             },
      77            1 :         ]);
      78            1 :         assert_eq!(generic_options.find("present_value"), Some("value".into()));
      79            1 :         assert_eq!(generic_options.find("missed_value"), None);
      80            1 :         assert_eq!(generic_options.find("invalid_value"), None);
      81              : 
      82            1 :         let empty_generic_options: GenericOptions = Some(vec![]);
      83            1 :         assert_eq!(empty_generic_options.find("present_value"), None);
      84            1 :         assert_eq!(empty_generic_options.find("missed_value"), None);
      85            1 :         assert_eq!(empty_generic_options.find("invalid_value"), None);
      86              : 
      87            1 :         let none_generic_options: GenericOptions = None;
      88            1 :         assert_eq!(none_generic_options.find("present_value"), None);
      89            1 :         assert_eq!(none_generic_options.find("missed_value"), None);
      90            1 :         assert_eq!(none_generic_options.find("invalid_value"), None);
      91            1 :     }
      92              : 
      93              :     #[test]
      94            1 :     fn test_escape_literal() {
      95            1 :         assert_eq!(escape_literal("test"), "'test'");
      96            1 :         assert_eq!(escape_literal("test'"), "'test'''");
      97            1 :         assert_eq!(escape_literal("test\\'"), "E'test\\\\'''");
      98            1 :         assert_eq!(escape_literal("test\\'\\'"), "E'test\\\\''\\\\'''");
      99            1 :     }
     100              : }
        

Generated by: LCOV version 2.1-beta