Пример #1
0
        obj = cs.CommandContentAddDict(image=self.image, conf=self.conf, path=self.path, images=self.images, docker_context=self.docker_context)
        image_name = self.unique_val()
        self.conf.image_name = image_name
        self.assertEqual(obj.for_json(), {"image": image_name, "path": self.path})

describe CommandCase, "CommandAddExtra":
    it "yields commands for each value in get":
        meta = mock.Mock(name="meta")
        v1, r1 = mock.Mock(name='v1'), mock.Mock(name='r1')
        v2, r2 = mock.Mock(name='v2'), mock.Mock(name='r2')
        v3, r3 = mock.Mock(name='v3'), mock.Mock(name='r3')
        transform = {v1: r1, v2: r2, v3: r3}

        command_for = mock.Mock(name="command_for")
        command_for.side_effect = lambda v: transform[v]

        obj = cs.CommandAddExtra(get=[v1, v2, v3], prefix=NotSpecified)
        c = lambda r: co.Command(("ADD", r))

        with mock.patch.object(obj, "command_for", command_for):
            self.assertEqual(list(obj.commands(meta)), [c(r1), c(r2), c(r3)])

    it "yields command without prefix if no prefix is specified":
        obj = cs.CommandAddExtra(get=[], prefix=NotSpecified)
        self.assertEqual(obj.command_for("blah"), "blah blah")

    it "yields command with prefix if prefix is specified":
        obj = cs.CommandAddExtra(get=[], prefix="/stuff")
        self.assertEqual(obj.command_for("blah"), "blah /stuff/blah")

Пример #2
0
# coding: spec

from harpoon.option_spec import command_objs as co
from harpoon.errors import HarpoonError

from tests.helpers import HarpoonCase

from noseOfYeti.tokeniser.support import noy_sup_setUp
import mock
import os

describe HarpoonCase, "Context object":
    it "sets action and command from a space separated string":
        action = self.unique_val()
        cmd = self.unique_val()
        command = co.Command("{0} {1}".format(action, cmd))
        self.assertEqual(command.action, action)
        self.assertEqual(command.command, cmd)

    it "sets action and command from a two item tuple":
        action = self.unique_val()
        cmd = self.unique_val()
        command = co.Command((action, cmd))
        self.assertEqual(command.action, action)
        self.assertEqual(command.command, cmd)

    describe "as_string":
        it "concatenates action and command":
            self.assertEqual(co.Command(("blah", "meh")).as_string, "blah meh")
            self.assertEqual(co.Command("blah meh").as_string, "blah meh")
Пример #3
0
                harpoon_spec.tasks_spec = mock.Mock(name="tasks_spec")
                harpoon_spec.tasks_spec.return_value.normalise.return_value = normalised_tasks

                collector = Collector()
                configuration = collector.start_configuration()
                configuration["harpoon"] = {}
                configuration["images"] = {"blah": {"commands": "FROM ubuntu:14.04", "tasks": {"one": {}}}}
                configuration.converters.activate()

                collector.make_image_converters("blah", configuration, harpoon_spec)
                self.assertIs(configuration["images"]["blah"], normalised_image)
                self.assertIs(configuration[["images", "blah", "tasks"]], normalised_tasks)
                self.assertEqual(t1.image, "blah")
                self.assertEqual(t2.image, "blah")

            it "uses root of configuration with image as an override for the image converter":
                collector = Collector()
                configuration = collector.start_configuration()
                configuration["harpoon"] = {}
                configuration["context"] = False
                configuration["config_root"] = "."
                configuration["images"] = {"blah": {"commands": [["FROM", "{__image__.vars.blah}-{__image__.vars.stuff}"]], "vars": { "stuff": 2 }}}
                configuration["vars"] = {"blah": 30, "stuff": 40}
                configuration.converters.activate()
                collector.make_image_converters("blah", configuration, HarpoonSpec())

                self.assertEqual(configuration["images"]["blah"].commands.orig_commands, [[command_objs.Command(("FROM", "30-2"))]])
                self.assertEqual(configuration["images"]["blah"].context.enabled, False)