@@ -48,9 +48,18 @@ impl Cohort {
48
48
}
49
49
50
50
pub fn update_from_omaha ( & mut self , omaha_cohort : Self ) {
51
- // Do not overwrite cohort hint, because Omaha should never send cohort hint back.
52
- self . id = omaha_cohort. id ;
53
- self . name = omaha_cohort. name ;
51
+ // From Omaha spec:
52
+ // If this attribute is transmitted in the response (even if the value is empty-string),
53
+ // the client should overwrite the current cohort of this app with the sent value.
54
+ if omaha_cohort. id != None {
55
+ self . id = omaha_cohort. id ;
56
+ }
57
+ if omaha_cohort. hint != None {
58
+ self . hint = omaha_cohort. hint ;
59
+ }
60
+ if omaha_cohort. name != None {
61
+ self . name = omaha_cohort. name ;
62
+ }
54
63
}
55
64
56
65
/// A validation function to test that a given Cohort hint or name is valid per the Omaha spec:
@@ -84,6 +93,18 @@ mod tests {
84
93
assert_eq ! ( None , cohort. name) ;
85
94
}
86
95
96
+ #[ test]
97
+ fn test_cohort_update_from_omaha_none ( ) {
98
+ let mut cohort = Cohort {
99
+ id : Some ( "id" . to_string ( ) ) ,
100
+ hint : Some ( "hint" . to_string ( ) ) ,
101
+ name : Some ( "name" . to_string ( ) ) ,
102
+ } ;
103
+ let expected_cohort = cohort. clone ( ) ;
104
+ cohort. update_from_omaha ( Cohort :: default ( ) ) ;
105
+ assert_eq ! ( cohort, expected_cohort) ;
106
+ }
107
+
87
108
#[ test]
88
109
fn test_valid_cohort_names ( ) {
89
110
assert ! ( Cohort :: validate_name( "some-channel" ) ) ;
0 commit comments