| Tim Windelschmidt | 6d33a43 | 2025-02-04 14:34:25 +0100 | [diff] [blame] | 1 | // Copyright The Monogon Project Authors. |
| Lorenz Brun | 378a445 | 2021-01-26 13:47:41 +0100 | [diff] [blame] | 2 | // SPDX-License-Identifier: Apache-2.0 |
| Lorenz Brun | 378a445 | 2021-01-26 13:47:41 +0100 | [diff] [blame] | 3 | |
| 4 | package erofs |
| 5 | |
| 6 | import ( |
| 7 | "bytes" |
| 8 | "encoding/binary" |
| 9 | "testing" |
| 10 | |
| 11 | "github.com/stretchr/testify/assert" |
| 12 | ) |
| 13 | |
| Serge Bazanski | 216fe7b | 2021-05-21 18:36:16 +0200 | [diff] [blame] | 14 | // These test that the specified structures serialize to the same number of |
| 15 | // bytes as the ones in the EROFS kernel module. |
| Lorenz Brun | 378a445 | 2021-01-26 13:47:41 +0100 | [diff] [blame] | 16 | |
| 17 | func TestSuperblockSize(t *testing.T) { |
| 18 | var buf bytes.Buffer |
| 19 | if err := binary.Write(&buf, binary.LittleEndian, &superblock{}); err != nil { |
| 20 | t.Fatalf("failed to write superblock: %v", err) |
| 21 | } |
| 22 | assert.Equal(t, 128, buf.Len()) |
| 23 | } |
| 24 | |
| 25 | func TestDirectoryEntrySize(t *testing.T) { |
| 26 | var buf bytes.Buffer |
| 27 | if err := binary.Write(&buf, binary.LittleEndian, &directoryEntryRaw{}); err != nil { |
| 28 | t.Fatalf("failed to write directory entry: %v", err) |
| 29 | } |
| 30 | assert.Equal(t, 12, buf.Len()) |
| 31 | } |
| 32 | |
| 33 | func TestInodeCompactSize(t *testing.T) { |
| 34 | var buf bytes.Buffer |
| 35 | if err := binary.Write(&buf, binary.LittleEndian, &inodeCompact{}); err != nil { |
| 36 | t.Fatalf("failed to write compact inode: %v", err) |
| 37 | } |
| 38 | assert.Equal(t, 32, buf.Len()) |
| 39 | } |