-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathpack_nonwin32_test.go
99 lines (93 loc) · 2.25 KB
/
pack_nonwin32_test.go
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//go:build !windows
package pack
import (
"context"
"os"
"path/filepath"
"testing"
"github.com/data-preservation-programs/singularity/model"
"github.com/data-preservation-programs/singularity/util/testutil"
"github.com/gotidy/ptr"
"github.com/stretchr/testify/require"
"gorm.io/gorm"
)
func TestAssembleCar_InaccessibleFile(t *testing.T) {
tmp := t.TempDir()
err := os.WriteFile(filepath.Join(tmp, "test.txt"), []byte("test"), 0000)
require.NoError(t, err)
stat, err := os.Stat(filepath.Join(tmp, "test.txt"))
require.NoError(t, err)
testutil.All(t, func(ctx context.Context, t *testing.T, db *gorm.DB) {
job := model.Job{
Type: model.Pack,
State: model.Processing,
Attachment: &model.SourceAttachment{
Preparation: &model.Preparation{
MaxSize: 2000000,
PieceSize: 1 << 21,
},
Storage: &model.Storage{
Type: "local",
Path: tmp,
},
},
FileRanges: []model.FileRange{
{
Offset: 0,
Length: 5,
File: &model.File{
Path: "test.txt",
Size: stat.Size(),
LastModifiedNano: stat.ModTime().UnixNano(),
AttachmentID: 1,
Directory: &model.Directory{
AttachmentID: 1,
},
},
},
},
}
err := db.Create(&job).Error
require.NoError(t, err)
_, err = Pack(ctx, db, job)
require.ErrorContains(t, err, "failed to open")
})
testutil.All(t, func(ctx context.Context, t *testing.T, db *gorm.DB) {
job := model.Job{
Type: model.Pack,
State: model.Processing,
Attachment: &model.SourceAttachment{
Preparation: &model.Preparation{
MaxSize: 2000000,
PieceSize: 1 << 21,
},
Storage: &model.Storage{
Type: "local",
Path: tmp,
ClientConfig: model.ClientConfig{
SkipInaccessibleFile: ptr.Of(true),
},
},
},
FileRanges: []model.FileRange{
{
Offset: 0,
Length: 5,
File: &model.File{
Path: "test.txt",
Size: stat.Size(),
LastModifiedNano: stat.ModTime().UnixNano(),
AttachmentID: 1,
Directory: &model.Directory{
AttachmentID: 1,
},
},
},
},
}
err := db.Create(&job).Error
require.NoError(t, err)
_, err = Pack(ctx, db, job)
require.ErrorIs(t, err, ErrNoContent)
})
}