-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelpers_test.go
131 lines (113 loc) · 3.33 KB
/
helpers_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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* Copyright (C) 2019, 2020, 2021, 2022. Genome Research Ltd. All rights
* reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License,
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @file helpers_test.go
* @author Keith James <[email protected]>
*/
package extendo_test
import (
"fmt"
"math/rand"
"os"
"path/filepath"
. "github.com/onsi/ginkgo/v2"
ex "github.com/wtsi-npg/extendo/v2"
)
type itemPathTransform func(i []ex.RodsItem) []string
type collPathTransform func(i []ex.Collection) []string
type objPathTransform func(i []ex.DataObject) []string
type localPathTransform func(i []ex.RodsItem) []string
var batonArgs = []string{"--unbuffered"}
func makeRodsItemTransform(workColl string) func(i []ex.RodsItem) []string {
return func(items []ex.RodsItem) []string {
var paths []string
for _, p := range items {
r, _ := filepath.Rel(workColl, p.RodsPath())
paths = append(paths, r)
}
return paths
}
}
func makeCollTransform(workColl string) func(i []ex.Collection) []string {
return func(colls []ex.Collection) []string {
var paths []string
for _, p := range colls {
r, _ := filepath.Rel(workColl, p.RodsPath())
paths = append(paths, r)
}
return paths
}
}
func makeObjTransform(workColl string) func(i []ex.DataObject) []string {
return func(objs []ex.DataObject) []string {
var paths []string
for _, p := range objs {
r, _ := filepath.Rel(workColl, p.RodsPath())
paths = append(paths, r)
}
return paths
}
}
func makeLocalFileTransform(root string) func(i []ex.RodsItem) []string {
return func(items []ex.RodsItem) []string {
var paths []string
for _, p := range items {
r, _ := filepath.Rel(root, p.LocalPath())
paths = append(paths, r)
}
return paths
}
}
// Copy test data from local directory src into iRODS collection dst
func putTestData(src string, dst string) error {
src = filepath.Clean(src)
dst = filepath.Clean(dst)
client, err := ex.FindAndStart("--unbuffered")
if err != nil {
return err
}
_, err = client.MkDir(ex.Args{Recurse: true}, ex.RodsItem{IPath: dst})
if err != nil {
return err
}
_, err = client.Put(ex.Args{Checksum: true, Recurse: true},
ex.RodsItem{IDirectory: src, IPath: dst})
if err != nil {
return err
}
return err
}
// Remove test data recursively from under path dst from iRODS
func removeTmpCollection(dst string) error {
client, err := ex.FindAndStart("--unbuffered")
if err != nil {
return err
}
_, err = client.RemDir(ex.Args{Force: true, Recurse: true},
ex.RodsItem{IPath: dst})
if err != nil {
return err
}
return client.Stop()
}
// Return a new pseudo randomised path in iRODS
func tmpRodsPath(root string, prefix string) string {
s := rand.NewSource(GinkgoRandomSeed())
r := rand.New(s)
d := fmt.Sprintf("%s.%d.%010d", prefix, os.Getpid(), r.Uint32())
return filepath.Join(root, d)
}