4
. "launchpad.net/gocheck"
5
"launchpad.net/juju-core/bzr"
12
func Test(t *testing.T) {
16
var _ = Suite(&BzrSuite{})
22
func (s *BzrSuite) SetUpTest(c *C) {
23
b, err := bzr.New(c.MkDir())
25
c.Assert(b.Init(), IsNil)
29
func (s *BzrSuite) TestNewFindsRoot(c *C) {
30
err := os.Mkdir(s.b.Join("dir"), 0755)
32
b, err := bzr.New(s.b.Join("dir"))
34
c.Assert(b.Location(), Equals, s.b.Location())
37
func (s *BzrSuite) TestJoin(c *C) {
38
b, err := bzr.New("lp:foo")
40
path := b.Join("baz", "bar")
41
c.Assert(path, Equals, "lp:foo/baz/bar")
44
func (s *BzrSuite) TestErrorHandling(c *C) {
45
b, err := bzr.New("/non/existent/path")
48
c.Assert(err, ErrorMatches, `(?s)error running "bzr init":.*does not exist.*`)
51
func (s *BzrSuite) TestInit(c *C) {
52
_, err := os.Stat(s.b.Join(".bzr"))
56
func (s *BzrSuite) TestRevisionIdOnEmpty(c *C) {
57
revid, err := s.b.RevisionId()
58
c.Assert(err, ErrorMatches, "branch has no content")
59
c.Assert(revid, Equals, "")
62
func (s *BzrSuite) TestCommit(c *C) {
63
f, err := os.Create(s.b.Join("myfile"))
66
err = s.b.Add("myfile")
68
err = s.b.Commit("my log message")
71
revid, err := s.b.RevisionId()
74
cmd := exec.Command("bzr", "log", "--long", "-v", s.b.Location())
75
output, err := cmd.CombinedOutput()
77
c.Assert(string(output), Matches, "(?s).*revision-id: " + revid + "\n.*message:\n.*my log message\n.*added:\n.*myfile .*")
80
func (s *BzrSuite) TestPush(c *C) {
81
b1, err := bzr.New(c.MkDir())
83
b2, err := bzr.New(c.MkDir())
85
b3, err := bzr.New(c.MkDir())
87
c.Assert(b1.Init(), IsNil)
88
c.Assert(b2.Init(), IsNil)
89
c.Assert(b3.Init(), IsNil)
91
// Create and add b1/file to the branch.
92
f, err := os.Create(b1.Join("file"))
97
err = b1.Commit("added file")
101
err = b1.Push(&bzr.PushAttr{Location: b2.Location()})
104
// Push location should be set to b2.
105
location, err := b1.PushLocation()
107
c.Assert(location, Equals, b2.Location())
109
// Now push it to b3.
110
err = b1.Push(&bzr.PushAttr{Location: b3.Location()})
113
// Push location is still set to b2.
114
location, err = b1.PushLocation()
116
c.Assert(location, Equals, b2.Location())
118
// Push it again, this time with the remember flag set.
119
err = b1.Push(&bzr.PushAttr{Location: b3.Location(), Remember: true})
122
// Now the push location has shifted to b3.
123
location, err = b1.PushLocation()
125
c.Assert(location, Equals, b3.Location())
127
// Both b2 and b3 should have the file.
128
_, err = os.Stat(b2.Join("file"))
130
_, err = os.Stat(b3.Join("file"))