-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpayload_test.go
54 lines (44 loc) · 1.21 KB
/
payload_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
package go_bagit
import (
"path/filepath"
"regexp"
"testing"
)
func TestPayloadFuncs(t *testing.T) {
t.Run("Test GetFileInPayload()", func(t *testing.T) {
bagRoot := filepath.Join("test", "valid-with-subdirs")
bag, err := GetExistingBag(bagRoot)
if err != nil {
t.Error(err)
}
want := "output2.log"
got, err := bag.Payload.GetFileInPayload(want)
if err != nil {
t.Error(err)
}
if want != got.FileInfo.Name() {
t.Errorf("\n%v !=\n%v", want, got)
}
})
}
func TestFindFilesInPayload(t *testing.T) {
t.Run("Test FindFilesInPayload()", func(t *testing.T) {
bagRoot := filepath.Join("test", "valid-erecord-with-subdirs")
bag, err := GetExistingBag(bagRoot)
if err != nil {
t.Error(err)
}
want := 1
wantPtn := regexp.MustCompile("_aspace_wo.tsv$")
got := bag.Payload.FindFilesInPayload(wantPtn)
if err != nil {
t.Error(err)
}
if want != len(got) {
t.Fatal("length of returned slice does not match expectations")
}
if got[0].Path != "test/valid-erecord-with-subdirs/data/objects/metadata/transfers/fales_mss2023_cuid39675-48b63462-0fec-4f6a-8913-1f2e2f9168e5/fales_mss2023_cuid39675_aspace_wo.tsv" {
t.Errorf("Path value does not match expectations")
}
})
}