-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcondor_test.go
101 lines (91 loc) · 2.1 KB
/
condor_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
//nolint
package main
import (
"io/ioutil"
"os"
"os/exec"
"path"
"path/filepath"
"testing"
"github.com/pkg/errors"
"gopkg.in/cyverse-de/model.v4"
"github.com/cyverse-de/condor-launcher/test"
)
type filerecord struct {
path string
contents []byte
mode os.FileMode
}
type tsys struct {
dirsCreated map[string]os.FileMode
filesWritten []filerecord
}
// newTSys creates a new instance of tsys.
func newtsys() *tsys {
return &tsys{
dirsCreated: make(map[string]os.FileMode, 0),
filesWritten: make([]filerecord, 0),
}
}
func (t *tsys) MkdirAll(path string, mode os.FileMode) error {
t.dirsCreated[path] = mode
return nil
}
func (t *tsys) WriteFile(path string, contents []byte, mode os.FileMode) error {
t.filesWritten = append(t.filesWritten, filerecord{
path: path,
contents: contents,
mode: mode,
})
return nil
}
func TestLaunch(t *testing.T) {
cfg := test.InitConfig(t)
test.InitPath(t)
csPath, err := exec.LookPath("condor_submit")
if err != nil {
t.Error(errors.Wrapf(err, "failed to find condor_submit in $PATH"))
}
if !path.IsAbs(csPath) {
csPath, err = filepath.Abs(csPath)
if err != nil {
t.Error(errors.Wrapf(err, "failed to get the absolute path to %s", csPath))
}
}
crPath, err := exec.LookPath("condor_rm")
if err != nil {
t.Error(errors.Wrap(err, "failed to find condor_rm on the $PATH"))
}
if !path.IsAbs(crPath) {
crPath, err = filepath.Abs(crPath)
if err != nil {
t.Error(errors.Wrapf(err, "failed to get the absolute path for %s", crPath))
}
}
filesystem := newtsys()
cl := New(cfg, nil, filesystem, csPath, crPath)
if err != nil {
t.Error(err)
}
data, err := ioutil.ReadFile("test/test_submission.json")
if err != nil {
t.Error(err)
}
j, err := model.NewFromData(cl.cfg, data)
if err != nil {
t.Error(err)
}
actual, err := cl.launch(j, "", "")
if err != nil {
t.Error(err)
}
expected := "10000"
if actual != expected {
t.Errorf("launch returned:\n%s\ninstead of:\n%s\n", actual, expected)
}
parent := path.Join(j.CondorLogPath, "test_this_is_a_test")
err = os.RemoveAll(parent)
if err != nil {
t.Error(err)
}
}