Compare commits

..

No commits in common. "9d7a64a371f6f5e1ef8be6ecca502677451d50c3" and "8cd3ed2127f1c179646cf7bfecd3786eb0a91b9a" have entirely different histories.

10 changed files with 146 additions and 193 deletions

View File

@ -2,8 +2,8 @@ package commands
import ( import (
"fmt" "fmt"
"gitlab.com/revalus/grm/internal/config"
"os" "os"
"path"
"github.com/go-git/go-billy/v5" "github.com/go-git/go-billy/v5"
"github.com/go-git/go-billy/v5/osfs" "github.com/go-git/go-billy/v5/osfs"
@ -13,9 +13,12 @@ import (
"github.com/go-git/go-git/v5/storage/filesystem" "github.com/go-git/go-git/v5/storage/filesystem"
) )
type TestSetupPaths struct { type TestSetup struct {
baseTestDirectory string rootFS billy.Filesystem
baseTestRepository string baseRepository struct {
fileSystem billy.Filesystem
repo *git.Repository
}
} }
func checkErrorDuringPreparation(err error) { func checkErrorDuringPreparation(err error) {
@ -25,94 +28,111 @@ func checkErrorDuringPreparation(err error) {
} }
} }
func createRepositoryForTest() string { func createTmpDir() string {
systemTMPDirectoryWithTestPath := fmt.Sprintf("%v/grmTest", os.TempDir())
if _, ok := os.Stat(systemTMPDirectoryWithTestPath); ok != nil { baseForTMPDir := fmt.Sprintf("%v/grmTest", os.TempDir())
err := os.Mkdir(systemTMPDirectoryWithTestPath, 0777) if _, ok := os.Stat(baseForTMPDir); ok != nil {
err := os.Mkdir(baseForTMPDir, 0777)
checkErrorDuringPreparation(err) checkErrorDuringPreparation(err)
} }
temporaryDirPath, err := os.MkdirTemp(systemTMPDirectoryWithTestPath, "*")
tempDir, err := os.MkdirTemp(baseForTMPDir, "*")
checkErrorDuringPreparation(err) checkErrorDuringPreparation(err)
return temporaryDirPath
return tempDir
} }
// prepareRepositoryDirectories - prepare directories for file (rootRepositoryDirectory) and git metadata (gitMetadataDirectory) func getTestSetup() TestSetup {
func prepareRepositoryDirectories(dirName string) (billy.Filesystem, billy.Filesystem) {
rootRepositoryDirectory := osfs.New(dirName) tmpDir := createTmpDir()
gitMetadataDirectory, err := rootRepositoryDirectory.Chroot(".git")
baseFileSystem := osfs.New(tmpDir)
initRepositoryFileSystem, err := baseFileSystem.Chroot("worktree")
checkErrorDuringPreparation(err) checkErrorDuringPreparation(err)
return rootRepositoryDirectory, gitMetadataDirectory directoryForGitMetadata, err := initRepositoryFileSystem.Chroot(".git")
}
func prepareBasicRepository() TestSetupPaths {
temporaryDirPath := createRepositoryForTest()
// Create an interface of abstraction over filesystem to provide tests over multiple systems
// baseTestsDirectory - provides to main directory where new directories might be created
baseTestsDirectory := osfs.New(temporaryDirPath)
rootRepositoryDirectory, gitMetadataDirectory := prepareRepositoryDirectories(baseTestsDirectory.Root() + "/base_repository")
repository, err := git.Init(filesystem.NewStorage(
gitMetadataDirectory,
cache.NewObjectLRUDefault()),
rootRepositoryDirectory,
)
checkErrorDuringPreparation(err) checkErrorDuringPreparation(err)
testFile, err := rootRepositoryDirectory.Create("TestFile.txt") repository, err := git.Init(filesystem.NewStorage(directoryForGitMetadata, cache.NewObjectLRUDefault()), initRepositoryFileSystem)
checkErrorDuringPreparation(err) checkErrorDuringPreparation(err)
_, err = testFile.Write([]byte("foo-conent")) fileForFirstCommit, err := initRepositoryFileSystem.Create("TestFile.txt")
checkErrorDuringPreparation(err)
_, err = fileForFirstCommit.Write([]byte("foo-conent"))
checkErrorDuringPreparation(err) checkErrorDuringPreparation(err)
repositoryWorkTree, err := repository.Worktree() repositoryWorkTree, err := repository.Worktree()
checkErrorDuringPreparation(err) checkErrorDuringPreparation(err)
_, err = repositoryWorkTree.Add(testFile.Name()) repositoryWorkTree.Add(fileForFirstCommit.Name())
checkErrorDuringPreparation(err)
_, err = repositoryWorkTree.Commit("First commit", &git.CommitOptions{}) _, err = repositoryWorkTree.Commit("First commit", &git.CommitOptions{})
checkErrorDuringPreparation(err) checkErrorDuringPreparation(err)
return TestSetupPaths{ return TestSetup{
baseTestDirectory: baseTestsDirectory.Root(), baseRepository: struct {
baseTestRepository: rootRepositoryDirectory.Root(), fileSystem billy.Filesystem
repo *git.Repository
}{
fileSystem: initRepositoryFileSystem,
repo: repository,
},
rootFS: baseFileSystem,
} }
} }
func makeCommit(wk *git.Worktree, commitMessage string) { func makeCommit(wk *git.Worktree, commitMessage string) {
_, err := wk.Commit(commitMessage, &git.CommitOptions{}) _, err := wk.Commit(commitMessage, &git.CommitOptions{})
checkErrorDuringPreparation(err) checkErrorDuringPreparation(err)
} }
// createAndCloneRepository - create sub-repository with cloned base repository required to verify sync command func getFSForLocalRepo(dirName string, baseFileSystem billy.Filesystem) (billy.Filesystem, *filesystem.Storage) {
func createAndCloneRepository(repositoryName string, paths TestSetupPaths) *git.Repository { fsForLocalRepo, err := baseFileSystem.Chroot(dirName)
checkErrorDuringPreparation(err)
fsForMetadata, err := fsForLocalRepo.Chroot(".git")
checkErrorDuringPreparation(err)
storageForTestRepo := filesystem.NewStorage(fsForMetadata, cache.NewObjectLRUDefault())
return fsForLocalRepo, storageForTestRepo
}
baseGitRepository, gitMetadataDirectory := prepareRepositoryDirectories( func getBaseForTestingSyncCommand() (StatusChecker, *git.Repository, config.RepositoryConfig, TestSetup) {
path.Join(paths.baseTestDirectory, repositoryName), tmpDirWithInitialRepository := getTestSetup()
) dirNameForLocalRepository := "testRepo"
fsForLocalRepo, storageForTestRepo := getFSForLocalRepo(dirNameForLocalRepository, tmpDirWithInitialRepository.rootFS)
storageForSubRepository := filesystem.NewStorage(gitMetadataDirectory, cache.NewObjectLRUDefault()) fakeLocalRepository, err := git.Clone(storageForTestRepo, fsForLocalRepo, &git.CloneOptions{
fakeLocalRepository, err := git.Clone(storageForSubRepository, baseGitRepository, &git.CloneOptions{ URL: tmpDirWithInitialRepository.baseRepository.fileSystem.Root(),
URL: paths.baseTestRepository,
}) })
checkErrorDuringPreparation(err) checkErrorDuringPreparation(err)
return fakeLocalRepository
sc := StatusChecker{
workspace: tmpDirWithInitialRepository.rootFS.Root(),
} }
func addLocalRepositoryAsAFakeRemoteRepository(repository *git.Repository, baseTestRepositoryPath string) error { repoCfg := config.RepositoryConfig{
Name: "test",
Src: tmpDirWithInitialRepository.baseRepository.fileSystem.Root(),
Dest: dirNameForLocalRepository,
}
_, err := repository.CreateRemote(&gitcfg.RemoteConfig{ return sc, fakeLocalRepository, repoCfg, tmpDirWithInitialRepository
}
func getBaseForTestingSyncMultipleRemote() (StatusChecker, *git.Repository, config.RepositoryConfig) {
sc, fakeLocalRepository, repoCfg, tmpDirWithInitialRepository := getBaseForTestingSyncCommand()
fakeLocalRepository.CreateRemote(&gitcfg.RemoteConfig{
Name: "subremote", Name: "subremote",
URLs: []string{baseTestRepositoryPath}, URLs: []string{tmpDirWithInitialRepository.baseRepository.fileSystem.Root()},
}) })
if err != nil {
return err fakeLocalRepository.Fetch(&git.FetchOptions{
}
return repository.Fetch(&git.FetchOptions{
RemoteName: "subremote", RemoteName: "subremote",
}) })
return sc, fakeLocalRepository, repoCfg
} }

