-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathpush_test.go
127 lines (110 loc) · 3.92 KB
/
push_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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package main
import (
"io/ioutil"
"os/exec"
"path/filepath"
"strings"
"testing"
)
func TestPush(t *testing.T) {
// $ git clone ipfs://ipfs/$hash/repo.git $tmpDir
startURL := "ipfs://ipfs/QmZhuM4TxuhxbamPtWHyHYCUXfkqCkgBmWREKF2kqTLbvz/unpackedTest"
tmpDir := cloneAndCheckout(t, startURL, expectedClone)
// $ cd repo && make $stuff
checkFatal(t, ioutil.WriteFile(filepath.Join(tmpDir, "newFile"), []byte("Hello From Test"), 0700))
cmd := exec.Command(gitPath, "add", "newFile")
cmd.Dir = tmpDir
out, err := cmd.CombinedOutput()
t.Log("git add out: ", string(out))
checkFatal(t, err)
// $ git commit -a -m 'done!'
cmd = exec.Command(gitPath, "commit", "-m", "Test Add newFile Commit")
cmd.Dir = tmpDir
out, err = cmd.CombinedOutput()
t.Log("git commit out: ", string(out))
checkFatal(t, err)
// $ git push origin
cmd = exec.Command(gitPath, "push", "origin")
cmd.Dir = tmpDir
out, err = cmd.CombinedOutput()
t.Log("git push out: ", string(out))
checkFatal(t, err)
cmd = exec.Command(gitPath, "config", "--get", "remote.origin.url")
cmd.Dir = tmpDir
out, err = cmd.CombinedOutput()
checkFatal(t, err)
newURL := strings.TrimSpace(string(out))
if newURL == startURL {
t.Fatalf("remote url wasn't updated. is:%q", newURL)
}
rmDir(t, tmpDir)
var expectedClone = map[string]string{
"testA": "9417d011822b875da72221c8d188089cbfcee806",
"hello.txt": "e2839ad2e47386d342038958fba941fc78e3780e",
"notes": "32ed91604b272860ec911fc2bf4ae631b7900aa8",
"newFile": "cc7aae22f2d4301b6006e5f26e28b63579b61072",
}
rmDir(t, cloneAndCheckout(t, newURL, expectedClone))
}
func TestPush_twice(t *testing.T) {
startURL := "ipfs://ipfs/QmZhuM4TxuhxbamPtWHyHYCUXfkqCkgBmWREKF2kqTLbvz/unpackedTest"
tmpDir := cloneAndCheckout(t, startURL, expectedClone)
checkFatal(t, ioutil.WriteFile(filepath.Join(tmpDir, "newFile"), []byte("Hello From Test"), 0700))
cmd := exec.Command(gitPath, "add", "newFile")
cmd.Dir = tmpDir
out, err := cmd.CombinedOutput()
t.Log("git add out: ", string(out))
checkFatal(t, err)
cmd = exec.Command(gitPath, "commit", "-m", "test: Add newFile Commit")
cmd.Dir = tmpDir
out, err = cmd.CombinedOutput()
t.Log("git commit out: ", string(out))
checkFatal(t, err)
// $ git push origin
cmd = exec.Command(gitPath, "push", "origin")
cmd.Dir = tmpDir
out, err = cmd.CombinedOutput()
t.Log("git push out: ", string(out))
checkFatal(t, err)
cmd = exec.Command(gitPath, "config", "--get", "remote.origin.url")
cmd.Dir = tmpDir
out, err = cmd.CombinedOutput()
checkFatal(t, err)
newURL := strings.TrimSpace(string(out))
if newURL == startURL {
t.Fatalf("remote url wasn't updated. is:%q", newURL)
}
checkFatal(t, ioutil.WriteFile(filepath.Join(tmpDir, "2ndNewFile"), []byte("Hello From 2nd push Test"), 0700))
cmd = exec.Command(gitPath, "add", "2ndNewFile")
cmd.Dir = tmpDir
out, err = cmd.CombinedOutput()
t.Log("git add out: ", string(out))
checkFatal(t, err)
cmd = exec.Command(gitPath, "commit", "-m", "test: Add a 2nd file")
cmd.Dir = tmpDir
out, err = cmd.CombinedOutput()
t.Log("git commit out: ", string(out))
checkFatal(t, err)
// $ git push origin
cmd = exec.Command(gitPath, "push", "origin")
cmd.Dir = tmpDir
out, err = cmd.CombinedOutput()
t.Log("git push out: ", string(out))
checkFatal(t, err)
cmd = exec.Command(gitPath, "config", "--get", "remote.origin.url")
cmd.Dir = tmpDir
out, err = cmd.CombinedOutput()
checkFatal(t, err)
nextURL := strings.TrimSpace(string(out))
if nextURL == startURL || nextURL == newURL {
t.Fatalf("remote url wasn't updated (2nd time). is:%q", nextURL)
}
var expectedClone = map[string]string{
"testA": "9417d011822b875da72221c8d188089cbfcee806",
"hello.txt": "e2839ad2e47386d342038958fba941fc78e3780e",
"notes": "32ed91604b272860ec911fc2bf4ae631b7900aa8",
"newFile": "cc7aae22f2d4301b6006e5f26e28b63579b61072",
"2ndNewFile": "bacbe054a5fc6654bac497e36b474cd6839e3616",
}
rmDir(t, cloneAndCheckout(t, nextURL, expectedClone))
}