:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(flags): parameterize geoip person-property override tests (#61713)
Phil Haack40c414388f98
diff --git a/rust/feature-flags/src/handler/tests.rs b/rust/feature-flags/src/handler/tests.rsindex 92faef106fcf..b727c61e979e 100644--- a/rust/feature-flags/src/handler/tests.rs+++ b/rust/feature-flags/src/handler/tests.rs@@ -45,6 +45,7 @@ use common_cache::NegativeCache;use common_database::Client;use common_geoip::GeoIpClient;use reqwest::header::CONTENT_TYPE;+use rstest::rstest;use serde_json::{json, Value};use std::net::{Ipv4Addr, Ipv6Addr};use std::sync::atomic::{AtomicUsize, Ordering};@@ -88,90 +89,90 @@ fn create_test_geoip_service() -> GeoIpClient {.expect("Failed to create GeoIpService for testing")}-#[test]-fn test_geoip_enabled_with_person_properties() {- let geoip_service = create_test_geoip_service();-- let mut person_props = HashMap::new();- person_props.insert("name".to_string(), Value::String("John".to_string()));-- let result = properties::get_person_property_overrides(- false,- Some(person_props),- &IpAddr::V4(Ipv4Addr::new(8, 8, 8, 8)), // Google's public DNS, should be in the US- &geoip_service,- );-- assert!(result.is_some());- let result = result.unwrap();- assert!(result.len() > 1);- assert_eq!(result.get("name"), Some(&Value::String("John".to_string())));- assert!(result.contains_key("$geoip_country_name"));-}--#[test]-fn test_geoip_enabled_without_person_properties() {- let geoip_service = create_test_geoip_service();-- let result = properties::get_person_property_overrides(- false,- None,- &IpAddr::V4(Ipv4Addr::new(8, 8, 8, 8)), // Google's public DNS, should be in the US- &geoip_service,- );-- assert!(result.is_some());- let result = result.unwrap();- assert!(!result.is_empty());- assert!(result.contains_key("$geoip_country_name"));+enum GeoipExpected {+ /// GeoIP resolves and merges with the supplied person props (name + country keys).+ NameAndCountry,+ /// GeoIP is off, so only the supplied person prop survives.+ NameOnly,+ /// GeoIP resolves with no person props (country keys only).+ CountryOnly,+ /// Nothing to override.+ None,}-#[test]-fn test_geoip_disabled_with_person_properties() {+#[rstest]+// GeoIP on, public IP, with person props → name preserved + geoip merged+#[case(+ false,+ true,+ IpAddr::V4(Ipv4Addr::new(8, 8, 8, 8)),+ GeoipExpected::NameAndCountry+)]+// GeoIP on, public IP, no person props → geoip only+#[case(+ false,+ false,+ IpAddr::V4(Ipv4Addr::new(8, 8, 8, 8)),+ GeoipExpected::CountryOnly+)]+// GeoIP off, public IP, with person props → only the person prop survives+#[case(+ true,+ true,+ IpAddr::V4(Ipv4Addr::new(8, 8, 8, 8)),+ GeoipExpected::NameOnly+)]+// GeoIP off, public IP, no person props → nothing+#[case(+ true,+ false,+ IpAddr::V4(Ipv4Addr::new(8, 8, 8, 8)),+ GeoipExpected::None+)]+// GeoIP on, loopback IP → GeoIP is on but resolves nothing+#[case(+ false,+ false,+ IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),+ GeoipExpected::None+)]+fn test_geoip_person_property_overrides(+ #[case] geoip_disabled: bool,+ #[case] with_name: bool,+ #[case] ip: IpAddr,+ #[case] expected: GeoipExpected,+) {let geoip_service = create_test_geoip_service();+ let name = Value::String("John".to_string());- let mut person_props = HashMap::new();- person_props.insert("name".to_string(), Value::String("John".to_string()));+ let person_properties = with_name.then(|| HashMap::from([("name".to_string(), name.clone())]));let result = properties::get_person_property_overrides(- true,- Some(person_props),- &IpAddr::V4(Ipv4Addr::new(8, 8, 8, 8)),+ geoip_disabled,+ person_properties,+ &ip,&geoip_service,);- assert!(result.is_some());- let result = result.unwrap();- assert_eq!(result.len(), 1);- assert_eq!(result.get("name"), Some(&Value::String("John".to_string())));-}--#[test]-fn test_geoip_disabled_without_person_properties() {- let geoip_service = create_test_geoip_service();-- let result = properties::get_person_property_overrides(- true,- None,- &IpAddr::V4(Ipv4Addr::new(8, 8, 8, 8)),- &geoip_service,- );-- assert!(result.is_none());-}--#[test]-fn test_geoip_enabled_local_ip() {- let geoip_service = create_test_geoip_service();-- let result = properties::get_person_property_overrides(- true,- None,- &IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),- &geoip_service,- );-- assert!(result.is_none());+ match expected {+ GeoipExpected::NameAndCountry => {+ let result = result.expect("expected property overrides");+ assert!(result.len() > 1);+ assert_eq!(result.get("name"), Some(&name));+ assert!(result.contains_key("$geoip_country_name"));+ }+ GeoipExpected::NameOnly => {+ let result = result.expect("expected property overrides");+ assert_eq!(result.len(), 1);+ assert_eq!(result.get("name"), Some(&name));+ }+ GeoipExpected::CountryOnly => {+ let result = result.expect("expected property overrides");+ assert!(!result.is_empty());+ assert!(result.contains_key("$geoip_country_name"));+ }+ GeoipExpected::None => assert!(result.is_none()),+ }}#[tokio::test]