1
# Copyright 2014 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Tests for Curtin-related utilities."""
6
from __future__ import (
17
from maastesting.factory import factory
18
from maastesting.testcase import MAASTestCase
19
from provisioningserver.utils.curtin import (
21
compose_write_text_file,
23
from testtools.matchers import (
30
class TestComposeMvCommand(MAASTestCase):
32
def test__returns_command_list(self):
33
command = compose_mv_command(
34
factory.make_name('source'), factory.make_name('dest'))
35
self.expectThat(command, IsInstance(list))
36
self.expectThat(command, AllMatch(IsInstance(unicode)))
38
def test__runs_command_in_target(self):
39
command = compose_mv_command(
40
factory.make_name('source'), factory.make_name('dest'))
41
self.assertEqual(['curtin', 'in-target', '--'], command[:3])
43
def test__moves_file(self):
44
source = factory.make_name('source')
45
dest = factory.make_name('dest')
47
['mv', '--', source, dest],
48
compose_mv_command(source, dest)[-4:])
51
class TestComposeWriteTextFile(MAASTestCase):
53
def test__returns_complete_write_file_dict(self):
54
preseed = compose_write_text_file(
55
factory.make_name('file'), factory.make_name('content'))
56
self.expectThat(preseed, IsInstance(dict))
59
ContainsAll(['path', 'content', 'owner', 'permissions']))
61
def test__obeys_path_param(self):
62
path = factory.make_name('path')
63
preseed = compose_write_text_file(path, factory.make_name('content'))
64
self.assertEqual(path, preseed['path'])
66
def test__obeys_content_param(self):
67
content = factory.make_name('content')
68
preseed = compose_write_text_file(factory.make_name('path'), content)
69
self.assertEqual(content, preseed['content'])
71
def test__defaults_owner_to_root(self):
72
preseed = compose_write_text_file(
73
factory.make_name('file'), factory.make_name('content'))
74
self.assertEqual('root:root', preseed['owner'])
76
def test__obeys_owner_param(self):
78
factory.make_name('user'),
79
factory.make_name('group'),
81
preseed = compose_write_text_file(
82
factory.make_name('file'), factory.make_name('content'),
84
self.assertEqual(owner, preseed['owner'])
86
def test__defaults_permissions_to_0600(self):
87
preseed = compose_write_text_file(
88
factory.make_name('file'), factory.make_name('content'))
89
self.assertEqual('0600', preseed['permissions'])
91
def test__obeys_permissions_param(self):
93
preseed = compose_write_text_file(
94
factory.make_name('file'), factory.make_name('content'),
95
permissions=permissions)
96
self.assertEqual('0123', preseed['permissions'])