From 4197af902e049d2b802d543082907608861f4e36 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Tue, 21 Jan 2014 15:33:22 +0400 Subject: [PATCH] Tests for mirror list/show. --- system/lib.py | 31 ++++++++++++------- system/t04_mirror/CreateMirror7Test_gold | 4 +++ .../t04_mirror/CreateMirror7Test_mirror_show | 18 +++++++++++ system/t04_mirror/ListMirror1Test_gold | 6 ++++ system/t04_mirror/ListMirror2Test_gold | 1 + system/t04_mirror/ShowMirror1Test_gold | 18 +++++++++++ system/t04_mirror/ShowMirror2Test_gold | 1 + system/t04_mirror/__init__.py | 2 ++ system/t04_mirror/create.py | 14 +++++++++ system/t04_mirror/list.py | 20 ++++++++++++ system/t04_mirror/show.py | 17 ++++++++++ 11 files changed, 121 insertions(+), 11 deletions(-) create mode 100644 system/t04_mirror/CreateMirror7Test_gold create mode 100644 system/t04_mirror/CreateMirror7Test_mirror_show create mode 100644 system/t04_mirror/ListMirror1Test_gold create mode 100644 system/t04_mirror/ListMirror2Test_gold create mode 100644 system/t04_mirror/ShowMirror1Test_gold create mode 100644 system/t04_mirror/ShowMirror2Test_gold create mode 100644 system/t04_mirror/list.py create mode 100644 system/t04_mirror/show.py diff --git a/system/lib.py b/system/lib.py index 19753753..3301c21e 100644 --- a/system/lib.py +++ b/system/lib.py @@ -4,17 +4,28 @@ Test library. import difflib import inspect +import json import subprocess import os import shutil import string + class BaseTest(object): """ Base class for all tests. """ expectedCode = 0 + configFile = { + "rootDir": "%s/.aptly" % os.environ["HOME"], + "downloadConcurrency": 4, + "architectures": [], + "dependencyFollowSuggests": False, + "dependencyFollowRecommends": False, + "dependencyFollowAllVariants": False + } + configOverride = {} def test(self): self.prepare() @@ -28,10 +39,17 @@ class BaseTest(object): os.remove(os.path.join(os.environ["HOME"], ".aptly.conf")) def prepare_default_config(self): + cfg = self.configFile.copy() + cfg.update(**self.configOverride) f = open(os.path.join(os.environ["HOME"], ".aptly.conf"), "w") - f.write(config_file) + f.write(json.dumps(cfg)) f.close() + def prepare_fixture(self): + if hasattr(self, "fixtureCmds"): + for cmd in self.fixtureCmds: + self.run_cmd(cmd) + def run(self): self.output = self.run_cmd(self.runCmd, self.expectedCode) @@ -75,14 +93,5 @@ class BaseTest(object): def prepare(self): self.prepare_remove_all() self.prepare_default_config() + self.prepare_fixture() -config_file = """ -{ - "rootDir": "%s/.aptly", - "downloadConcurrency": 4, - "architectures": [], - "dependencyFollowSuggests": false, - "dependencyFollowRecommends": false, - "dependencyFollowAllVariants": false -} -""" % (os.environ["HOME"]) diff --git a/system/t04_mirror/CreateMirror7Test_gold b/system/t04_mirror/CreateMirror7Test_gold new file mode 100644 index 00000000..192d8274 --- /dev/null +++ b/system/t04_mirror/CreateMirror7Test_gold @@ -0,0 +1,4 @@ +Downloading http://mirror.yandex.ru/debian/dists/wheezy/Release... + +Mirror [mirror7]: http://mirror.yandex.ru/debian/ wheezy successfully added. +You can run 'aptly mirror update mirror7' to download repository contents. diff --git a/system/t04_mirror/CreateMirror7Test_mirror_show b/system/t04_mirror/CreateMirror7Test_mirror_show new file mode 100644 index 00000000..c224e805 --- /dev/null +++ b/system/t04_mirror/CreateMirror7Test_mirror_show @@ -0,0 +1,18 @@ +Name: mirror7 +Archive Root URL: http://mirror.yandex.ru/debian/ +Distribution: wheezy +Components: main, contrib +Architectures: i386, amd64 +Last update: never + +Information from release file: +Architectures: amd64 armel armhf i386 ia64 kfreebsd-amd64 kfreebsd-i386 mips mipsel powerpc s390 s390x sparc +Codename: wheezy +Components: main contrib non-free +Date: Sat, 14 Dec 2013 10:51:30 UTC +Description: Debian 7.3 Released 14 December 2013 + +Label: Debian +Origin: Debian +Suite: stable +Version: 7.3 diff --git a/system/t04_mirror/ListMirror1Test_gold b/system/t04_mirror/ListMirror1Test_gold new file mode 100644 index 00000000..4c982784 --- /dev/null +++ b/system/t04_mirror/ListMirror1Test_gold @@ -0,0 +1,6 @@ +List of mirrors: + * [mirror1]: http://mirror.yandex.ru/debian/ wheezy + * [mirror2]: http://mirror.yandex.ru/debian/ squeeze + * [mirror3]: http://mirror.yandex.ru/debian/ squeeze + +To get more information about mirror, run `aptly mirror show `. diff --git a/system/t04_mirror/ListMirror2Test_gold b/system/t04_mirror/ListMirror2Test_gold new file mode 100644 index 00000000..dcd0df02 --- /dev/null +++ b/system/t04_mirror/ListMirror2Test_gold @@ -0,0 +1 @@ +No mirrors found, create one with `aptly mirror create ...`. diff --git a/system/t04_mirror/ShowMirror1Test_gold b/system/t04_mirror/ShowMirror1Test_gold new file mode 100644 index 00000000..5dc67195 --- /dev/null +++ b/system/t04_mirror/ShowMirror1Test_gold @@ -0,0 +1,18 @@ +Name: mirror1 +Archive Root URL: http://mirror.yandex.ru/debian/ +Distribution: wheezy +Components: main, contrib, non-free +Architectures: amd64, armel, armhf, i386, ia64, kfreebsd-amd64, kfreebsd-i386, mips, mipsel, powerpc, s390, s390x, sparc +Last update: never + +Information from release file: +Architectures: amd64 armel armhf i386 ia64 kfreebsd-amd64 kfreebsd-i386 mips mipsel powerpc s390 s390x sparc +Codename: wheezy +Components: main contrib non-free +Date: Sat, 14 Dec 2013 10:51:30 UTC +Description: Debian 7.3 Released 14 December 2013 + +Label: Debian +Origin: Debian +Suite: stable +Version: 7.3 diff --git a/system/t04_mirror/ShowMirror2Test_gold b/system/t04_mirror/ShowMirror2Test_gold new file mode 100644 index 00000000..5b1f2811 --- /dev/null +++ b/system/t04_mirror/ShowMirror2Test_gold @@ -0,0 +1 @@ +ERROR: unable to show: mirror with name mirror-xx not found diff --git a/system/t04_mirror/__init__.py b/system/t04_mirror/__init__.py index 4d21298e..e82ee172 100644 --- a/system/t04_mirror/__init__.py +++ b/system/t04_mirror/__init__.py @@ -3,3 +3,5 @@ Testing mirror management """ from .create import * +from .show import * +from .list import * diff --git a/system/t04_mirror/create.py b/system/t04_mirror/create.py index 64ed947d..41c44977 100644 --- a/system/t04_mirror/create.py +++ b/system/t04_mirror/create.py @@ -59,3 +59,17 @@ class CreateMirror6Test(BaseTest): expectedCode = 1 runCmd = "aptly mirror create mirror6 http://mirror.yandex.ru/debian/ suslik" + + +class CreateMirror7Test(BaseTest): + """ + create mirror: architectures fixed via config file + """ + runCmd = "aptly mirror create mirror7 http://mirror.yandex.ru/debian/ wheezy main contrib" + configOverride = {"architectures": ["i386", "amd64"]} + + def check(self): + self.check_output() + self.check_cmd_output("aptly mirror show mirror7", "mirror_show") + + diff --git a/system/t04_mirror/list.py b/system/t04_mirror/list.py new file mode 100644 index 00000000..784ea354 --- /dev/null +++ b/system/t04_mirror/list.py @@ -0,0 +1,20 @@ +from lib import BaseTest + + +class ListMirror1Test(BaseTest): + """ + list mirrors: regular list + """ + fixtureCmds = [ + "aptly mirror create mirror1 http://mirror.yandex.ru/debian/ wheezy", + "aptly mirror create mirror2 http://mirror.yandex.ru/debian/ squeeze contrib", + "aptly -architectures=i386 mirror create mirror3 http://mirror.yandex.ru/debian/ squeeze non-free", + ] + runCmd = "aptly mirror list" + + +class ListMirror2Test(BaseTest): + """ + list mirrors: empty list + """ + runCmd = "aptly mirror list" diff --git a/system/t04_mirror/show.py b/system/t04_mirror/show.py new file mode 100644 index 00000000..1075e28d --- /dev/null +++ b/system/t04_mirror/show.py @@ -0,0 +1,17 @@ +from lib import BaseTest + + +class ShowMirror1Test(BaseTest): + """ + show mirror: regular mirror + """ + fixtureCmds = ["aptly mirror create mirror1 http://mirror.yandex.ru/debian/ wheezy"] + runCmd = "aptly mirror show mirror1" + + +class ShowMirror2Test(BaseTest): + """ + show mirror: missing mirror + """ + runCmd = "aptly mirror show mirror-xx" + expectedCode = 1