-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_test.go
96 lines (85 loc) · 2.62 KB
/
process_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
package main
import (
"fmt"
"os"
"testing"
"github.com/crispgm/go-van/caravan"
"github.com/stretchr/testify/assert"
)
func getRealPath(p string) string {
cwd, _ := os.Getwd()
return fmt.Sprintf("%s/%s", cwd, p)
}
func initArgs() {
confName = getRealPath("caravan.yml")
specName = "master"
initYAML = false
deployOnce = false
}
func TestInitConf(t *testing.T) {
confPath := getRealPath(caravan.DefaultConfName)
os.Remove(confPath)
err := initConf()
assert.NoError(t, err)
assert.FileExists(t, confPath)
err = initConf()
assert.Error(t, errFileExisted, err)
os.Remove(confPath)
}
func TestDeployOnceWithConf(t *testing.T) {
initArgs()
os.Remove(getRealPath("caravan.yml"))
os.Remove(getRealPath("fixtures/testoutput/file.txt"))
caravan.DefaultConf.Once = true
caravan.DefaultConf.Source = getRealPath("fixtures/testsrc/")
caravan.DefaultConf.Destination = getRealPath("fixtures/testoutput/")
caravan.CreateDefault(getRealPath("caravan.yml"))
err := parseConfAndWatch(false)
assert.NoError(t, err)
assert.FileExists(t, getRealPath("fixtures/testoutput/file.txt"))
os.Remove(getRealPath("fixtures/testoutput/file.txt"))
os.Remove(getRealPath("caravan.yml"))
}
func TestDeployOnceWithArgs(t *testing.T) {
initArgs()
deployOnce = true
os.Remove(getRealPath("caravan.yml"))
os.Remove(getRealPath("fixtures/testoutput/file.txt"))
caravan.DefaultConf.Source = getRealPath("fixtures/testsrc/")
caravan.DefaultConf.Destination = getRealPath("fixtures/testoutput/")
caravan.CreateDefault(getRealPath("caravan.yml"))
err := parseConfAndWatch(false)
assert.NoError(t, err)
assert.FileExists(t, getRealPath("fixtures/testoutput/file.txt"))
os.Remove(getRealPath("fixtures/testoutput/file.txt"))
os.Remove(getRealPath("caravan.yml"))
}
func TestLoadConfFail(t *testing.T) {
initArgs()
err := parseConfAndWatch(false)
assert.Error(t, err)
}
func TestUnsupportedMode(t *testing.T) {
initArgs()
os.Remove(getRealPath("caravan.yml"))
caravan.DefaultConf.Mode = "scp"
caravan.CreateDefault(getRealPath("caravan.yml"))
err := parseConfAndWatch(false)
assert.Error(t, errUnsupportedMode, err)
os.Remove(getRealPath("caravan.yml"))
}
func TestInpsect(t *testing.T) {
initArgs()
confPath := getRealPath(caravan.DefaultConfName)
os.Remove(confPath)
err := initConf()
assert.NoError(t, err)
output := caravan.CaptureOutput(func() { parseConfAndWatch(true) })
assert.Contains(t, output, "Reading configuration..")
assert.Contains(t, output, "=> deploy_mode: scp")
os.Remove(getRealPath("caravan.yml"))
}
func TestVersion(t *testing.T) {
output := caravan.CaptureOutput(func() { version() })
assert.Contains(t, output, "go-van version")
}