blob: e5ccafe5c9c16d2adf702c79fac25343cb0e6917 [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001# Copyright (C) 2017-2018 Wind River Systems, Inc.
2#
Brad Bishopc342db32019-05-15 21:57:59 -04003# SPDX-License-Identifier: GPL-2.0-only
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08004#
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08005
6import unittest
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08007import os
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08008
9import layerindexlib
10from layerindexlib.tests.common import LayersTest
11
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080012
13def skipIfNoNetwork():
14 if os.environ.get("BB_SKIP_NETTESTS") == "yes":
15 return unittest.skip("Network tests being skipped")
16 return lambda f: f
17
18class LayerIndexWebRestApiTest(LayersTest):
19
20 @skipIfNoNetwork()
21 def setUp(self):
22 self.assertFalse(os.environ.get("BB_SKIP_NETTESTS") == "yes", msg="BB_SKIP_NETTESTS set, but we tried to test anyway")
23 LayersTest.setUp(self)
24 self.layerindex = layerindexlib.LayerIndex(self.d)
25 self.layerindex.load_layerindex('http://layers.openembedded.org/layerindex/api/;branch=sumo', load=['layerDependencies'])
26
27 @skipIfNoNetwork()
28 def test_layerindex_is_empty(self):
29 self.assertFalse(self.layerindex.is_empty(), msg="Layerindex is empty")
30
31 @skipIfNoNetwork()
32 def test_layerindex_store_file(self):
33 self.layerindex.store_layerindex('file://%s/file.json' % self.tempdir, self.layerindex.indexes[0])
34
35 self.assertTrue(os.path.isfile('%s/file.json' % self.tempdir), msg="Temporary file was not created by store_layerindex")
36
37 reload = layerindexlib.LayerIndex(self.d)
38 reload.load_layerindex('file://%s/file.json' % self.tempdir)
39
40 self.assertFalse(reload.is_empty(), msg="Layerindex is empty")
41
42 # Calculate layerItems in original index that should NOT be in reload
43 layerItemNames = []
44 for itemId in self.layerindex.indexes[0].layerItems:
45 layerItemNames.append(self.layerindex.indexes[0].layerItems[itemId].name)
46
47 for layerBranchId in self.layerindex.indexes[0].layerBranches:
48 layerItemNames.remove(self.layerindex.indexes[0].layerBranches[layerBranchId].layer.name)
49
50 for itemId in reload.indexes[0].layerItems:
51 self.assertFalse(reload.indexes[0].layerItems[itemId].name in layerItemNames, msg="Item reloaded when it shouldn't have been")
52
53 # Compare the original to what we wrote...
54 for type in self.layerindex.indexes[0]._index:
55 if type == 'apilinks' or \
56 type == 'layerItems' or \
57 type in self.layerindex.indexes[0].config['local']:
58 continue
59 for id in getattr(self.layerindex.indexes[0], type):
60 self.logger.debug(1, "type %s" % (type))
61
62 self.assertTrue(id in getattr(reload.indexes[0], type), msg="Id number not in reloaded index")
63
64 self.logger.debug(1, "%s ? %s" % (getattr(self.layerindex.indexes[0], type)[id], getattr(reload.indexes[0], type)[id]))
65
66 self.assertEqual(getattr(self.layerindex.indexes[0], type)[id], getattr(reload.indexes[0], type)[id], msg="Reloaded contents different")
67
68 @skipIfNoNetwork()
69 def test_layerindex_store_split(self):
70 self.layerindex.store_layerindex('file://%s' % self.tempdir, self.layerindex.indexes[0])
71
72 reload = layerindexlib.LayerIndex(self.d)
73 reload.load_layerindex('file://%s' % self.tempdir)
74
75 self.assertFalse(reload.is_empty(), msg="Layer index is empty")
76
77 for type in self.layerindex.indexes[0]._index:
78 if type == 'apilinks' or \
79 type == 'layerItems' or \
80 type in self.layerindex.indexes[0].config['local']:
81 continue
82 for id in getattr(self.layerindex.indexes[0] ,type):
83 self.logger.debug(1, "type %s" % (type))
84
85 self.assertTrue(id in getattr(reload.indexes[0], type), msg="Id number missing from reloaded data")
86
87 self.logger.debug(1, "%s ? %s" % (getattr(self.layerindex.indexes[0] ,type)[id], getattr(reload.indexes[0], type)[id]))
88
89 self.assertEqual(getattr(self.layerindex.indexes[0] ,type)[id], getattr(reload.indexes[0], type)[id], msg="reloaded data does not match original")
90
91 @skipIfNoNetwork()
92 def test_dependency_resolution(self):
93 # Verify depth first searching...
94 (dependencies, invalidnames) = self.layerindex.find_dependencies(names=['meta-python'])
95
96 first = True
97 for deplayerbranch in dependencies:
98 layerBranch = dependencies[deplayerbranch][0]
99 layerDeps = dependencies[deplayerbranch][1:]
100
101 if not first:
102 continue
103
104 first = False
105
106 # Top of the deps should be openembedded-core, since everything depends on it.
107 self.assertEqual(layerBranch.layer.name, "openembedded-core", msg='OpenEmbedded-Core is no the first dependency')
108
109 # meta-python should cause an openembedded-core dependency, if not assert!
110 for dep in layerDeps:
111 if dep.layer.name == 'meta-python':
112 break
113 else:
114 self.logger.debug(1, "meta-python was not found")
115 self.assetTrue(False)
116
117 # Only check the first element...
118 break
119 else:
120 # Empty list, this is bad.
121 self.logger.debug(1, "Empty list of dependencies")
122 self.assertIsNotNone(first, msg="Empty list of dependencies")
123
124 # Last dep should be the requested item
125 layerBranch = dependencies[deplayerbranch][0]
126 self.assertEqual(layerBranch.layer.name, "meta-python", msg="Last dependency not meta-python")
127
128 @skipIfNoNetwork()
129 def test_find_collection(self):
130 def _check(collection, expected):
131 self.logger.debug(1, "Looking for collection %s..." % collection)
132 result = self.layerindex.find_collection(collection)
133 if expected:
134 self.assertIsNotNone(result, msg="Did not find %s when it should be there" % collection)
135 else:
136 self.assertIsNone(result, msg="Found %s when it shouldn't be there" % collection)
137
138 tests = [ ('core', True),
139 ('openembedded-core', False),
140 ('networking-layer', True),
141 ('meta-python', True),
142 ('openembedded-layer', True),
143 ('notpresent', False) ]
144
145 for collection,result in tests:
146 _check(collection, result)
147
148 @skipIfNoNetwork()
149 def test_find_layerbranch(self):
150 def _check(name, expected):
151 self.logger.debug(1, "Looking for layerbranch %s..." % name)
152
153 for index in self.layerindex.indexes:
154 for layerbranchid in index.layerBranches:
155 self.logger.debug(1, "Present: %s" % index.layerBranches[layerbranchid].layer.name)
156 result = self.layerindex.find_layerbranch(name)
157 if expected:
158 self.assertIsNotNone(result, msg="Did not find %s when it should be there" % collection)
159 else:
160 self.assertIsNone(result, msg="Found %s when it shouldn't be there" % collection)
161
162 tests = [ ('openembedded-core', True),
163 ('core', False),
164 ('meta-networking', True),
165 ('meta-python', True),
166 ('meta-oe', True),
167 ('notpresent', False) ]
168
169 for collection,result in tests:
170 _check(collection, result)
171