forked from devfile/integration-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_list_cmd.py
120 lines (81 loc) · 4.26 KB
/
test_list_cmd.py
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
115
116
117
118
119
120
import tempfile
import jmespath
from utils.config import *
from utils.util import *
@pytest.mark.usefixtures("use_test_registry")
class TestListCmd:
CONTEXT = "test-context"
tmp_project_name = None
@classmethod
def setup_class(cls):
# Runs once per class
cls.tmp_project_name = create_test_project()
@classmethod
def teardown_class(cls):
'''Runs at end of class'''
subprocess.run(["odo", "project", "delete", cls.tmp_project_name, "-f", "-w"])
def test_list_component_in_application(self):
print("Test case : should successfully list component when a component is created in 'app' application")
with tempfile.TemporaryDirectory() as tmp_workspace:
os.chdir(tmp_workspace)
# example devfile path
source_devfile_path = os.path.join(os.path.dirname(__file__),
'../examples/source/devfiles/nodejs/devfile.yaml')
copy_and_create(source_devfile_path, "nodejs/project", tmp_workspace, self.CONTEXT)
os.chdir(self.CONTEXT)
list_components = [
"app",
"nodejs",
"Not Pushed"
]
result = subprocess.run(["odo", "list"],
capture_output=True, text=True, check=True)
assert match_all(result.stdout, list_components)
result_json = subprocess.run(["odo", "list", "-o", "json"],
capture_output=True, text=True, check=True)
assert validate_json_format(result_json.stdout)
dict = json.loads(result_json.stdout)
path = jmespath.search('kind', dict)
assert contains(path, "List")
path = jmespath.search('devfileComponents[0].kind', dict)
assert contains(path, "Component")
path = jmespath.search('devfileComponents[0].metadata.name', dict)
assert contains(path, "nodejs")
path = jmespath.search('devfileComponents[0].status.state', dict)
assert contains(path, "Not Pushed")
def test_list_component_missing_metadata_projecttype(self):
print("Test case : should show the language for 'Type' in odo list")
with tempfile.TemporaryDirectory() as tmp_workspace:
os.chdir(tmp_workspace)
# example devfile path
source_devfile_path = os.path.join(os.path.dirname(__file__),
'../examples/source/devfiles/springboot/devfile-with-missing-projectType-metadata.yaml')
copy_and_create(source_devfile_path, "springboot/project", tmp_workspace, self.CONTEXT)
os.chdir(self.CONTEXT)
list_components = [
"app",
"java",
"myspringbootproject",
"Not Pushed"
]
result = subprocess.run(["odo", "list"],
capture_output=True, text=True, check=True)
assert match_all(result.stdout, list_components)
result_json = subprocess.run(["odo", "list", "-o", "json"],
capture_output=True, text=True, check=True)
assert validate_json_format(result_json.stdout)
dict = json.loads(result_json.stdout)
path = jmespath.search('devfileComponents[0].spec.type', dict)
assert contains(path, "java")
def test_list_component_missing_metadata_projecttype_language(self):
print("Test case : should show 'Not available' for 'Type' in odo list")
with tempfile.TemporaryDirectory() as tmp_workspace:
os.chdir(tmp_workspace)
# example devfile path
source_devfile_path = os.path.join(os.path.dirname(__file__),
'../examples/source/devfiles/springboot/devfile-with-missing-projectType-and-language-metadata.yaml')
copy_and_create(source_devfile_path, "springboot/project", tmp_workspace, self.CONTEXT)
os.chdir(self.CONTEXT)
result = subprocess.run(["odo", "list"],
capture_output=True, text=True, check=True)
assert contains(result.stdout, "Not available")