diff options
| author | Jean-Marie LEMETAYER <jean-marie.lemetayer@savoirfairelinux.com> | 2020-01-24 18:08:14 +0100 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2020-01-27 16:48:10 +0000 |
| commit | f6728edb7e022b27223d28bd80ce40c2f2374a13 (patch) | |
| tree | 166ad0220d4d10ee5fc041faac3ed6057861988f /bitbake | |
| parent | e0bd972ba7eaa5f3b0f5d93bf579cd79290d6601 (diff) | |
| download | poky-f6728edb7e022b27223d28bd80ce40c2f2374a13.tar.gz | |
bitbake: tests/fetch: add npmsw tests
This commit adds some tests to validate the npmsw fetcher:
- bb.tests.fetch.NPMTest.test_npmsw
- bb.tests.fetch.NPMTest.test_npmsw_bad_checksum
- bb.tests.fetch.NPMTest.test_npmsw_destsuffix
- bb.tests.fetch.NPMTest.test_npmsw_dev
- bb.tests.fetch.NPMTest.test_npmsw_mirrors
- bb.tests.fetch.NPMTest.test_npmsw_no_network_no_tarball
- bb.tests.fetch.NPMTest.test_npmsw_no_network_with_tarball
- bb.tests.fetch.NPMTest.test_npmsw_npm_reusability
- bb.tests.fetch.NPMTest.test_npmsw_premirrors
(Bitbake rev: ba205df20b6a07a4b1125332601c6c54c7b019b5)
Signed-off-by: Jean-Marie LEMETAYER <jean-marie.lemetayer@savoirfairelinux.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
| -rw-r--r-- | bitbake/lib/bb/tests/fetch.py | 251 |
1 files changed, 251 insertions, 0 deletions
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py index 5eeb64c512..45dc9e5d08 100644 --- a/bitbake/lib/bb/tests/fetch.py +++ b/bitbake/lib/bb/tests/fetch.py | |||
| @@ -2220,3 +2220,254 @@ class NPMTest(FetcherTest): | |||
| 2220 | url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example' | 2220 | url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example' |
| 2221 | with self.assertRaises(bb.fetch2.MissingParameterError): | 2221 | with self.assertRaises(bb.fetch2.MissingParameterError): |
| 2222 | fetcher = bb.fetch.Fetch([url], self.d) | 2222 | fetcher = bb.fetch.Fetch([url], self.d) |
| 2223 | |||
| 2224 | def create_shrinkwrap_file(self, data): | ||
| 2225 | import json | ||
| 2226 | datadir = os.path.join(self.tempdir, 'data') | ||
| 2227 | swfile = os.path.join(datadir, 'npm-shrinkwrap.json') | ||
| 2228 | bb.utils.mkdirhier(datadir) | ||
| 2229 | with open(swfile, 'w') as f: | ||
| 2230 | json.dump(data, f) | ||
| 2231 | # Also configure the S directory | ||
| 2232 | self.sdir = os.path.join(self.unpackdir, 'S') | ||
| 2233 | self.d.setVar('S', self.sdir) | ||
| 2234 | return swfile | ||
| 2235 | |||
| 2236 | @skipIfNoNpm() | ||
| 2237 | @skipIfNoNetwork() | ||
| 2238 | def test_npmsw(self): | ||
| 2239 | swfile = self.create_shrinkwrap_file({ | ||
| 2240 | 'dependencies': { | ||
| 2241 | 'array-flatten': { | ||
| 2242 | 'version': '1.1.1', | ||
| 2243 | 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', | ||
| 2244 | 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=', | ||
| 2245 | 'dependencies': { | ||
| 2246 | 'content-type': { | ||
| 2247 | 'version': 'https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz', | ||
| 2248 | 'integrity': 'sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==', | ||
| 2249 | 'dependencies': { | ||
| 2250 | 'cookie': { | ||
| 2251 | 'version': 'git+https://github.com/jshttp/cookie.git#aec1177c7da67e3b3273df96cf476824dbc9ae09', | ||
| 2252 | 'from': 'git+https://github.com/jshttp/cookie.git' | ||
| 2253 | } | ||
| 2254 | } | ||
| 2255 | } | ||
| 2256 | } | ||
| 2257 | } | ||
| 2258 | } | ||
| 2259 | }) | ||
| 2260 | fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d) | ||
| 2261 | fetcher.download() | ||
| 2262 | self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz'))) | ||
| 2263 | self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz'))) | ||
| 2264 | self.assertTrue(os.path.exists(os.path.join(self.dldir, 'git2', 'github.com.jshttp.cookie.git'))) | ||
| 2265 | fetcher.unpack(self.unpackdir) | ||
| 2266 | self.assertTrue(os.path.exists(os.path.join(self.sdir, 'npm-shrinkwrap.json'))) | ||
| 2267 | self.assertTrue(os.path.exists(os.path.join(self.sdir, 'node_modules', 'array-flatten', 'package.json'))) | ||
| 2268 | self.assertTrue(os.path.exists(os.path.join(self.sdir, 'node_modules', 'array-flatten', 'node_modules', 'content-type', 'package.json'))) | ||
| 2269 | self.assertTrue(os.path.exists(os.path.join(self.sdir, 'node_modules', 'array-flatten', 'node_modules', 'content-type', 'node_modules', 'cookie', 'package.json'))) | ||
| 2270 | |||
| 2271 | @skipIfNoNpm() | ||
| 2272 | @skipIfNoNetwork() | ||
| 2273 | def test_npmsw_dev(self): | ||
| 2274 | swfile = self.create_shrinkwrap_file({ | ||
| 2275 | 'dependencies': { | ||
| 2276 | 'array-flatten': { | ||
| 2277 | 'version': '1.1.1', | ||
| 2278 | 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', | ||
| 2279 | 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' | ||
| 2280 | }, | ||
| 2281 | 'content-type': { | ||
| 2282 | 'version': '1.0.4', | ||
| 2283 | 'resolved': 'https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz', | ||
| 2284 | 'integrity': 'sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==', | ||
| 2285 | 'dev': True | ||
| 2286 | } | ||
| 2287 | } | ||
| 2288 | }) | ||
| 2289 | # Fetch with dev disabled | ||
| 2290 | fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d) | ||
| 2291 | fetcher.download() | ||
| 2292 | self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz'))) | ||
| 2293 | self.assertFalse(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz'))) | ||
| 2294 | # Fetch with dev enabled | ||
| 2295 | fetcher = bb.fetch.Fetch(['npmsw://' + swfile + ';dev=1'], self.d) | ||
| 2296 | fetcher.download() | ||
| 2297 | self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz'))) | ||
| 2298 | self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz'))) | ||
| 2299 | |||
| 2300 | @skipIfNoNpm() | ||
| 2301 | @skipIfNoNetwork() | ||
| 2302 | def test_npmsw_destsuffix(self): | ||
| 2303 | swfile = self.create_shrinkwrap_file({ | ||
| 2304 | 'dependencies': { | ||
| 2305 | 'array-flatten': { | ||
| 2306 | 'version': '1.1.1', | ||
| 2307 | 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', | ||
| 2308 | 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' | ||
| 2309 | } | ||
| 2310 | } | ||
| 2311 | }) | ||
| 2312 | fetcher = bb.fetch.Fetch(['npmsw://' + swfile + ';destsuffix=foo/bar'], self.d) | ||
| 2313 | fetcher.download() | ||
| 2314 | fetcher.unpack(self.unpackdir) | ||
| 2315 | self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'foo', 'bar', 'node_modules', 'array-flatten', 'package.json'))) | ||
| 2316 | |||
| 2317 | def test_npmsw_no_network_no_tarball(self): | ||
| 2318 | swfile = self.create_shrinkwrap_file({ | ||
| 2319 | 'dependencies': { | ||
| 2320 | 'array-flatten': { | ||
| 2321 | 'version': '1.1.1', | ||
| 2322 | 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', | ||
| 2323 | 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' | ||
| 2324 | } | ||
| 2325 | } | ||
| 2326 | }) | ||
| 2327 | self.d.setVar('BB_NO_NETWORK', '1') | ||
| 2328 | fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d) | ||
| 2329 | with self.assertRaises(bb.fetch2.NetworkAccess): | ||
| 2330 | fetcher.download() | ||
| 2331 | |||
| 2332 | @skipIfNoNpm() | ||
| 2333 | @skipIfNoNetwork() | ||
| 2334 | def test_npmsw_no_network_with_tarball(self): | ||
| 2335 | # Fetch once to get a tarball | ||
| 2336 | fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d) | ||
| 2337 | fetcher.download() | ||
| 2338 | # Disable network access | ||
| 2339 | self.d.setVar('BB_NO_NETWORK', '1') | ||
| 2340 | # Fetch again | ||
| 2341 | swfile = self.create_shrinkwrap_file({ | ||
| 2342 | 'dependencies': { | ||
| 2343 | 'array-flatten': { | ||
| 2344 | 'version': '1.1.1', | ||
| 2345 | 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', | ||
| 2346 | 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' | ||
| 2347 | } | ||
| 2348 | } | ||
| 2349 | }) | ||
| 2350 | fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d) | ||
| 2351 | fetcher.download() | ||
| 2352 | fetcher.unpack(self.unpackdir) | ||
| 2353 | self.assertTrue(os.path.exists(os.path.join(self.sdir, 'node_modules', 'array-flatten', 'package.json'))) | ||
| 2354 | |||
| 2355 | @skipIfNoNpm() | ||
| 2356 | @skipIfNoNetwork() | ||
| 2357 | def test_npmsw_npm_reusability(self): | ||
| 2358 | # Fetch once with npmsw | ||
| 2359 | swfile = self.create_shrinkwrap_file({ | ||
| 2360 | 'dependencies': { | ||
| 2361 | 'array-flatten': { | ||
| 2362 | 'version': '1.1.1', | ||
| 2363 | 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', | ||
| 2364 | 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' | ||
| 2365 | } | ||
| 2366 | } | ||
| 2367 | }) | ||
| 2368 | fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d) | ||
| 2369 | fetcher.download() | ||
| 2370 | # Disable network access | ||
| 2371 | self.d.setVar('BB_NO_NETWORK', '1') | ||
| 2372 | # Fetch again with npm | ||
| 2373 | fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d) | ||
| 2374 | fetcher.download() | ||
| 2375 | fetcher.unpack(self.unpackdir) | ||
| 2376 | self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'npm', 'package.json'))) | ||
| 2377 | |||
| 2378 | @skipIfNoNpm() | ||
| 2379 | @skipIfNoNetwork() | ||
| 2380 | def test_npmsw_bad_checksum(self): | ||
| 2381 | # Try to fetch with bad checksum | ||
| 2382 | swfile = self.create_shrinkwrap_file({ | ||
| 2383 | 'dependencies': { | ||
| 2384 | 'array-flatten': { | ||
| 2385 | 'version': '1.1.1', | ||
| 2386 | 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', | ||
| 2387 | 'integrity': 'sha1-gfNEp2hqgLTFKT6P3AsBYMgsBqg=' | ||
| 2388 | } | ||
| 2389 | } | ||
| 2390 | }) | ||
| 2391 | fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d) | ||
| 2392 | with self.assertRaises(bb.fetch2.FetchError): | ||
| 2393 | fetcher.download() | ||
| 2394 | # Fetch correctly to get a tarball | ||
| 2395 | swfile = self.create_shrinkwrap_file({ | ||
| 2396 | 'dependencies': { | ||
| 2397 | 'array-flatten': { | ||
| 2398 | 'version': '1.1.1', | ||
| 2399 | 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', | ||
| 2400 | 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' | ||
| 2401 | } | ||
| 2402 | } | ||
| 2403 | }) | ||
| 2404 | fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d) | ||
| 2405 | fetcher.download() | ||
| 2406 | localpath = os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz') | ||
| 2407 | self.assertTrue(os.path.exists(localpath)) | ||
| 2408 | # Modify the tarball | ||
| 2409 | bad = b'bad checksum' | ||
| 2410 | with open(localpath, 'wb') as f: | ||
| 2411 | f.write(bad) | ||
| 2412 | # Verify that the tarball is fetched again | ||
| 2413 | fetcher.download() | ||
| 2414 | badsum = hashlib.sha1(bad).hexdigest() | ||
| 2415 | self.assertTrue(os.path.exists(localpath + '_bad-checksum_' + badsum)) | ||
| 2416 | self.assertTrue(os.path.exists(localpath)) | ||
| 2417 | |||
| 2418 | @skipIfNoNpm() | ||
| 2419 | @skipIfNoNetwork() | ||
| 2420 | def test_npmsw_premirrors(self): | ||
| 2421 | # Fetch once to get a tarball | ||
| 2422 | fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d) | ||
| 2423 | ud = fetcher.ud[fetcher.urls[0]] | ||
| 2424 | fetcher.download() | ||
| 2425 | self.assertTrue(os.path.exists(ud.localpath)) | ||
| 2426 | # Setup the mirror | ||
| 2427 | mirrordir = os.path.join(self.tempdir, 'mirror') | ||
| 2428 | bb.utils.mkdirhier(mirrordir) | ||
| 2429 | os.replace(ud.localpath, os.path.join(mirrordir, os.path.basename(ud.localpath))) | ||
| 2430 | self.d.setVar('PREMIRRORS', 'https?$://.*/.* file://%s/\n' % mirrordir) | ||
| 2431 | self.d.setVar('BB_FETCH_PREMIRRORONLY', '1') | ||
| 2432 | # Fetch again | ||
| 2433 | self.assertFalse(os.path.exists(ud.localpath)) | ||
| 2434 | swfile = self.create_shrinkwrap_file({ | ||
| 2435 | 'dependencies': { | ||
| 2436 | 'array-flatten': { | ||
| 2437 | 'version': '1.1.1', | ||
| 2438 | 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', | ||
| 2439 | 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' | ||
| 2440 | } | ||
| 2441 | } | ||
| 2442 | }) | ||
| 2443 | fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d) | ||
| 2444 | fetcher.download() | ||
| 2445 | self.assertTrue(os.path.exists(ud.localpath)) | ||
| 2446 | |||
| 2447 | @skipIfNoNpm() | ||
| 2448 | @skipIfNoNetwork() | ||
| 2449 | def test_npmsw_mirrors(self): | ||
| 2450 | # Fetch once to get a tarball | ||
| 2451 | fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d) | ||
| 2452 | ud = fetcher.ud[fetcher.urls[0]] | ||
| 2453 | fetcher.download() | ||
| 2454 | self.assertTrue(os.path.exists(ud.localpath)) | ||
| 2455 | # Setup the mirror | ||
| 2456 | mirrordir = os.path.join(self.tempdir, 'mirror') | ||
| 2457 | bb.utils.mkdirhier(mirrordir) | ||
| 2458 | os.replace(ud.localpath, os.path.join(mirrordir, os.path.basename(ud.localpath))) | ||
| 2459 | self.d.setVar('MIRRORS', 'https?$://.*/.* file://%s/\n' % mirrordir) | ||
| 2460 | # Fetch again with invalid url | ||
| 2461 | self.assertFalse(os.path.exists(ud.localpath)) | ||
| 2462 | swfile = self.create_shrinkwrap_file({ | ||
| 2463 | 'dependencies': { | ||
| 2464 | 'array-flatten': { | ||
| 2465 | 'version': '1.1.1', | ||
| 2466 | 'resolved': 'https://invalid', | ||
| 2467 | 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' | ||
| 2468 | } | ||
| 2469 | } | ||
| 2470 | }) | ||
| 2471 | fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d) | ||
| 2472 | fetcher.download() | ||
| 2473 | self.assertTrue(os.path.exists(ud.localpath)) | ||
