2021-11-02 18:19:31 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"gitlab.com/revalus/grm/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSyncInit(t *testing.T) {
|
|
|
|
sync := NewSynchronizer("test")
|
|
|
|
if sync.workspace != "test" {
|
|
|
|
t.Errorf("Expected to get \"test\", instead of this got %v", sync.workspace)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSyncCommand(t *testing.T) {
|
|
|
|
|
2021-11-06 23:43:53 +00:00
|
|
|
testSetup := getTestSetup()
|
2021-11-02 18:19:31 +00:00
|
|
|
|
|
|
|
sync := Synchronizer{
|
2021-11-06 23:43:53 +00:00
|
|
|
workspace: testSetup.rootFS.Root(),
|
2021-11-02 18:19:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cfg := config.RepositoryConfig{
|
2021-11-06 23:43:53 +00:00
|
|
|
Src: fmt.Sprintf("file://%v", testSetup.baseRepository.fileSystem.Root()),
|
2021-11-02 18:19:31 +00:00
|
|
|
Dest: "awesome-go",
|
|
|
|
}
|
|
|
|
|
2021-11-08 17:30:45 +00:00
|
|
|
cloneStatus := sync.Command(cfg)
|
2021-11-02 18:19:31 +00:00
|
|
|
if cloneStatus.Error {
|
|
|
|
t.Errorf("Unexpected error: %v", cloneStatus.Message)
|
|
|
|
}
|
|
|
|
|
2021-11-06 23:43:53 +00:00
|
|
|
info, err := os.Stat(fmt.Sprintf("%v/awesome-go/.git", testSetup.rootFS.Root()))
|
2021-11-02 18:19:31 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unexpected error: %v", err.Error())
|
|
|
|
}
|
|
|
|
if !info.IsDir() {
|
|
|
|
t.Errorf("Expected that the selected path is dir")
|
|
|
|
}
|
|
|
|
|
|
|
|
if cloneStatus.Changed != true {
|
|
|
|
t.Errorf("Expected that the status is changed")
|
|
|
|
}
|
|
|
|
|
|
|
|
if cloneStatus.Message != syncCloned {
|
|
|
|
t.Errorf("Expected to get %v, instead of this got %v", syncCloned, cloneStatus.Message)
|
|
|
|
}
|
|
|
|
|
2021-11-08 17:30:45 +00:00
|
|
|
fetchStatus := sync.Command(cfg)
|
2021-11-02 18:19:31 +00:00
|
|
|
if fetchStatus.Error {
|
|
|
|
t.Errorf("Unexpected error: %v", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
if fetchStatus.Changed != false {
|
|
|
|
t.Errorf("Expected that the status is not changed")
|
|
|
|
}
|
|
|
|
|
|
|
|
if fetchStatus.Message != syncUpToDate {
|
|
|
|
t.Errorf("Expected to get %v, instead of this got %v", syncUpToDate, cloneStatus.Message)
|
|
|
|
}
|
|
|
|
}
|