use mkfs_xfs::{FormatOptions, FormatPlan};

#[test]
fn initial_superblock_encoder_is_stable_for_default_1g_plan() {
    let uuid = [
        0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee,
        0xff,
    ];
    let mut options = FormatOptions::new(1 << 30, uuid);
    options.label = Some("testfs".to_string());

    let plan = FormatPlan::new(options).unwrap();
    let sb = plan.initial_superblock();
    let bytes = sb.encode_without_crc();
    let bytes_with_crc = sb.encode_with_crc();

    assert_eq!(&bytes[0..4], b"XFSB");
    assert_eq!(&bytes[4..8], &4096_u32.to_be_bytes());
    assert_eq!(&bytes[8..16], &262_144_u64.to_be_bytes());
    assert_eq!(&bytes[32..48], &uuid);
    assert_eq!(&bytes[84..88], &65_536_u32.to_be_bytes());
    assert_eq!(&bytes[88..92], &4_u32.to_be_bytes());
    assert_eq!(&bytes[100..102], &0xb4b5_u16.to_be_bytes());
    assert_eq!(&bytes[108..114], b"testfs");
    assert_eq!(&bytes[200..204], &0x18a_u32.to_be_bytes());
    assert_eq!(&bytes[204..208], &0x18a_u32.to_be_bytes());
    assert_eq!(&bytes[212..216], &0x0f_u32.to_be_bytes());
    assert_eq!(&bytes[216..220], &0xeb_u32.to_be_bytes());
    assert_ne!(&bytes_with_crc[224..228], &[0, 0, 0, 0]);
}
