Lorenz Brun | 378a445 | 2021-01-26 13:47:41 +0100 | [diff] [blame] | 1 | // Copyright 2020 The Monogon Project Authors. |
| 2 | // |
| 3 | // SPDX-License-Identifier: Apache-2.0 |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
| 16 | |
| 17 | package erofs |
| 18 | |
| 19 | import ( |
| 20 | "bytes" |
| 21 | "encoding/binary" |
| 22 | "testing" |
| 23 | |
| 24 | "github.com/stretchr/testify/assert" |
| 25 | ) |
| 26 | |
Serge Bazanski | 216fe7b | 2021-05-21 18:36:16 +0200 | [diff] [blame] | 27 | // These test that the specified structures serialize to the same number of |
| 28 | // bytes as the ones in the EROFS kernel module. |
Lorenz Brun | 378a445 | 2021-01-26 13:47:41 +0100 | [diff] [blame] | 29 | |
| 30 | func TestSuperblockSize(t *testing.T) { |
| 31 | var buf bytes.Buffer |
| 32 | if err := binary.Write(&buf, binary.LittleEndian, &superblock{}); err != nil { |
| 33 | t.Fatalf("failed to write superblock: %v", err) |
| 34 | } |
| 35 | assert.Equal(t, 128, buf.Len()) |
| 36 | } |
| 37 | |
| 38 | func TestDirectoryEntrySize(t *testing.T) { |
| 39 | var buf bytes.Buffer |
| 40 | if err := binary.Write(&buf, binary.LittleEndian, &directoryEntryRaw{}); err != nil { |
| 41 | t.Fatalf("failed to write directory entry: %v", err) |
| 42 | } |
| 43 | assert.Equal(t, 12, buf.Len()) |
| 44 | } |
| 45 | |
| 46 | func TestInodeCompactSize(t *testing.T) { |
| 47 | var buf bytes.Buffer |
| 48 | if err := binary.Write(&buf, binary.LittleEndian, &inodeCompact{}); err != nil { |
| 49 | t.Fatalf("failed to write compact inode: %v", err) |
| 50 | } |
| 51 | assert.Equal(t, 32, buf.Len()) |
| 52 | } |