File: test_diff.py

package info (click to toggle)
python-openshift 0.13.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 332 kB
  • sloc: python: 1,824; makefile: 20; sh: 14
file content (114 lines) | stat: -rw-r--r-- 3,926 bytes parent folder | download | duplicates (2)
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
from openshift.dynamic.apply import recursive_diff

tests = [
    dict(
        before = dict(
            kind="Service",
            metadata=dict(name="foo"),
            spec=dict(ports=[dict(port=8080, name="http")])
        ),
        after = dict(
            kind="Service",
            metadata=dict(name="foo"),
            spec=dict(ports=[dict(port=8080, name="http")])
        ),
        expected = None
    ),
    dict(
        before = dict(
            kind="Service",
            metadata=dict(name="foo"),
            spec=dict(ports=[dict(port=8080, name="http")])
        ),
        after = dict(
            kind="Service",
            metadata=dict(name="foo"),
            spec=dict(ports=[dict(port=8081, name="http")])
        ),
        expected = (
            dict(spec=dict(ports=[dict(port=8080, name="http")])),
            dict(spec=dict(ports=[dict(port=8081, name="http")]))
        )
    ),
    dict(
        before = dict(
            kind="Service",
            metadata=dict(name="foo"),
            spec=dict(ports=[dict(port=8080, name="http"), dict(port=8081, name="https")])
        ),
        after = dict(
            kind="Service",
            metadata=dict(name="foo"),
            spec=dict(ports=[dict(port=8081, name="https"), dict(port=8080, name="http")])
        ),
        expected = None
    ),

    dict(
        before = dict(
            kind="Pod",
            metadata=dict(name="foo"),
            spec=dict(containers=[dict(name="busybox", image="busybox",
                                       env=[dict(name="hello", value="world"),
                                            dict(name="another", value="next")])])
        ),
        after = dict(
            kind="Pod",
            metadata=dict(name="foo"),
            spec=dict(containers=[dict(name="busybox", image="busybox",
                                       env=[dict(name="hello", value="everyone")])])
        ),
        expected=(dict(spec=dict(containers=[dict(name="busybox", env=[dict(name="another", value="next"), dict(name="hello", value="world")])])),
                  dict(spec=dict(containers=[dict(name="busybox", env=[dict(name="hello", value="everyone")])])))
    ),

    dict(
        before = dict(
            kind="Pod",
            metadata=dict(name="foo"),
            spec=dict(containers=[dict(name="busybox", image="busybox")])
        ),
        after = dict(
            kind="Service",
            metadata=dict(name="foo"),
            spec=dict(ports=[dict(port=8081, name="http")])
        ),
        expected=(dict(kind='Pod', spec=dict(containers=[dict(image='busybox', name='busybox')])),
                  dict(kind='Service', spec=dict(ports=[dict(name='http', port=8081)])))
    ),

    dict(
        before = dict(
            kind="Pod",
            metadata=dict(name="foo"),
            spec=dict(containers=[dict(name="busybox", image="busybox")])
        ),
        after = dict(
            # kind="...",
            metadata=dict(name="foo"),
            spec=dict(ports=[dict(port=8081, name="http")])
        ),
        expected=(dict(kind='Pod', spec=dict(containers=[dict(image='busybox', name='busybox')])),
                  dict(spec=dict(ports=[dict(name='http', port=8081)])))
    ),

    dict(
        before = dict(
            # kind="...",
            metadata=dict(name="foo"),
            spec=dict(containers=[dict(name="busybox", image="busybox")])
        ),
        after = dict(
            kind="Service",
            metadata=dict(name="foo"),
            spec=dict(ports=[dict(port=8081, name="http")])
        ),
        expected=(dict(spec=dict(containers=[dict(image='busybox', name='busybox')])),
                  dict(kind='Service', spec=dict(ports=[dict(name='http', port=8081)])))
    ),
    ]


def test_diff():
    for test in tests:
        assert(recursive_diff(test['before'], test['after']) == test['expected'])