GitRepositoryManager/internal/commands/sync_cmd_test.go
Mikołaj Pęczkowski 68636d5e64 Improve code readability #1
+ Improved tests readability of common_utils_test.go
+ Fixed minor typos
2024-06-16 15:27:55 +02:00

65 lines
1.4 KiB
Go

package commands
import (
"fmt"
"gitlab.com/revalus/grm/internal/config"
"os"
"testing"
)
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) {
pathsToTest := prepareBasicRepository()
sync := Synchronizer{
workspace: pathsToTest.baseTestDirectory,
}
cfg := config.RepositoryConfig{
Src: fmt.Sprintf("file://%v", pathsToTest.baseTestRepository),
Dest: "awesome-go",
}
cloneStatus := sync.Command(cfg)
if cloneStatus.Error {
t.Errorf("Unexpected error: %v", cloneStatus.Message)
}
info, err := os.Stat(fmt.Sprintf("%v/awesome-go/.git", pathsToTest.baseTestDirectory))
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)
}
fetchStatus := sync.Command(cfg)
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)
}
}