Repository navigation
Expand file tree
/
Copy patherrors_test.go
More file actions
53 lines (47 loc) · 1.47 KB
/
Copy patherrors_test.go
File metadata and controls
53 lines (47 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package fsforge_test
import (
"os"
"path/filepath"
"testing"
fsforge "github.com/emmanuel-deloget/fsforge"
)
func TestBuildFromDirMissingSource(t *testing.T) {
err := fsforge.New("ext2").Size("16M").
BuildFromDir(filepath.Join(t.TempDir(), "nope"), filepath.Join(t.TempDir(), "o.img"))
if err == nil {
t.Fatal("building from a missing directory should fail")
}
}
func TestConvertMissingImageSource(t *testing.T) {
err := fsforge.Convert(
fsforge.Location{Kind: "ext2", Path: filepath.Join(t.TempDir(), "absent.img")},
fsforge.Location{Kind: "dir", Path: t.TempDir()},
fsforge.Options{},
)
if err == nil {
t.Fatal("converting from a missing image should fail")
}
}
func TestConvertCorruptSquashfsSource(t *testing.T) {
bad := filepath.Join(t.TempDir(), "bad.sqfs")
if err := os.WriteFile(bad, []byte("not a squashfs image at all"), 0o644); err != nil {
t.Fatal(err)
}
err := fsforge.Convert(
fsforge.Location{Kind: "squashfs", Path: bad},
fsforge.Location{Kind: "dir", Path: t.TempDir()},
fsforge.Options{},
)
if err == nil {
t.Fatal("converting from a corrupt squashfs should fail")
}
}
func TestBuildInvalidBlockSize(t *testing.T) {
// squashfs rejects a non-power-of-two block size at Format time, surfacing
// through the Builder's create pipeline.
err := fsforge.New("squashfs").BlockSize(1000).
BuildFromDir(sampleTree(t), filepath.Join(t.TempDir(), "x.sqfs"))
if err == nil {
t.Fatal("an invalid squashfs block size should fail the build")
}
}