[pbs-devel] [PATCH proxmox-backup 03/23] maintenance: add 'Unpplugged' maintenance type

Hannes Laimer h.laimer at proxmox.com
Thu Sep 21 09:41:40 CEST 2023



On 9/19/23 15:37, Lukas Wagner wrote:
> 
> 
> On 9/15/23 08:54, Hannes Laimer wrote:
>> +
>> +#[test]
>> +fn test_check() {
>> +    let ro_mode = MaintenanceMode::new(MaintenanceType::ReadOnly, None);
>> +    let offline_mode = MaintenanceMode::new(MaintenanceType::Offline, 
>> None);
>> +    let delete_mode = MaintenanceMode::new(MaintenanceType::Delete, 
>> None);
>> +    let unplugged_mode = 
>> MaintenanceMode::new(MaintenanceType::Unplugged, None);
>> +
>> +    assert!(ro_mode.check(Some(Operation::Lookup)).is_ok());
>> +    assert!(ro_mode.check(Some(Operation::Read)).is_ok());
>> +    assert!(ro_mode.check(Some(Operation::Write)).is_err());
>> +
>> +    assert!(offline_mode.check(Some(Operation::Lookup)).is_ok());
>> +    assert!(offline_mode.check(Some(Operation::Read)).is_err());
>> +    assert!(offline_mode.check(Some(Operation::Write)).is_err());
>> +
>> +    assert!(delete_mode.check(Some(Operation::Lookup)).is_err());
>> +    assert!(delete_mode.check(Some(Operation::Read)).is_err());
>> +    assert!(delete_mode.check(Some(Operation::Write)).is_err());
>> +
>> +    assert!(unplugged_mode.check(Some(Operation::Lookup)).is_err());
>> +    assert!(unplugged_mode.check(Some(Operation::Read)).is_err());
>> +    assert!(unplugged_mode.check(Some(Operation::Write)).is_err());
>> +}
> 
> It's always advisable to have tests in separate submodule:
> 
> #[cfg(test)]
> mod tests {
>      use super::*;
> 
>      #[test]
>      fn test_check() {
>         ...
>      }
> }
> 
> This makes sure that the test(s) is/are not compiled during a normal 
> build :)
> 
Correct me if I'm wrong but, AFAIK `#[test]` does that, and since this
is the only and very simple test a whole mod thing seemed a bit
overkill, so I stuck with just `#[test]`.





More information about the pbs-devel mailing list