forked from mcuadros/ofelia
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsave_test.go
60 lines (43 loc) · 1.19 KB
/
save_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
package middlewares
import (
"io/ioutil"
"os"
"path/filepath"
"time"
. "gopkg.in/check.v1"
)
type SuiteSave struct {
BaseSuite
}
var _ = Suite(&SuiteSave{})
func (s *SuiteSave) TestNewSlackEmpty(c *C) {
c.Assert(NewSave(&SaveConfig{}), IsNil)
}
func (s *SuiteSave) TestRunSuccess(c *C) {
dir, err := ioutil.TempDir("/tmp", "save")
c.Assert(err, IsNil)
s.ctx.Start()
s.ctx.Stop(nil)
s.job.Name = "foo"
s.ctx.Execution.Date = time.Time{}
m := NewSave(&SaveConfig{SaveFolder: dir})
c.Assert(m.Run(s.ctx), IsNil)
_, err = os.Stat(filepath.Join(dir, "00010101_000000_foo.json"))
c.Assert(err, IsNil)
_, err = os.Stat(filepath.Join(dir, "00010101_000000_foo.stdout.log"))
c.Assert(err, IsNil)
_, err = os.Stat(filepath.Join(dir, "00010101_000000_foo.stderr.log"))
c.Assert(err, IsNil)
}
func (s *SuiteSave) TestRunSuccessOnError(c *C) {
dir, err := ioutil.TempDir("/tmp", "save")
c.Assert(err, IsNil)
s.ctx.Start()
s.ctx.Stop(nil)
s.job.Name = "foo"
s.ctx.Execution.Date = time.Time{}
m := NewSave(&SaveConfig{SaveFolder: dir, SaveOnlyOnError: true})
c.Assert(m.Run(s.ctx), IsNil)
_, err = os.Stat(filepath.Join(dir, "00010101_000000_foo.json"))
c.Assert(err, Not(IsNil))
}