grim/govcs
Clone
Summary
Browse
Changes
Graph
Replace sweet with testify and update all copyrights
draft
2019-07-27, Gary Kramlich
ba0d24484add
Replace sweet with testify and update all copyrights
// govcs
// Copyright 2017-2019 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/stretchr/testify/assert"
"bitbucket.org/rw_grim/govcs/exec"
"bitbucket.org/rw_grim/govcs/git"
"bitbucket.org/rw_grim/govcs/hg"
)
func
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
(
exec
.
NewMockResult
(
""
,
errors
.
New
(
"not a "
+
cmdName
+
" repo"
),
),
)
})
return
backend
}
func
TestFindGitFromGit
(
t
*
testing
.
T
)
{
backend
:=
setup
(
"git"
,
exec
.
NewMockCommand
(
exec
.
NewMockResult
(
"found"
,
nil
)))
defer
exec
.
SetBackend
(
backend
)
vcs
,
err
:=
Detect
(
"working-directory"
)
assert
.
NotNil
(
t
,
vcs
)
assert
.
Nil
(
t
,
err
)
g
,
ok
:=
vcs
.(
*
git
.
Git
)
assert
.
True
(
t
,
ok
)
assert
.
IsType
(
t
,
&
git
.
Git
{},
g
)
}
func
TestFindHgFromHg
(
t
*
testing
.
T
)
{
backend
:=
setup
(
"hg"
,
exec
.
NewMockCommand
(
exec
.
NewMockResult
(
"found"
,
nil
)))
defer
exec
.
SetBackend
(
backend
)
vcs
,
err
:=
Detect
(
"working-directory"
)
assert
.
NotNil
(
t
,
vcs
)
assert
.
Nil
(
t
,
err
)
m
,
ok
:=
vcs
.(
*
hg
.
Mercurial
)
assert
.
True
(
t
,
ok
)
assert
.
IsType
(
t
,
&
hg
.
Mercurial
{},
m
)
}
func
TestFindNoRepository
(
t
*
testing
.
T
)
{
backend
:=
setup
(
""
,
exec
.
NewMockCommand
(
exec
.
NewMockResult
(
""
,
errors
.
New
(
"not a repo"
))))
defer
exec
.
SetBackend
(
backend
)
vcs
,
err
:=
Detect
(
"working-directory"
)
assert
.
Nil
(
t
,
vcs
)
assert
.
Error
(
t
,
ErrNoRepositoryFound
,
err
)
}