-
Notifications
You must be signed in to change notification settings - Fork 51
/
captain_test.go
101 lines (81 loc) · 2.01 KB
/
captain_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
package captain // import "github.com/harbur/captain"
import (
"github.com/stretchr/testify/assert"
"testing"
)
// Test Fixtures
var validApp = App{
Image: "",
Pre: []string{"echo running pre"},
Post: []string{"echo running post"},
}
var invalidApp = App{
Pre: []string{"nonexistingPreCommand"},
Post: []string{"nonexistingPostCommand"},
}
// Pre Command
func TestPre(t *testing.T) {
res := Pre(validApp)
assert.Nil(t, res, "No error returned")
}
func TestPreFail(t *testing.T) {
res := Pre(invalidApp)
assert.NotNil(t, res, "Error returned")
}
// Post Command
func TestPost(t *testing.T) {
res := Post(validApp)
assert.Nil(t, res, "No error returned")
}
func TestPostFail(t *testing.T) {
res := Post(invalidApp)
assert.NotNil(t, res, "Error returned")
}
// Build Command
func TestBuild(t *testing.T) {
var testConfig = readConfig(configFile(basedir + "/test/Simple/captain.yml"))
var buildOpts = BuildOptions{
Config: testConfig,
}
Build(buildOpts)
}
// Test Command
func TestTest(t *testing.T) {
var testConfig = readConfig(configFile(basedir + "/test/Simple/captain.yml"))
var buildOpts = BuildOptions{
Config: testConfig,
}
Test(buildOpts)
}
// Pull Command
func TestPullNoBranchTags(t *testing.T) {
var testConfig = readConfig(configFile(basedir + "/test/alpine/captain.yml"))
var buildOpts = BuildOptions{
Config: testConfig,
Branch_tags: false,
}
Pull(buildOpts)
}
// Purge Command
func TestPurge(t *testing.T) {
var testConfig = readConfig(configFile(basedir + "/test/alpine/captain.yml"))
var buildOpts = BuildOptions{
Config: testConfig,
}
Purge(buildOpts)
}
// SelfUpdate Command
func TestSelfUpdate(t *testing.T) {
// First Time Self update
SelfUpdate()
// Already Installed last version
SelfUpdate()
}
func TestDownloadFile(t *testing.T) {
res := downloadFile("/tmp/captain.html", "https://github.com/harbur/captain")
assert.Nil(t, res, "captain")
}
func TestFindLastVersion(t *testing.T) {
res := findLastVersion()
assert.NotNil(t, res, "Last version exists")
}