-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecider_test.go
77 lines (61 loc) · 1.68 KB
/
decider_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
package main
import (
"io/ioutil"
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestTimeDecider(t *testing.T) {
assert := assert.New(t)
var d Decider = TimeDecider{}
var b bool
var e error
b, e = d.NeedBuild([]string{}, []string{})
assert.False(b)
assert.Error(e)
b, e = d.NeedBuild([]string{"/nothing/to/read"}, []string{})
assert.False(b)
assert.Error(e)
b, e = d.NeedBuild([]string{}, []string{"/nothing/to/read"})
assert.True(b)
assert.Nil(e)
b, e = d.NeedBuild([]string{"/nothing/to/read"}, []string{"/nothing/to/read"})
assert.True(b)
assert.Error(e)
o1, e := ioutil.TempFile("", "dmktest")
assert.Nil(e)
assert.NotNil(o1)
defer os.Remove(o1.Name())
if _, we := o1.Write([]byte("yadda")); we != nil {
assert.Fail(we.Error())
}
o1.Close()
// No input and file exists - no build necessary
b, e = d.NeedBuild([]string{}, []string{o1.Name()})
assert.False(b)
assert.Nil(e)
time.Sleep(5 * time.Millisecond) // Hacky way to make sure input is newer
i1, e := ioutil.TempFile("", "dmktest")
assert.Nil(e)
assert.NotNil(i1)
defer os.Remove(i1.Name())
if _, we := i1.Write([]byte("yadda")); we != nil {
assert.Fail(we.Error())
}
i1.Close()
// Input newer - must build
b, e = d.NeedBuild([]string{i1.Name()}, []string{o1.Name()})
assert.True(b)
assert.Nil(e)
// Input older - must NOT build
pcheck(os.Chtimes(o1.Name(), time.Now().Local(), time.Now().Local()))
b, e = d.NeedBuild([]string{i1.Name()}, []string{o1.Name()})
assert.False(b)
assert.Nil(e)
// Input missing - build required, and MUST return an error
os.Remove(i1.Name())
b, e = d.NeedBuild([]string{i1.Name()}, []string{o1.Name()})
assert.True(b)
assert.NotNil(e)
}