forked from drone-plugins/drone-hg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
78 lines (68 loc) · 1.52 KB
/
main_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
package main
import (
"github.com/drone/drone-plugin-go/plugin"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
var commits = []struct {
path string
clone string
event string
branch string
commit string
file string
data string
}{
// first commit
{
path: "cedk/drone-hg-test",
clone: "https://bitbucket.org/cedk/drone-hg-test",
event: plugin.EventPush,
branch: "default",
commit: "37526193d0139f188b20e5c8bed8fc0640c38627",
file: "test",
data: "",
},
// head commit
{
path: "cedk/drone-hg-test",
clone: "https://bitbucket.org/cedk/drone-hg-test",
event: plugin.EventPush,
branch: "default",
commit: "6e4637b5ef305536115bd05e97c913fc7cdcc69d",
file: "test",
data: "Test\n",
},
}
func TestClone(t *testing.T) {
for _, c := range commits {
dir := setup()
r := &plugin.Repo{Clone: c.clone}
b := &plugin.Build{Commit: c.commit, Branch: c.branch, Event: c.event}
w := &plugin.Workspace{Path: dir}
v := &Params{}
if err := run(r, b, w, v); err != nil {
t.Errorf("Expected successful clone. Got error. %s.", err)
}
data := readFile(dir, c.file)
if data != c.data {
t.Errorf("Expected %s to contain [%s]. Got [%s].", c.file, c.data, data)
}
teardown(dir)
}
}
func setup() string {
dir, _ := ioutil.TempDir("/tmp", "drone_hg_test_")
os.Mkdir(dir, 0777)
return dir
}
func teardown(dir string) {
os.RemoveAll(dir)
}
func readFile(dir, file string) string {
filename := filepath.Join(dir, file)
data, _ := ioutil.ReadFile(filename)
return string(data)
}