'``DockerClient.add`` accepts an environment object whose ID and
variables are used when starting a docker image.'

def test_add_with_environment(self):

    docker_dir = FilePath(self.mktemp())
    docker_dir.makedirs()
    docker_dir.child('Dockerfile').setContent('FROM    busybox\nCMD    ["/bin/sh",        "-c",    "while    true;    do    env    &&    echo    WOOT    &&    sleep    1;    done"]')
    expected_variables = frozenset({'key1': 'value1', 'key2': 'value2'}.items())
    unit_name = random_name(self)
    image = DockerImageBuilder(test=self, source_dir=docker_dir)
    d = image.build()
    def image_built(image_name):
        return self.start_container(unit_name=unit_name, image_name=image_name, environment=Environment(variables=expected_variables))
    d.addCallback(image_built)
    def started(_):
        output = ''
        client = dockerpy_client()
        while True:
            output += client.logs((self.namespacing_prefix + unit_name))
            if ('WOOT' in output):
                break
        assertContainsAll(output, test_case=self, needles=['{}={}\n'.format(k, v) for (k, v) in expected_variables])
    d.addCallback(started)
    return d
