mirror/merlin/sync/command_test.go

79 lines
1.8 KiB
Go

package sync
import (
"path/filepath"
"reflect"
"testing"
"git.csclub.uwaterloo.ca/public/merlin/config"
"git.csclub.uwaterloo.ca/public/merlin/logger"
)
// probably move this file
var CONFIG_PATH = "config_test.ini"
func dummyRepoConf(name string, syncType string, frequencyStr string, localDir string, rsyncHost string, rsyncDir string) *config.Repo {
doneChan := make(chan config.SyncResult)
stopChan := make(chan struct{})
repoLogFile := filepath.Join("test_files", name, name+".log")
logger := logger.NewLogger(name, repoLogFile)
return &config.Repo{
Name: name,
SyncType: syncType,
FrequencyStr: frequencyStr,
Frequency: 0,
MaxTime: config.DEFAULT_MAX_TIME,
LocalDir: localDir,
RsyncHost: rsyncHost,
RsyncDir: rsyncDir,
RsyncUser: "",
PasswordFile: "",
StateFile: "",
RepoLogFile: repoLogFile,
Logger: logger,
RsyncLogFile: "",
ZfssyncLogFile: "",
DoneChan: doneChan,
StopChan: stopChan,
State: config.RepoState{
IsRunning: false,
LastAttemptStartTime: 0,
LastAttemptRunTime: 0,
LastAttemptExit: config.NOT_RUN_YET,
},
}
}
func TestGetSyncCommand(t *testing.T) {
config.Conf.DownloadDir = "test_files"
testData := []struct {
repoConf *config.Repo
expected []string
}{
{
repoConf: dummyRepoConf("ubuntu", "csc-sync-debian", "bi-hourly", "ubuntu", "archive.ubuntu.com", "ubuntu"),
expected: []string{},
},
}
// WIP, make test pass for now
return
for _, test := range testData {
syncCommand := getSyncCommand(test.repoConf)
// check for correct command output
if !reflect.DeepEqual(syncCommand, test.expected) {
t.Errorf("Invalid command string for %s repo", test.repoConf.Name)
}
// check if download dir was created
}
}