grim/govcs
Clone
Summary
Browse
Changes
Graph
remove the Bookmark method from git
draft
2017-12-27, Gary Kramlich
e3e0b8f91448
remove the Bookmark method from git
// 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
govcs
import
(
"errors"
"testing"
"github.com/aphistic/sweet"
junit
"github.com/aphistic/sweet-junit"
.
"github.com/onsi/gomega"
"bitbucket.org/rw_grim/govcs/exec"
"bitbucket.org/rw_grim/govcs/git"
"bitbucket.org/rw_grim/govcs/hg"
)
type
vcsSuite
struct
{}
func
TestMain
(
m
*
testing
.
M
)
{
RegisterFailHandler
(
sweet
.
GomegaFail
)
sweet
.
Run
(
m
,
func
(
s
*
sweet
.
S
)
{
s
.
RegisterPlugin
(
junit
.
NewPlugin
())
s
.
AddSuite
(
&
vcsSuite
{})
})
}
func
(
s
*
vcsSuite
)
setup
(
cmdName
string
,
cmd
exec
.
Cmd
)
exec
.
ExecBackend
{
backend
:=
exec
.
Backend
()
exec
.
SetBackend
(
func
(
name
string
,
args
...
string
)
exec
.
Cmd
{
if
name
==
cmdName
{
return
cmd
}
return
exec
.
NewMockCommand
(
""
,
errors
.
New
(
"not a "
+
cmdName
+
" repo"
),
)
})
return
backend
}
func
(
s
*
vcsSuite
)
TestFindGitFromGit
(
t
sweet
.
T
)
{
backend
:=
s
.
setup
(
"git"
,
exec
.
NewMockCommand
(
"found"
,
nil
))
defer
exec
.
SetBackend
(
backend
)
vcs
,
err
:=
Detect
(
"working-directory"
)
Expect
(
vcs
).
ToNot
(
BeNil
())
Expect
(
err
).
To
(
BeNil
())
g
,
ok
:=
vcs
.(
*
git
.
Git
)
Expect
(
ok
).
To
(
BeTrue
())
Expect
(
g
).
To
(
BeAssignableToTypeOf
(
&
git
.
Git
{}))
}
func
(
s
*
vcsSuite
)
TestFindHgFromHg
(
t
sweet
.
T
)
{
backend
:=
s
.
setup
(
"hg"
,
exec
.
NewMockCommand
(
"found"
,
nil
))
defer
exec
.
SetBackend
(
backend
)
vcs
,
err
:=
Detect
(
"working-directory"
)
Expect
(
vcs
).
ToNot
(
BeNil
())
Expect
(
err
).
To
(
BeNil
())
m
,
ok
:=
vcs
.(
*
hg
.
Mercurial
)
Expect
(
ok
).
To
(
BeTrue
())
Expect
(
m
).
To
(
BeAssignableToTypeOf
(
&
hg
.
Mercurial
{}))
}
func
(
s
*
vcsSuite
)
TestFindNoRepository
(
t
sweet
.
T
)
{
backend
:=
s
.
setup
(
""
,
exec
.
NewMockCommand
(
""
,
errors
.
New
(
"not a repo"
)))
defer
exec
.
SetBackend
(
backend
)
vcs
,
err
:=
Detect
(
"working-directory"
)
Expect
(
vcs
).
To
(
BeNil
())
Expect
(
err
).
To
(
MatchError
(
ErrNoRepositoryFound
))
}