Skip to content

Commit f70b738

Browse files
committed
test: add a xfs makefs test
Assert on exact allocation for different filesystem size. Note: this test only reliably works in buildkit, with a specific version of `xfsprogs`. Fixes #10021 Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
1 parent 8212e48 commit f70b738

1 file changed

Lines changed: 113 additions & 0 deletions

File tree

pkg/makefs/xfs_test.go

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
package makefs_test
6+
7+
import (
8+
"bytes"
9+
"os"
10+
"os/exec"
11+
"path/filepath"
12+
"strings"
13+
"testing"
14+
15+
"github.com/stretchr/testify/assert"
16+
"github.com/stretchr/testify/require"
17+
18+
"github.com/siderolabs/talos/pkg/makefs"
19+
)
20+
21+
func TestXFSInfo(t *testing.T) { //nolint:tparallel
22+
if hostname, _ := os.Hostname(); hostname != "buildkitsandbox" { //nolint:errcheck
23+
t.Skipf("skipping test; only run on buildkitsandbox, got %s", hostname)
24+
}
25+
26+
t.Setenv("PATH", "/usr/bin:/bin:/usr/sbin:/sbin")
27+
28+
for _, test := range []struct {
29+
name string
30+
31+
size int64
32+
33+
expected string
34+
}{
35+
{
36+
name: "1G",
37+
38+
size: 1024 * 1024 * 1024,
39+
40+
expected: `meta-data=image isize=512 agcount=4, agsize=65536 blks
41+
= sectsz=512 attr=2, projid32bit=1
42+
= crc=1 finobt=1, sparse=1, rmapbt=1
43+
= reflink=1 bigtime=1 inobtcount=1 nrext64=1
44+
= exchange=0
45+
data = bsize=4096 blocks=262144, imaxpct=25
46+
= sunit=0 swidth=0 blks
47+
naming =version 2 bsize=4096 ascii-ci=0, ftype=1, parent=0
48+
log =internal log bsize=4096 blocks=16384, version=2
49+
= sectsz=512 sunit=0 blks, lazy-count=1
50+
realtime =none extsz=4096 blocks=0, rtextents=0
51+
`,
52+
},
53+
{
54+
name: "10G",
55+
56+
size: 10 * 1024 * 1024 * 1024,
57+
58+
expected: `meta-data=image isize=512 agcount=4, agsize=655360 blks
59+
= sectsz=512 attr=2, projid32bit=1
60+
= crc=1 finobt=1, sparse=1, rmapbt=1
61+
= reflink=1 bigtime=1 inobtcount=1 nrext64=1
62+
= exchange=0
63+
data = bsize=4096 blocks=2621440, imaxpct=25
64+
= sunit=0 swidth=0 blks
65+
naming =version 2 bsize=4096 ascii-ci=0, ftype=1, parent=0
66+
log =internal log bsize=4096 blocks=16384, version=2
67+
= sectsz=512 sunit=0 blks, lazy-count=1
68+
realtime =none extsz=4096 blocks=0, rtextents=0
69+
`,
70+
},
71+
{
72+
name: "100G",
73+
74+
size: 100 * 1024 * 1024 * 1024,
75+
76+
expected: `meta-data=image isize=512 agcount=4, agsize=6553600 blks
77+
= sectsz=512 attr=2, projid32bit=1
78+
= crc=1 finobt=1, sparse=1, rmapbt=1
79+
= reflink=1 bigtime=1 inobtcount=1 nrext64=1
80+
= exchange=0
81+
data = bsize=4096 blocks=26214400, imaxpct=25
82+
= sunit=0 swidth=0 blks
83+
naming =version 2 bsize=4096 ascii-ci=0, ftype=1, parent=0
84+
log =internal log bsize=4096 blocks=16384, version=2
85+
= sectsz=512 sunit=0 blks, lazy-count=1
86+
realtime =none extsz=4096 blocks=0, rtextents=0
87+
`,
88+
},
89+
} {
90+
t.Run(test.name, func(t *testing.T) {
91+
t.Parallel()
92+
93+
tmpDir := t.TempDir()
94+
95+
tempFile := filepath.Join(tmpDir, "xfs.img")
96+
97+
require.NoError(t, os.WriteFile(tempFile, nil, 0o644))
98+
require.NoError(t, os.Truncate(tempFile, test.size))
99+
100+
require.NoError(t, makefs.XFS(tempFile))
101+
102+
var stdout bytes.Buffer
103+
104+
cmd := exec.Command("xfs_info", tempFile)
105+
cmd.Stdout = &stdout
106+
require.NoError(t, cmd.Run())
107+
108+
actual := strings.ReplaceAll(stdout.String(), tempFile, "image")
109+
110+
assert.Equal(t, test.expected, actual)
111+
})
112+
}
113+
}

0 commit comments

Comments
 (0)