From 35af367d629dfc731ef3a03ee45b17dba9585c56 Mon Sep 17 00:00:00 2001 From: Max Erenberg Date: Tue, 4 Apr 2023 00:17:15 -0400 Subject: [PATCH] fix unit tests --- merlin/.gitignore | 1 + merlin/arthur/arthur_test.go | 39 +- merlin/config/config.go | 3 + merlin/config/config_test.go | 3 +- merlin/config/test_files/eelinux | 8 +- merlin/merlin-config-all.ini | 580 ------------------ merlin/test/debianBased | 1 - merlin/test/debian_update | 5 - .../debian/trace/mirror.csclub.uwaterloo.ca | 1 - .../hobo-linux/mirror.csclub.uwaterloo.ca | 1 - .../ubuntu/trace/mirror.csclub.uwaterloo.ca | 1 - merlin/test/mirrors | 1 - merlin/test/sync | 5 - merlin/test/test_repo_dict | 30 - .../test/trace/leningradskaya.canonical.com | 1 - .../{ => test_utils}/merlin-config-test.ini | 14 +- merlin/test_utils/test_utils.go | 50 ++ 17 files changed, 92 insertions(+), 652 deletions(-) delete mode 100644 merlin/merlin-config-all.ini delete mode 100644 merlin/test/debianBased delete mode 100755 merlin/test/debian_update delete mode 100755 merlin/test/mirror/debian/trace/mirror.csclub.uwaterloo.ca delete mode 100755 merlin/test/mirror/hobo-linux/mirror.csclub.uwaterloo.ca delete mode 100755 merlin/test/mirror/ubuntu/trace/mirror.csclub.uwaterloo.ca delete mode 100644 merlin/test/mirrors delete mode 100755 merlin/test/sync delete mode 100644 merlin/test/test_repo_dict delete mode 100755 merlin/test/trace/leningradskaya.canonical.com rename merlin/{ => test_utils}/merlin-config-test.ini (61%) create mode 100644 merlin/test_utils/test_utils.go diff --git a/merlin/.gitignore b/merlin/.gitignore index f0c1e96..6cef57c 100644 --- a/merlin/.gitignore +++ b/merlin/.gitignore @@ -8,3 +8,4 @@ /state/ /merlin /merlin.sock +/test_tmp diff --git a/merlin/arthur/arthur_test.go b/merlin/arthur/arthur_test.go index 49dac9c..5ef8587 100644 --- a/merlin/arthur/arthur_test.go +++ b/merlin/arthur/arthur_test.go @@ -9,8 +9,13 @@ import ( "git.csclub.uwaterloo.ca/public/merlin/config" "git.csclub.uwaterloo.ca/public/merlin/logger" + "git.csclub.uwaterloo.ca/public/merlin/test_utils" ) +func init() { + os.Chdir("..") +} + // Test that GetCommand is able to accept a connection and parse a request for the status func TestStatusCommand(t *testing.T) { r, w := net.Pipe() @@ -87,11 +92,12 @@ func TestSendStatus(t *testing.T) { if err != nil { t.Errorf(err.Error()) } - expected := `Repository Last Synced Next Expected Sync Running -alinux Sun, 02 May 2021 20:00:00 EDT Sun, 09 May 2021 20:00:03 EDT true -eeeee Sun, 13 Sep 2020 08:26:40 EDT Tue, 13 Oct 2020 08:26:40 EDT true -lnux Mon, 20 Dec 2021 06:33:20 EST Tue, 21 Dec 2021 06:33:20 EST false -` + expected := (` +Repository Last Synced Next Expected Sync Last Exit Running +alinux Sun, 02 May 2021 20:00:00 EDT Sun, 09 May 2021 20:00:03 EDT completed true +eeeee Sun, 13 Sep 2020 08:26:40 EDT Tue, 13 Oct 2020 08:26:40 EDT completed true +lnux Mon, 20 Dec 2021 06:33:20 EST Tue, 21 Dec 2021 06:33:20 EST completed false +`)[1:] if expected != string(msg) { t.Errorf("Expected:\n" + expected + "\nGot:\n" + string(msg)) } @@ -99,6 +105,9 @@ lnux Mon, 20 Dec 2021 06:33:20 EST Tue, 21 Dec 2021 06:33:20 EST // Test that ForceSync behaves properly func TestForceSync(t *testing.T) { + defer test_utils.TeardownTest() + test_utils.SetupTest() + saveRepos := config.Repos saveRepoMap := config.RepoMap doneChan := make(chan config.SyncResult) @@ -111,7 +120,8 @@ func TestForceSync(t *testing.T) { // Part 1: run a dummy sync repo := config.Repo{ Name: "nux", - SyncType: "csc-sync-dummy", + SyncType: "csc-sync-exec", + ExecStr: "true", Frequency: 7 * 86400, MaxTime: 30, Logger: logger.NewLogger("nux", "/tmp/merlin_force_sync_test_log", false), @@ -202,7 +212,7 @@ func TestStartListener(t *testing.T) { saveConf := config.Conf connChan := make(chan net.Conn) stopLisChan := make(chan struct{}) - wait := make(chan struct{}) + stopLisAckChan := make(chan struct{}) defer func() { config.Conf = saveConf close(connChan) @@ -215,32 +225,31 @@ func TestStartListener(t *testing.T) { // Test 1: check that closing/sending something to stopLisChan will stop the listener // and that a new listener can be created after stopping the old one go func() { - StartListener(connChan, stopLisChan) - wait <- struct{}{} + StartListener(connChan, stopLisChan, stopLisAckChan) }() stopLisChan <- struct{}{} select { - case <-wait: + case <-stopLisAckChan: case <-time.After(3 * time.Second): t.Errorf("StartListener should stop when struct{}{} is sent to stopLisChan") } go func() { - StartListener(connChan, stopLisChan) - wait <- struct{}{} + StartListener(connChan, stopLisChan, stopLisAckChan) }() close(stopLisChan) select { - case <-wait: + case <-stopLisAckChan: case <-time.After(3 * time.Second): t.Errorf("StartListener should stop when stopLisChan is closed") } - close(wait) + close(stopLisAckChan) // Test 2: check that connections can be made to the unix socket // this test does not appear to be very stable (I think there is a race condition somewhere) stopLisChan = make(chan struct{}) - go StartListener(connChan, stopLisChan) + stopLisAckChan = make(chan struct{}) + go StartListener(connChan, stopLisChan, stopLisAckChan) waitForMsg := func(expected string) { select { case conn := <-connChan: diff --git a/merlin/config/config.go b/merlin/config/config.go index abc5c26..f2c4adc 100644 --- a/merlin/config/config.go +++ b/merlin/config/config.go @@ -331,11 +331,14 @@ func (repo *Repo) SaveState() { state_cfg := ini.Empty() if err := ini.ReflectFrom(state_cfg, &repo.State); err != nil { repo.Logger.Error(err.Error()) + return } file, err := os.OpenFile(repo.StateFile, os.O_RDWR|os.O_CREATE, 0644) if err != nil { repo.Logger.Error(err.Error()) + return } + defer file.Close() if _, err := state_cfg.WriteTo(file); err != nil { repo.Logger.Error(err.Error()) } diff --git a/merlin/config/config_test.go b/merlin/config/config_test.go index 42f4aa8..b3b1932 100644 --- a/merlin/config/config_test.go +++ b/merlin/config/config_test.go @@ -37,6 +37,7 @@ func TestLoadConfig(t *testing.T) { stopChan := make(chan struct{}) LoadConfig("config_test.ini", doneChan, stopChan) expectedConfig := Config{ + Hostname: "mirror.csclub.uwaterloo.ca", MaxJobs: 6, IPv4Address: "129.97.134.129", IPv6Address: "2620:101:f000:4901:c5c::129", @@ -94,7 +95,7 @@ func TestLoadConfig(t *testing.T) { State: &RepoState{ IsRunning: false, LastAttemptStartTime: 0, - LastAttemptExit: 0, + LastAttemptExit: 2, }, } diff --git a/merlin/config/test_files/eelinux b/merlin/config/test_files/eelinux index 571d74e..2695c60 100644 --- a/merlin/config/test_files/eelinux +++ b/merlin/config/test_files/eelinux @@ -1,5 +1,7 @@ -is_running = false -last_attempt_time = 1600000000 -last_attempt_runtime = 100 +is_running = false +last_attempt_time = 1600000000 +last_attempt_exit = 1 + +ime = 100 last_attempt_exit = 1 diff --git a/merlin/merlin-config-all.ini b/merlin/merlin-config-all.ini deleted file mode 100644 index ec1e733..0000000 --- a/merlin/merlin-config-all.ini +++ /dev/null @@ -1,580 +0,0 @@ -max_jobs = 6 - -sock_path = /run/merlin/merlin.sock -states_path = /home/test-mirror/merlin/states - -; log_path? (just spes a dir and make files) -log_file = /tmp/test-mirror/test.log - -ipv4_address = 129.97.134.129 -ipv6_address = 2620:101:f000:4901:c5c::129 -download_dir = /tmp/test-mirror - -; 5 hours -; default_max_time = 18000 -; add default max_time -; add default frequency -; add default sync_type - -; [DEFAULT] -; - - -[debian] -sync_type = csc-sync-debian -frequency = bi-hourly -local_dir = debian -rsync_host = debian.mirror.rafal.ca -rsync_dir = debian - -; [debian-cdimage] -; sync_type = csc-sync-cdimage -; frequency = twice-daily -; local_dir = debian-cdimage -; rsync_host = cdimage.debian.org -; rsync_dir = cdimage - -[ubuntu] -sync_type = csc-sync-debian -frequency = bi-hourly -local_dir = ubuntu -rsync_host = archive.ubuntu.com -rsync_dir = ubuntu -trace_host = drescher.canonical.com - -[ubuntu-ports] -sync_type = csc-sync-debian -frequency = bi-hourly -local_dir = ubuntu-ports -rsync_host = ports.ubuntu.com -rsync_dir = ubuntu-ports -trace_host = drescher.canonical.com - -[linuxmint-packages] -sync_type = csc-sync-debian -frequency = bi-hourly -local_dir = linuxmint-packages -rsync_host = rsync-packages.linuxmint.com -rsync_dir = packages - -[debian-multimedia] -sync_type = csc-sync-debian -frequency = bi-hourly -local_dir = debian-multimedia -rsync_host = www.deb-multimedia.org -rsync_dir = deb - -[debian-backports] -sync_type = csc-sync-debian -frequency = bi-hourly -local_dir = debian-backports -rsync_host = debian.mirror.rafal.ca -rsync_dir = debian-backports - -; [debian-volatile] -; sync_type = csc-sync-debian -; frequency = bi-hourly -; local_dir = debian-volatile -; rsync_host = debian.mirror.rafal.ca -; rsync_dir = debian-volatile - -[debian-security] -sync_type = csc-sync-debian -frequency = twice-hourly -local_dir = debian-security -rsync_host = rsync.security.debian.org -rsync_dir = debian-security -; trace_host = security-master.debian.org - -[ubuntu-releases] -sync_type = csc-sync-standard -frequency = bi-hourly -local_dir = ubuntu-releases -rsync_host = rsync.releases.ubuntu.com -rsync_dir = releases - -[xubuntu-releases] -sync_type = csc-sync-standard -frequency = bi-hourly -local_dir = xubuntu-releases -rsync_host = cdimage.ubuntu.com -rsync_dir = cdimage/xubuntu/releases/ - -; [emdebian] -; sync_type = csc-sync-badperms -; frequency = twice-daily -; local_dir = emdebian -; rsync_host = www.emdebian.org -; rsync_dir = debian - -[puppylinux] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = puppylinux -rsync_host = distro.ibiblio.org -rsync_dir = puppylinux - -[CPAN] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = CPAN -rsync_host = cpan-rsync.perl.org -rsync_dir = CPAN - -[CRAN] -sync_type = csc-sync-ssh -frequency = twice-daily -local_dir = CRAN -rsync_host = cran.r-project.org -; address is $RSYNC_HOST:$RSYNC_DIR/ (and $RSYNC_DIR="") but rsync_dir should not be empty -rsync_dir = / -rsync_user = cran-rsync -password_file = ~/.ssh/id_cran_rsa - -[CTAN] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = CTAN -rsync_host = rsync.dante.ctan.org -rsync_dir = CTAN - -; [openoffice] -; sync_type = csc-sync-standard -; frequency = twice-daily -; local_dir = openoffice -; rsync_host = rsync.services.openoffice.org -; rsync_host = ftp.snt.utwente.nl -; rsync_dir = openoffice-extended - -[fedora-epel] -sync_type = csc-sync-standard -frequency = bi-hourly -local_dir = fedora/epel -rsync_host = mirrors.kernel.org -rsync_dir = fedora-epel -; ~/bin/report_mirror > /dev/null - -[cygwin] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = cygwin -rsync_host = cygwin.com -rsync_dir = cygwin-ftp - -[gnu] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = gnu -; rsync_host = mirrors.ibiblio.org -; rsync_dir = gnuftp/gnu/ -rsync_host = ftp.gnu.org -rsync_dir = gnu - -[nongnu] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = nongnu -rsync_host = dl.sv.gnu.org -rsync_dir = releases - -[mysql] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = mysql -; rsync_host = mysql.he.net -; rsync_dir = mysql -rsync_host = rsync.mirrorservice.org -rsync_dir = ftp.mysql.com - -; No longer syncs, and no longer really relevant -; [mozdev] -; sync_type = csc-sync-standard -; frequency = twice-daily -; local_dir = mozdev -; rsync_host = rsync.mozdev.org -; rsync_dir = mozdev - -[gnome] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = gnome -rsync_host = master.gnome.org -rsync_dir = gnomeftp -; password_file = gnome -; password_file = /home/mirror/passwords/gnome - -[damnsmalllinux] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = damnsmalllinux -rsync_host = ftp.heanet.ie -rsync_dir = mirrors/damnsmalllinux.org/ - -[linuxmint] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = linuxmint -rsync_host = pub.linuxmint.com -rsync_dir = pub - -[kernel.org-linux] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = kernel.org/linux -rsync_host = rsync.kernel.org -rsync_dir = pub/linux/ - -[kernel.org-software] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = kernel.org/software -rsync_host = rsync.kernel.org -rsync_dir = pub/software/ - -[apache] -sync_type = csc-sync-apache -frequency = twice-daily -local_dir = apache -rsync_host = rsync.us.apache.org -rsync_dir = apache-dist - -[eclipse] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = eclipse -rsync_host = download.eclipse.org -rsync_dir = eclipseMirror - -[kde] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = kde -rsync_host = rsync.kde.org -rsync_dir = kdeftp - -[kde-applicationdata] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = kde-applicationdata -rsync_host = rsync.kde.org -rsync_dir = applicationdata - -; We are a Tier 1 arch mirror (https://bugs.archlinux.org/task/52853) -; so our IP is important. -; our rsync_host is rsync://rsync.archlinux.org/ftp_tier1 -[archlinux] -; csc-sync-standard archlinux archlinux.mirror.rafal.ca archlinux -sync_type = csc-sync-archlinux -frequency = five-minutely -local_dir = archlinux -rsync_host = rsync.archlinux.org -rsync_dir = ftp_tier1 -trace_host = http://rsync.archlinux.org/lastupdate - -[debian-ports] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = debian-ports -rsync_host = ftp.de.debian.org -rsync_dir = debian-ports - -[slackware] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = slackware -rsync_host = slackware.cs.utah.edu -rsync_dir = slackware - -[debian-cd] -sync_type = csc-sync-debian-cd -frequency = twice-daily - -[x.org] -; csc-sync-standard x.org xorg.freedesktop.org xorg-archive -; csc-sync-standard x.org mirror.us.leaseweb.net xorg -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = x.org -rsync_host = rsync.mirrorservice.org -rsync_dir = ftp.x.org/pub - -[centos] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = centos -rsync_host = us-msync.centos.org -rsync_dir = CentOS - -[opensuse] -; "--exclude distribution/.timestamp_invisible" -sync_type = csc-sync-standard -frequency = bi-hourly -local_dir = opensuse -rsync_host = stage.opensuse.org -rsync_dir = opensuse-full/opensuse/ - -[FreeBSD] -; Has not updated since at least June 2018 -; csc-sync-standard FreeBSD ftp10.us.freebsd.org FreeBSD -sync_type = csc-sync-standard -; csc-sync-standard FreeBSD ftp3.us.freebsd.org FreeBSD/ -frequency = twice-daily -local_dir = FreeBSD -rsync_host = ftp2.uk.freebsd.org -rsync_dir = ftp.freebsd.org/pub/FreeBSD/ - -[fedora-enchilada] -; csc-sync-standard fedora/linux mirrors.kernel.org fedora-enchilada/linux/ --ignore-errors && ~/bin/report_mirror >/dev/null -sync_type = csc-sync-standard -frequency = bi-hourly -local_dir = fedora/linux -rsync_host = mirrors.kernel.org -rsync_dir = fedora-enchilada/linux/ -; ~/bin/report_mirror >/dev/null - -[ubuntu-ports-releases] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = ubuntu-ports-releases -rsync_host = cdimage.ubuntu.com -rsync_dir = cdimage/releases/ - -[gentoo-distfiles] -sync_type = csc-sync-gentoo -frequency = bi-hourly - -[gentoo-portage] -sync_type = csc-sync-standard -frequency = twice_hourly -local_dir = gentoo-portage -rsync_host = rsync1.us.gentoo.org -rsync_dir = gentoo-portage - -; This project is no longer available for mirroring -; https://bugzilla.mozilla.org/show_bug.cgi?id=807543 -; [mozilla.org] -; csc-sync-standard mozilla.org releases-rsync.mozilla.org mozilla-releases -; frequency = twice_hourly - -[gutenberg] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = gutenberg -rsync_host = ftp@ftp.ibiblio.org -rsync_dir = gutenberg - -[racket-installers] -sync_type = csc-sync-wget -frequency = twice-daily -local_dir = racket/racket-installers -rsync_host = https://mirror.racket-lang.org/installers/ -; for csc-sync-wget the --cut-dirs=1 is hardcoded - -[plt-bundles] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = racket/plt-bundles -rsync_host = mirror.racket-lang.org -rsync_dir = plt-bundles - -[OpenBSD] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = OpenBSD -rsync_host = ftp3.usa.openbsd.org -rsync_dir = ftp - -[xiph] -; csc-sync-standard xiph downloads.xiph.org xiph/releases -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = xiph -rsync_host = ftp.osuosl.org -rsync_dir = xiph - -; We currently don't have the disk space -[netbsd] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = NetBSD -rsync_host = rsync.netbsd.org -rsync_dir = NetBSD - -[netbsd-pkgsrc] -sync_type = csc-sync-standard -; csc-sync-standard pkgsrc rsync3.jp.netbsd.org pub/pkgsrc/ -frequency = twice-daily -local_dir = pkgsrc -rsync_host = rsync.netbsd.org -rsync_dir = pkgsrc - -[macports-release] -sync_type = csc-sync-standard -frequency = bi-hourly -local_dir = MacPorts/release -rsync_host = rsync.macports.org -rsync_dir = macports/release/ - -[macports-distfiles] -sync_type = csc-sync-standard -frequency = bi-hourly -local_dir = MacPorts/mpdistfiles -rsync_host = rsync.macports.org -rsync_dir = macports/distfiles/ - -; [raspberrypi] -; sync_type = csc-sync-standard -; frequency = twice-daily -; local_dir = raspberrypi -; rsync_host = mirrors.rit.edu -; rsync_dir = rpi - -[sagemath] -; csc-sync-standard sage mirror.clibre.uqam.ca sage -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = sage -rsync_host = rsync.sagemath.org -rsync_dir = sage - -; [cs136] -; csc-sync-ssh uw-coursewear/cs136 linux024.student.cs.uwaterloo.ca /u/cs136/mirror.uwaterloo.ca csc01 ~/.ssh/id_rsa_csc01 -; frequency = hourly - -[vlc] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = vlc -rsync_host = rsync.videolan.org -rsync_dir = videolan-ftp - -[qtproject] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = qtproject -rsync_host = master.qt.io -rsync_dir = qt-all - -[tdf] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = tdf -rsync_host = rsync.documentfoundation.org -rsync_dir = tdf-pub - -[saltstack] -sync_type = csc-sync-s3 -frequency = daily -local_dir = saltstack -rsync_host = https://s3.repo.saltproject.io - -; [kali] -; csc-sync-standard kali kali.mirror.globo.tech kali -; frequency = twice-daily - -; [kali-images] -; csc-sync-standard kali-images kali.mirror.globo.tech kali-images -; frequency = twice-daily - -[alpine] -sync_type = csc-sync-standard -frequency = hourly -local_dir = alpine -rsync_host = rsync.alpinelinux.org -rsync_dir = alpine - -[raspbian] -sync_type = csc-sync-standard -frequency = bi-hourly -local_dir = raspbian -rsync_host = archive.raspbian.org -rsync_dir = archive - -[raspberrypi] -sync_type = csc-sync-standard-ipv6 -frequency = bi-hourly -local_dir = raspberrypi -rsync_host = apt-repo.raspberrypi.org -rsync_dir = archive - -[ipfire] -sync_type = csc-sync-standard -frequency = hourly -local_dir = ipfire -rsync_host = rsync.ipfire.org -rsync_dir = full - -[manjaro] -sync_type = csc-sync-standard -frequency = hourly -local_dir = manjaro -rsync_host = mirrorservice.org -rsync_dir = repo.manjaro.org/repos/ - -[scientific] -sync_type = csc-sync-standard -frequency = bi-hourly -local_dir = scientific -rsync_host = rsync.scientificlinux.org -rsync_dir = scientific - -[mxlinux] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = mxlinux -rsync_host = mirror.math.princeton.edu -rsync_dir = pub/mxlinux/ - -[mxlinux-iso] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = mxlinux-iso -rsync_host = mirror.math.princeton.edu -rsync_dir = pub/mxlinux-iso/ - - -[parabola] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = parabola -rsync_host = repo.parabola.nu:875 -rsync_dir = repos/ - -; [hyperbola-sources] -; csc-sync-chmod hyperbola/sources repo.hyperbola.info:52000 repo/ -; frequency = twice-daily - -; [hyperbola-stable] -; csc-sync-chmod hyperbola/gnu-plus-linux-libre/stable repo.hyperbola.info:52012 repo/ -; frequency = twice-daily - -; [hyperbola-testing] -; csc-sync-chmod hyperbola/gnu-plus-linux-libre/testing repo.hyperbola.info:52011 repo/ -; frequency = twice-daily - -[trisquel-packages] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = trisquel/packages -rsync_host = rsync.trisquel.info -rsync_dir = trisquel.packages/ - -[trisquel-iso] -sync_type = csc-sync-standard -frequency = twice-daily -local_dir = trisquel/iso -rsync_host = rsync.trisquel.info -rsync_dir = trisquel.iso/ - -[almalinux] -sync_type = csc-sync-standard -frequency = bi-hourly -local_dir = almalinux -rsync_host = rsync.repo.almalinux.org -rsync_dir = almalinux/ - -[ceph] -sync_type = csc-sync-ceph -frequency = tri-hourly -local_dir = ceph -rsync_host = download.ceph.com diff --git a/merlin/test/debianBased b/merlin/test/debianBased deleted file mode 100644 index 116a682..0000000 --- a/merlin/test/debianBased +++ /dev/null @@ -1 +0,0 @@ -("debian", "debian-backports", "debian-cd", "debian-multimedia", "debian-ports", "debian-security", "debian-unofficial", "debian-volatile", "ubuntu", "ubuntu-ports", "ubuntu-ports-releases", "ubuntu-releases", "xubuntu-releases") diff --git a/merlin/test/debian_update b/merlin/test/debian_update deleted file mode 100755 index 391d33a..0000000 --- a/merlin/test/debian_update +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -#Dummy debian update script for testing -echo "Updating debian-type mirror: $1" -sleep 5 diff --git a/merlin/test/mirror/debian/trace/mirror.csclub.uwaterloo.ca b/merlin/test/mirror/debian/trace/mirror.csclub.uwaterloo.ca deleted file mode 100755 index 364218f..0000000 --- a/merlin/test/mirror/debian/trace/mirror.csclub.uwaterloo.ca +++ /dev/null @@ -1 +0,0 @@ -Wed Dec 30 03:17:50 UTC 2009 diff --git a/merlin/test/mirror/hobo-linux/mirror.csclub.uwaterloo.ca b/merlin/test/mirror/hobo-linux/mirror.csclub.uwaterloo.ca deleted file mode 100755 index 135bef0..0000000 --- a/merlin/test/mirror/hobo-linux/mirror.csclub.uwaterloo.ca +++ /dev/null @@ -1 +0,0 @@ -Sun Dec 27 03:17:50 UTC 2009 diff --git a/merlin/test/mirror/ubuntu/trace/mirror.csclub.uwaterloo.ca b/merlin/test/mirror/ubuntu/trace/mirror.csclub.uwaterloo.ca deleted file mode 100755 index 135bef0..0000000 --- a/merlin/test/mirror/ubuntu/trace/mirror.csclub.uwaterloo.ca +++ /dev/null @@ -1 +0,0 @@ -Sun Dec 27 03:17:50 UTC 2009 diff --git a/merlin/test/mirrors b/merlin/test/mirrors deleted file mode 100644 index 91470f7..0000000 --- a/merlin/test/mirrors +++ /dev/null @@ -1 +0,0 @@ -{'debian': 'foo'} diff --git a/merlin/test/sync b/merlin/test/sync deleted file mode 100755 index 94019ff..0000000 --- a/merlin/test/sync +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -sleep 2 -echo "done syncing $1" - diff --git a/merlin/test/test_repo_dict b/merlin/test/test_repo_dict deleted file mode 100644 index f02f44a..0000000 --- a/merlin/test/test_repo_dict +++ /dev/null @@ -1,30 +0,0 @@ -repos = { - 'gnu': { - 'command': 'sleep 10', - 'interval': daily, - }, - 'nongnu': { - 'command': 'sleep 10', - 'interval': daily, - }, - 'mysql': { - 'command': 'sleep 10', - 'interval': daily, - }, - 'mozdev': { - 'command': 'sleep 10', - 'interval': daily, - }, - 'gnome': { - 'command': 'sleep 10', - 'interval': daily, - }, - 'damnsmalllinux': { - 'command': 'sleep 10', - 'interval': daily, - }, - 'linuxmint': { - 'command': 'sleep 10', - 'interval': daily, - }, -} diff --git a/merlin/test/trace/leningradskaya.canonical.com b/merlin/test/trace/leningradskaya.canonical.com deleted file mode 100755 index 7fad5ca..0000000 --- a/merlin/test/trace/leningradskaya.canonical.com +++ /dev/null @@ -1 +0,0 @@ -Tue Dec 29 02:47:07 UTC 2009 diff --git a/merlin/merlin-config-test.ini b/merlin/test_utils/merlin-config-test.ini similarity index 61% rename from merlin/merlin-config-test.ini rename to merlin/test_utils/merlin-config-test.ini index 8811079..55789c8 100644 --- a/merlin/merlin-config-test.ini +++ b/merlin/test_utils/merlin-config-test.ini @@ -3,15 +3,15 @@ ipv6_address = 2620:101:f000:4901:c5c::f:1055 ; max_jobs = 6 -download_dir = /mirror/root -trace_dir = /home/mirror-go/merlin/trace -state_dir = /home/mirror-go/merlin/state +download_dir = ./test_tmp/download +trace_dir = ./test_tmp/trace +state_dir = ./test_tmp/state -repo_log_dir = /home/mirror-go/merlin/log -rsync_log_dir = /home/mirror-go/merlin/log-rsync -zfssync_log_dir = /home/mirror-go/merlin/log-zfssync +repo_log_dir = ./test_tmp/log +rsync_log_dir = ./test_tmp/log-rsync +zfssync_log_dir = ./test_tmp/log-zfssync -sock_path = /mirror/merlin/run/merlin-go.sock +sock_path = ./test_tmp/merlin-go.sock [ubuntu] dry_run = true diff --git a/merlin/test_utils/test_utils.go b/merlin/test_utils/test_utils.go new file mode 100644 index 0000000..4e57d6e --- /dev/null +++ b/merlin/test_utils/test_utils.go @@ -0,0 +1,50 @@ +package test_utils + +import ( + "os" + "path" + + "git.csclub.uwaterloo.ca/public/merlin/config" +) + +const TmpDir = "./test_tmp" + +func removeTmpDir() { + _, err := os.Stat(TmpDir) + if err != nil { + if os.IsNotExist(err) { + return + } + panic(err) + } + err = os.RemoveAll(TmpDir) + if err != nil { + panic(err) + } +} + +func createTmpDir() { + for _, subdir := range []string{"download/ubuntu"} { + err := os.MkdirAll(path.Join(TmpDir, subdir), 0755) + if err != nil { + panic(err) + } + } +} + +func SetupTestWithConfig(configPath string) (doneChan chan config.SyncResult, stopChan chan struct{}) { + removeTmpDir() + createTmpDir() + doneChan = make(chan config.SyncResult) + stopChan = make(chan struct{}) + config.LoadConfig(configPath, doneChan, stopChan) + return +} + +func SetupTest() (chan config.SyncResult, chan struct{}) { + return SetupTestWithConfig("test_utils/merlin-config-test.ini") +} + +func TeardownTest() { + removeTmpDir() +}