grim/govcs

Add subversion support
draft
2017-12-27, Gary Kramlich
8f7139d219b9
Add subversion support
// govcs
// Copyright 2017 Gary Kramlich <grim@reaperworld.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package hg
import (
"errors"
"testing"
"github.com/aphistic/sweet"
junit "github.com/aphistic/sweet-junit"
. "github.com/onsi/gomega"
"bitbucket.org/rw_grim/govcs/exec"
)
type hgSuite struct{}
func TestMain(m *testing.M) {
RegisterFailHandler(sweet.GomegaFail)
sweet.Run(m, func(s *sweet.S) {
s.RegisterPlugin(junit.NewPlugin())
s.AddSuite(&hgSuite{})
})
}
func (s *hgSuite) setup(cmd exec.Cmd) exec.ExecBackend {
backend := exec.Backend()
exec.SetBackend(func(name string, args ...string) exec.Cmd {
return cmd
})
return backend
}
func (s *hgSuite) TestDetectFound(t sweet.T) {
backend := s.setup(exec.NewMockCommand("found", nil))
defer exec.SetBackend(backend)
vcs := Detect("working-directory")
Expect(vcs).ToNot(BeNil())
hg, ok := vcs.(*Mercurial)
Expect(ok).To(BeTrue())
Expect(hg.wd).To(Equal("working-directory"))
}
func (s *hgSuite) TestDetectNotFound(t sweet.T) {
backend := s.setup(exec.NewMockCommand("", errors.New("not found")))
defer exec.SetBackend(backend)
vcs := Detect("")
Expect(vcs).To(BeNil())
}
func (s *hgSuite) TestRemoteEmpty(t sweet.T) {
backend := s.setup(exec.NewMockCommand("mypath\n", nil))
defer exec.SetBackend(backend)
hg := Mercurial{}
Expect(hg.Remote("")).To(Equal("mypath"))
}
func (s *hgSuite) TestRemoteNamed(t sweet.T) {
backend := s.setup(exec.NewMockCommand("myupstream\n", nil))
defer exec.SetBackend(backend)
hg := Mercurial{}
Expect(hg.Remote("upstream")).To(Equal("myupstream"))
}
func (s *hgSuite) TestRoot(t sweet.T) {
path := "/home/foo/go/src/bitbucket.org/bar/baz"
backend := s.setup(exec.NewMockCommand(path+"\n", nil))
defer exec.SetBackend(backend)
hg := Mercurial{}
Expect(hg.Root()).To(Equal(path))
}
func (s *hgSuite) TestCommit(t sweet.T) {
backend := s.setup(exec.NewMockCommand("deadbeef", nil))
defer exec.SetBackend(backend)
hg := Mercurial{}
Expect(hg.Commit()).To(Equal("deadbeef"))
}
func (s *hgSuite) TestBranch(t sweet.T) {
backend := s.setup(exec.NewMockCommand("my-fancy-branch", nil))
defer exec.SetBackend(backend)
hg := Mercurial{}
Expect(hg.Branch()).To(Equal("my-fancy-branch"))
}
func (s *hgSuite) TestBookmark(t sweet.T) {
backend := s.setup(exec.NewMockCommand("my-fancy-bookmark", nil))
defer exec.SetBackend(backend)
hg := Mercurial{}
Expect(hg.Bookmark()).To(Equal("my-fancy-bookmark"))
}
func (s *hgSuite) TestConfigPaths(t sweet.T) {
backend := s.setup(exec.NewMockCommand("paths.default=default\npaths.upstream=upstream\n", nil))
defer exec.SetBackend(backend)
hg := Mercurial{}
Expect(hg.Config("paths")).To(Equal([]string{"paths.default=default", "paths.upstream=upstream"}))
}