View File

@ -6,7 +6,6 @@ import (
"github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object" "github.com/go-git/go-git/v5/plumbing/object"
"gitlab.com/revalus/grm/internal/config" "gitlab.com/revalus/grm/internal/config"
"path"
"sort" "sort"
) )
@ -21,7 +20,7 @@ func NewStatusChecker(workspace string) StatusChecker {
} }
func findNumberOfCommitDiffs(srcCommit *object.Commit, dstCommit *object.Commit) int { func findNumberOfCommitDiffs(srcCommit *object.Commit, dstCommit *object.Commit) int {
// This function is a helper function to get only five latest items, based on given commit
getFiveElementsFromHashes := func(commit *object.Commit, hashedSlice *[]string) *object.Commit { getFiveElementsFromHashes := func(commit *object.Commit, hashedSlice *[]string) *object.Commit {
var err error var err error
@ -37,7 +36,6 @@ func findNumberOfCommitDiffs(srcCommit *object.Commit, dstCommit *object.Commit)
return commit return commit
} }
// Compare diff between sources by hash list (the same hash list must be present to assume the end of changes)
getRangeDiff := func(listFist, listSecond []string) (int, bool) { getRangeDiff := func(listFist, listSecond []string) (int, bool) {
diffRange := 0 diffRange := 0
@ -54,10 +52,8 @@ func findNumberOfCommitDiffs(srcCommit *object.Commit, dstCommit *object.Commit)
return diffRange, false return diffRange, false
} }
var baseCommitHashes []string baseCommitHashes := []string{}
var destCommitHashes []string destCommitHashes := []string{}
// Try to find all differences, limit only to five last changes to avoid reading whole repository at once
for { for {
if srcCommit != nil { if srcCommit != nil {
@ -84,8 +80,8 @@ func (sc StatusChecker) Command(repoCfg config.RepositoryConfig) CommandStatus {
Error: false, Error: false,
} }
repositoryPath := path.Join(sc.workspace, repoCfg.Dest) destPath := fmt.Sprintf("%v/%v", sc.workspace, repoCfg.Dest)
repo, err := git.PlainOpen(repositoryPath) repo, err := git.PlainOpen(destPath)
if err != nil { if err != nil {
cmdStatus.Error = true cmdStatus.Error = true

View File

@ -2,10 +2,7 @@ package commands
import ( import (
"fmt" "fmt"
"github.com/go-git/go-git/v5/plumbing/cache"
"github.com/go-git/go-git/v5/storage/filesystem"
"gitlab.com/revalus/grm/internal/config" "gitlab.com/revalus/grm/internal/config"
"path"
"testing" "testing"
"github.com/go-git/go-billy/v5/memfs" "github.com/go-git/go-billy/v5/memfs"
@ -15,10 +12,10 @@ import (
) )
func TestIfBranchesAreEqual(t *testing.T) { func TestIfBranchesAreEqual(t *testing.T) {
pathsToTest := prepareBasicRepository() tmpDirWithInitialRepository := getTestSetup()
fakeLocalRepo, err := git.Clone(memory.NewStorage(), memfs.New(), &git.CloneOptions{ fakeLocalRepo, err := git.Clone(memory.NewStorage(), memfs.New(), &git.CloneOptions{
URL: pathsToTest.baseTestRepository, URL: tmpDirWithInitialRepository.baseRepository.fileSystem.Root(),
}) })
checkErrorDuringPreparation(err) checkErrorDuringPreparation(err)
@ -45,9 +42,9 @@ func TestIfBranchesAreEqual(t *testing.T) {
func TestIfCurrentBranchIsDifferent(t *testing.T) { func TestIfCurrentBranchIsDifferent(t *testing.T) {
pathsToTest := prepareBasicRepository() tmpDirWithInitialRepository := getTestSetup()
fakeLocalRepo, err := git.Clone(memory.NewStorage(), memfs.New(), &git.CloneOptions{ fakeLocalRepo, err := git.Clone(memory.NewStorage(), memfs.New(), &git.CloneOptions{
URL: pathsToTest.baseTestRepository, URL: tmpDirWithInitialRepository.baseRepository.fileSystem.Root(),
}) })
checkErrorDuringPreparation(err) checkErrorDuringPreparation(err)
@ -88,21 +85,28 @@ func TestIfCurrentBranchIsDifferent(t *testing.T) {
result = findNumberOfCommitDiffs(currentBranchCommit, remoteBranchCommit) result = findNumberOfCommitDiffs(currentBranchCommit, remoteBranchCommit)
if result != 15 { if result != 15 {
t.Errorf("Expected to get 15 changes, instead of this got %v", result) t.Errorf("Expected to get 5 changes, instead of this got %v", result)
} }
} }
func TestCommandRepositoryDoesNotExists(t *testing.T) { func TestCommandRepositoryDoesNotExists(t *testing.T) {
pathsToTest := prepareBasicRepository() tmpDirWithInitialRepository := getTestSetup()
fsForLocalRepo, storageForTestRepo := getFSForLocalRepo("noMatterValue", tmpDirWithInitialRepository.rootFS)
_, err := git.Clone(storageForTestRepo, fsForLocalRepo, &git.CloneOptions{
URL: tmpDirWithInitialRepository.baseRepository.fileSystem.Root(),
})
checkErrorDuringPreparation(err)
sc := StatusChecker{ sc := StatusChecker{
workspace: pathsToTest.baseTestDirectory, workspace: tmpDirWithInitialRepository.rootFS.Root(),
} }
repoCfg := config.RepositoryConfig{ repoCfg := config.RepositoryConfig{
Name: "test", Name: "test",
Src: pathsToTest.baseTestRepository, Src: tmpDirWithInitialRepository.baseRepository.fileSystem.Root(),
Dest: pathsToTest.baseTestDirectory, Dest: tmpDirWithInitialRepository.rootFS.Root(),
} }
repoStatus := sc.Command(repoCfg) repoStatus := sc.Command(repoCfg)
@ -121,15 +125,12 @@ func TestCommandRepositoryDoesNotExists(t *testing.T) {
func TestCommandRepositoryNoRemoteBranch(t *testing.T) { func TestCommandRepositoryNoRemoteBranch(t *testing.T) {
pathsToTest := prepareBasicRepository() tmpDirWithInitialRepository := getTestSetup()
dirNameForLocalRepository := "sub-repository" dirNameForLocalRepository := "testRepo"
fsForLocalRepo, gitMetadataDirectory := prepareRepositoryDirectories( fsForLocalRepo, storageForTestRepo := getFSForLocalRepo(dirNameForLocalRepository, tmpDirWithInitialRepository.rootFS)
path.Join(pathsToTest.baseTestDirectory, dirNameForLocalRepository),
)
storageForTestRepo := filesystem.NewStorage(gitMetadataDirectory, cache.NewObjectLRUDefault())
fakeLocalRepository, err := git.Clone(storageForTestRepo, fsForLocalRepo, &git.CloneOptions{ fakeLocalRepository, err := git.Clone(storageForTestRepo, fsForLocalRepo, &git.CloneOptions{
URL: pathsToTest.baseTestRepository, URL: tmpDirWithInitialRepository.baseRepository.fileSystem.Root(),
}) })
checkErrorDuringPreparation(err) checkErrorDuringPreparation(err)
@ -137,12 +138,12 @@ func TestCommandRepositoryNoRemoteBranch(t *testing.T) {
checkErrorDuringPreparation(err) checkErrorDuringPreparation(err)
sc := StatusChecker{ sc := StatusChecker{
workspace: pathsToTest.baseTestDirectory, workspace: tmpDirWithInitialRepository.rootFS.Root(),
} }
repoCfg := config.RepositoryConfig{ repoCfg := config.RepositoryConfig{
Name: "test", Name: "test",
Src: pathsToTest.baseTestRepository, Src: tmpDirWithInitialRepository.baseRepository.fileSystem.Root(),
Dest: dirNameForLocalRepository, Dest: dirNameForLocalRepository,
} }
@ -163,21 +164,7 @@ func TestCommandRepositoryNoRemoteBranch(t *testing.T) {
func TestCommandAllCorrectWithoutChanges(t *testing.T) { func TestCommandAllCorrectWithoutChanges(t *testing.T) {
pathsToTest := prepareBasicRepository() sc, _, repoCfg, _ := getBaseForTestingSyncCommand()
subRepositoryDirectoryName := "sub-repository"
// Get new empty repository to compare with base repository
createAndCloneRepository(subRepositoryDirectoryName, pathsToTest)
sc := StatusChecker{
workspace: pathsToTest.baseTestDirectory,
}
repoCfg := config.RepositoryConfig{
Name: "test",
Src: pathsToTest.baseTestRepository,
Dest: subRepositoryDirectoryName,
}
repoStatus := sc.Command(repoCfg) repoStatus := sc.Command(repoCfg)
expectedMessage := "branch master - ( | origin | \u21910 \u21930 )" expectedMessage := "branch master - ( | origin | \u21910 \u21930 )"
@ -195,19 +182,7 @@ func TestCommandAllCorrectWithoutChanges(t *testing.T) {
} }
func TestCommandAllCorrectWithOneChange(t *testing.T) { func TestCommandAllCorrectWithOneChange(t *testing.T) {
pathsToTest := prepareBasicRepository() sc, fakeLocalRepository, repoCfg, _ := getBaseForTestingSyncCommand()
subRepositoryDirectoryName := "sub-repository"
fakeLocalRepository := createAndCloneRepository(subRepositoryDirectoryName, pathsToTest)
sc := StatusChecker{
workspace: pathsToTest.baseTestDirectory,
}
repoCfg := config.RepositoryConfig{
Name: "test",
Src: pathsToTest.baseTestRepository,
Dest: subRepositoryDirectoryName,
}
fakeLocalWorkTree, err := fakeLocalRepository.Worktree() fakeLocalWorkTree, err := fakeLocalRepository.Worktree()
checkErrorDuringPreparation(err) checkErrorDuringPreparation(err)
@ -232,26 +207,9 @@ func TestCommandAllCorrectWithOneChange(t *testing.T) {
} }
} }
func TestCommandMultiRemotesNoChanges(t *testing.T) { func TestCommandMultiRemoteNoChanges(t *testing.T) {
pathsToTest := prepareBasicRepository()
subRepositoryDirectoryName := "sub-repository"
fakeLocalRepository := createAndCloneRepository(subRepositoryDirectoryName, pathsToTest)
sc := StatusChecker{
workspace: pathsToTest.baseTestDirectory,
}
repoCfg := config.RepositoryConfig{
Name: "test",
Src: pathsToTest.baseTestRepository,
Dest: subRepositoryDirectoryName,
}
err := addLocalRepositoryAsAFakeRemoteRepository(fakeLocalRepository, pathsToTest.baseTestRepository)
if err != nil {
t.Errorf("Unexpected error %v", err)
}
sc, _, repoCfg := getBaseForTestingSyncMultipleRemote()
repoStatus := sc.Command(repoCfg) repoStatus := sc.Command(repoCfg)
expectedMessage := "branch master - ( | origin | \u21910 \u21930 ) - ( | subremote | \u21910 \u21930 )" expectedMessage := "branch master - ( | origin | \u21910 \u21930 ) - ( | subremote | \u21910 \u21930 )"
@ -267,25 +225,8 @@ func TestCommandMultiRemotesNoChanges(t *testing.T) {
} }
} }
func TestCommandMultiRemotesWithOneChange(t *testing.T) { func TestCommandMultiRemoteWithOneChange(t *testing.T) {
pathsToTest := prepareBasicRepository() sc, fakeLocalRepository, repoCfg := getBaseForTestingSyncMultipleRemote()
subRepositoryDirectoryName := "sub-repository"
fakeLocalRepository := createAndCloneRepository(subRepositoryDirectoryName, pathsToTest)
sc := StatusChecker{
workspace: pathsToTest.baseTestDirectory,
}
repoCfg := config.RepositoryConfig{
Name: "test",
Src: pathsToTest.baseTestRepository,
Dest: subRepositoryDirectoryName,
}
err := addLocalRepositoryAsAFakeRemoteRepository(fakeLocalRepository, pathsToTest.baseTestRepository)
if err != nil {
t.Errorf("Unexpected error %v", err)
}
fakeLocalWorkTree, err := fakeLocalRepository.Worktree() fakeLocalWorkTree, err := fakeLocalRepository.Worktree()
checkErrorDuringPreparation(err) checkErrorDuringPreparation(err)

View File

@ -1,7 +1,6 @@
package commands package commands
import ( import (
"errors"
"fmt" "fmt"
"gitlab.com/revalus/grm/internal/config" "gitlab.com/revalus/grm/internal/config"
@ -27,14 +26,15 @@ const (
func fetchRepository(repo *git.Repository) (bool, error) { func fetchRepository(repo *git.Repository) (bool, error) {
err := repo.Fetch(&git.FetchOptions{}) err := repo.Fetch(&git.FetchOptions{})
switch { if err == git.NoErrAlreadyUpToDate {
case errors.Is(err, git.NoErrAlreadyUpToDate):
return false, nil return false, nil
case errors.Is(err, git.NoErrAlreadyUpToDate):
return false, nil
default:
return true, nil
} }
if err != nil && err != git.NoErrAlreadyUpToDate {
return false, err
}
return true, nil
} }
func cloneRepository(destPath string, repoCfg *config.RepositoryConfig) (bool, error) { func cloneRepository(destPath string, repoCfg *config.RepositoryConfig) (bool, error) {
@ -62,23 +62,21 @@ func (s Synchronizer) Command(repoCfg config.RepositoryConfig) CommandStatus {
destPath := fmt.Sprintf("%v/%v", s.workspace, repoCfg.Dest) destPath := fmt.Sprintf("%v/%v", s.workspace, repoCfg.Dest)
repo, err := git.PlainOpen(destPath) repo, err := git.PlainOpen(destPath)
if err != nil { if err != nil && err == git.ErrRepositoryNotExists {
if errors.Is(err, git.ErrRepositoryNotExists) {
cmdStatus.Changed, err = cloneRepository(destPath, &repoCfg) cmdStatus.Changed, err = cloneRepository(destPath, &repoCfg)
cmdStatus.Message = syncCloned cmdStatus.Message = syncCloned
} else { } else if err == nil {
cmdStatus.Error = true
cmdStatus.Message = err.Error()
}
return cmdStatus
}
cmdStatus.Changed, err = fetchRepository(repo) cmdStatus.Changed, err = fetchRepository(repo)
if cmdStatus.Changed { if cmdStatus.Changed {
cmdStatus.Message = syncFetched cmdStatus.Message = syncFetched
} else { } else {
cmdStatus.Message = syncUpToDate cmdStatus.Message = syncUpToDate
} }
} else {
cmdStatus.Error = true
cmdStatus.Message = err.Error()
return cmdStatus
}
if err != nil { if err != nil {
cmdStatus.Error = true cmdStatus.Error = true

View File

@ -16,14 +16,14 @@ func TestSyncInit(t *testing.T) {
func TestSyncCommand(t *testing.T) { func TestSyncCommand(t *testing.T) {
pathsToTest := prepareBasicRepository() testSetup := getTestSetup()
sync := Synchronizer{ sync := Synchronizer{
workspace: pathsToTest.baseTestDirectory, workspace: testSetup.rootFS.Root(),
} }
cfg := config.RepositoryConfig{ cfg := config.RepositoryConfig{
Src: fmt.Sprintf("file://%v", pathsToTest.baseTestRepository), Src: fmt.Sprintf("file://%v", testSetup.baseRepository.fileSystem.Root()),
Dest: "awesome-go", Dest: "awesome-go",
} }
@ -32,11 +32,10 @@ func TestSyncCommand(t *testing.T) {
t.Errorf("Unexpected error: %v", cloneStatus.Message) t.Errorf("Unexpected error: %v", cloneStatus.Message)
} }
info, err := os.Stat(fmt.Sprintf("%v/awesome-go/.git", pathsToTest.baseTestDirectory)) info, err := os.Stat(fmt.Sprintf("%v/awesome-go/.git", testSetup.rootFS.Root()))
if err != nil { if err != nil {
t.Errorf("Unexpected error: %v", err.Error()) t.Errorf("Unexpected error: %v", err.Error())
} }
if !info.IsDir() { if !info.IsDir() {
t.Errorf("Expected that the selected path is dir") t.Errorf("Expected that the selected path is dir")
} }

View File

@ -41,9 +41,9 @@ func GetRepositoryConfig(data []byte, fileExtension string) (Configuration, erro
return Configuration{}, errors.New(errorMessage) return Configuration{}, errors.New(errorMessage)
} }
if repo.Name == "" { if repo.Name == "" {
splitGit := strings.Split(repo.Src, "/") splittedGit := strings.Split(repo.Src, "/")
nameWithExtension := splitGit[len(splitGit)-1] nameWithExcention := splittedGit[len(splittedGit)-1]
name := strings.Split(nameWithExtension, ".")[0] name := strings.Split(nameWithExcention, ".")[0]
config.Repositories[index].Name = name config.Repositories[index].Name = name
} }
if repo.Dest == "" { if repo.Dest == "" {

View File

@ -1,7 +1,6 @@
package config package config
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
"reflect" "reflect"
@ -102,9 +101,9 @@ repositories:
`) `)
_, err := GetRepositoryConfig(exampleWrongYamlConfig, "yaml") _, err := GetRepositoryConfig(exampleWrongYamlConfig, "yaml")
expectedError := errors.New(fmt.Sprintf(errMissingSrcField, 0)) expectedError := fmt.Sprintf(errMissingSrcField, 0)
if errors.Is(err, expectedError) { if err.Error() != expectedError {
t.Errorf("Expected to get error with value %v, instead of this got: %v", expectedError, err.Error()) t.Errorf("Expected to get error with value %v, instead of this got: %v", expectedError, err.Error())
} }
} }
@ -128,7 +127,7 @@ repositories:
} }
expectedError := getDuplicateFieldError("name", "example2", []int{1, 2}) expectedError := getDuplicateFieldError("name", "example2", []int{1, 2})
if errors.Is(err, expectedError) { if err.Error() != expectedError.Error() {
t.Errorf("Expected to get error with value %v, instead of this got: %v", expectedError.Error(), err.Error()) t.Errorf("Expected to get error with value %v, instead of this got: %v", expectedError.Error(), err.Error())
} }
} }
@ -152,7 +151,7 @@ repositories:
expectedError := getDuplicateFieldError("dest", "example", []int{1, 2}) expectedError := getDuplicateFieldError("dest", "example", []int{1, 2})
if errors.Is(err, expectedError) { if err.Error() != expectedError.Error() {
t.Errorf("Expected to get error with value \"%v\", instead of this got: \"%v\"", expectedError, err) t.Errorf("Expected to get error with value \"%v\", instead of this got: \"%v\"", expectedError, err)
} }
} }

View File

@ -61,18 +61,18 @@ func (g *GitRepositoryManager) Run(w io.Writer) int {
exitCode := 0 exitCode := 0
if len(g.cliArguments.LimitToTags) != 0 { if len(g.cliArguments.LimitToTags) != 0 {
err := g.limitRepositoriesToTags() err := g.limitTags()
if err != nil { if err != nil {
echo.ErrorfMsg(err.Error()) echo.ErrorfMsg(err.Error())
return 1 exitCode = 1
} }
} }
if g.cliArguments.LimitToName != "" { if g.cliArguments.LimitToName != "" {
err := g.limitRepositoryToName() err := g.limitName()
if err != nil { if err != nil {
echo.ErrorfMsg(err.Error()) echo.ErrorfMsg(err.Error())
return 1 exitCode = 1
} }
} }
@ -108,7 +108,7 @@ func describeStatus(status commands.CommandStatus) {
} }
} }
func (g *GitRepositoryManager) limitRepositoriesToTags() error { func (g *GitRepositoryManager) limitTags() error {
limitedTagsTmp := []config.RepositoryConfig{} limitedTagsTmp := []config.RepositoryConfig{}
for _, item := range g.configuration.Repositories { for _, item := range g.configuration.Repositories {
@ -123,7 +123,7 @@ func (g *GitRepositoryManager) limitRepositoriesToTags() error {
return nil return nil
} }
func (g *GitRepositoryManager) limitRepositoryToName() error { func (g *GitRepositoryManager) limitName() error {
for _, item := range g.configuration.Repositories { for _, item := range g.configuration.Repositories {
if g.cliArguments.LimitToName == item.Name { if g.cliArguments.LimitToName == item.Name {
g.configuration.Repositories = []config.RepositoryConfig{item} g.configuration.Repositories = []config.RepositoryConfig{item}

View File

@ -163,7 +163,7 @@ func TestLimitTags(t *testing.T) {
} }
echo.Color(false) echo.Color(false)
echo.Output(emt) echo.Output(emt)
grm.limitRepositoriesToTags() grm.limitTags()
grm.runCommand(fakeCommand) grm.runCommand(fakeCommand)
} }
@ -192,7 +192,7 @@ func TestLimitName(t *testing.T) {
} }
echo.Color(false) echo.Color(false)
echo.Output(emt) echo.Output(emt)
grm.limitRepositoryToName() grm.limitName()
grm.runCommand(fakeCommand) grm.runCommand(fakeCommand)
} }
func TestRunWithNotExistingNameInLimit(t *testing.T) { func TestRunWithNotExistingNameInLimit(t *testing.T) {

View File

@ -29,7 +29,7 @@ func TestGetFileExtension(t *testing.T) {
} }
func TestErrorInGetExtensionFile(t *testing.T) { func TestErrorInGetExcensionFile(t *testing.T) {
result, err := getFileExtension("test") result, err := getFileExtension("test")