grim/govcs

Bump the go version in go.mod
draft
2021-11-18, Gary Kramlich
6c01c30c9326
Bump the go version in go.mod
// 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"
"keep.imfreedom.org/grim/govcs/exec"
"keep.imfreedom.org/grim/govcs/git"
"keep.imfreedom.org/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)
}