From da371530b267e1e5822ccbd21d162942e5ffb5ab Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Tue, 19 Jan 2021 14:03:21 +0000 Subject: [PATCH] test/fmt_v1: add new loader check Add a new test that loads a manifest description and checks that the loaded `Manifest` corresponds to what we expected. --- test/mod/test_fmt_v1.py | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/mod/test_fmt_v1.py b/test/mod/test_fmt_v1.py index 50b4b93a..f0a54850 100644 --- a/test/mod/test_fmt_v1.py +++ b/test/mod/test_fmt_v1.py @@ -4,6 +4,7 @@ import os import unittest +from typing import Dict import osbuild import osbuild.meta @@ -12,6 +13,7 @@ from osbuild.formats import v1 as fmt class TestFormatV1(unittest.TestCase): + def test_canonical(self): """Degenerate case. Make sure we always return the same canonical description when passing empty or null values.""" @@ -32,6 +34,47 @@ class TestFormatV1(unittest.TestCase): desc = fmt.describe(fmt.load(manifest, index)) self.assertEqual(desc["pipeline"], {}) + def test_load(self): + # Load a pipeline and check the resulting manifest + def check_stage(have: osbuild.Stage, want: Dict): + self.assertEqual(have.name, want["name"]) + self.assertEqual(have.options, want["options"]) + + index = osbuild.meta.Index(os.curdir) + + description = BASIC_PIPELINE + + # load the manifest description, that will check all + # the stages can be found in the index and have valid + # arguments, i.e. the schema is correct + + manifest = fmt.load(description, index) + self.assertIsNotNone(manifest) + + # We have to have a build pipeline and a main pipeline + self.assertTrue(manifest.pipelines) + self.assertTrue(len(manifest.pipelines) == 2) + + build = description["pipeline"]["build"] + pl = manifest.pipelines[0] + have = pl.stages[0] + want = build["pipeline"]["stages"][0] + check_stage(have, want) + + runner = build["runner"] + + # main pipeline is the next one + pl = manifest.pipelines[1] + have = pl.stages[0] + want = description["pipeline"]["stages"][0] + self.assertEqual(pl.runner, runner) + check_stage(have, want) + + # the assembler + have = pl.assembler + want = description["pipeline"]["assembler"] + self.assertEqual(have.name, want["name"]) + def test_pipeline(self): index = osbuild.meta.Index(os.curdir)