-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_unroll.py
More file actions
114 lines (90 loc) · 3.58 KB
/
Copy pathtest_unroll.py
File metadata and controls
114 lines (90 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
"""
Copyright 2026 Guillaume Everarts de Velp
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Contact: edvgui@gmail.com
"""
import pytest
from inmanta_plugins.example.slices import fs, recursive, simple
from inmanta_plugins.git_ops import const
from pytest_inmanta_git_ops.project import GitOpsProject
def test_fs(git_ops_project: GitOpsProject) -> None:
git_ops_project.load_stores("import example::slices::fs::unroll")
assert git_ops_project.stores is not None
assert fs.STORE in git_ops_project.stores.values()
# Create a first slice
slice1 = git_ops_project.test_slice(
fs.RootFolder(
root="/tmp/",
name="test",
),
store_name=fs.STORE.name,
)
assert git_ops_project.write_slice(slice1).version == 1
assert len(slice1.get_versions()) == 1
assert len(git_ops_project.get_instance(slice1).content) == 0
# Empty update on the slice, we should get the same version
assert git_ops_project.write_slice(slice1).version == 1
assert len(slice1.get_versions()) == 1
# Add some folder
slice1.slice.content = [
fs.Folder(name="a"),
fs.Folder(name="b"),
fs.Folder(name="c"),
fs.File(name="d"),
]
assert git_ops_project.write_slice(slice1).version == 2
assert len(slice1.get_versions()) == 2
assert len(git_ops_project.get_instance(slice1).content) == 4
assert (
git_ops_project.get_instance(slice1).content[0].path
== "content[type=folder][name=a]"
)
# Prune version after update
git_ops_project.prune()
assert len(slice1.get_versions()) == 1
# Remove a folder
slice1.slice.content = [
fs.Folder(name="a"),
fs.Folder(name="b"),
]
assert git_ops_project.write_slice(slice1).version == 3
assert len(slice1.get_versions()) == 2
assert len(git_ops_project.get_instance(slice1).content) == 4
assert (
next(
dir
for dir in git_ops_project.get_instance(slice1).content
if dir.operation == const.SLICE_DELETE
).name
== "c"
)
# Prune version after update
git_ops_project.prune()
assert len(slice1.get_versions()) == 1
git_ops_project.export()
assert len(git_ops_project.get_instance(slice1).content) == 2
# Delete slice
assert git_ops_project.remove_slice(slice1).version == 4
assert git_ops_project.remove_slice(slice1).emit_slice(fs.STORE.name).deleted
assert len(git_ops_project.get_instance(slice1).content) == 2
# Prune after delete
git_ops_project.prune()
assert len(slice1.get_versions()) == 0
with pytest.raises(LookupError):
git_ops_project.get_instance(slice1)
def test_recursive(git_ops_project: GitOpsProject) -> None:
git_ops_project.load_stores("import example::slices::recursive")
assert git_ops_project.stores is not None
assert recursive.STORE in git_ops_project.stores.values()
def test_simple(git_ops_project: GitOpsProject) -> None:
git_ops_project.load_stores("import example::slices::simple")
assert git_ops_project.stores is not None
assert simple.STORE in git_ops_project.stores.values()