@@ -30,6 +30,7 @@ impl Policy {
3030fn parse_policy ( data : & str ) -> Result < Policy > {
3131 let mut builder = PolicyBuilder :: new ( ) ;
3232 let lines = PolicyLines :: new ( data) ;
33+ let mut quorum_set = false ;
3334 for ( lineno, tokens) in lines {
3435 match tokens[ ..] {
3536 [ "log" , ..] => {
@@ -80,6 +81,10 @@ fn parse_policy(data: &str) -> Result<Policy> {
8081 }
8182 }
8283 [ "quorum" , name] => {
84+ if quorum_set {
85+ bail ! ( lineno, "quorum already set" ) ;
86+ }
87+ quorum_set = true ;
8388 if name != "none" {
8489 if let Err ( err) = builder. set_quorum ( name. into ( ) ) {
8590 bail ! ( lineno, "invalid quorum rule: {err}" ) ;
@@ -91,6 +96,9 @@ fn parse_policy(data: &str) -> Result<Policy> {
9196 [ ] => unreachable ! ( "PolicyLines skips empty lines" ) ,
9297 }
9398 }
99+ if !quorum_set {
100+ bail ! ( data. lines( ) . count( ) , "no quorum set" ) ;
101+ }
94102 Ok ( builder. build ( ) )
95103}
96104
@@ -202,9 +210,7 @@ mod tests {
202210
203211 #[ test]
204212 fn parse_policy_empty ( ) {
205- let expected = PolicyBuilder :: new ( ) . build ( ) ;
206- let actual = parse_policy ( "" ) . unwrap ( ) ;
207- assert_eq ! ( expected, actual) ;
213+ insta:: assert_snapshot!( parse_policy( "" ) . unwrap_err( ) , @"line 0: no quorum set" )
208214 }
209215
210216 #[ test]
@@ -357,7 +363,7 @@ mod tests {
357363 quorum WIT-1\n \
358364 quorum WIT-2\n \
359365 ") . unwrap_err( ) ,
360- @"line 4: invalid quorum rule: quorum already set" ,
366+ @"line 4: quorum already set" ,
361367 ) ;
362368 }
363369
0 commit comments