summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorJean-Marie LEMETAYER <jean-marie.lemetayer@savoirfairelinux.com>2020-01-24 18:08:12 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-01-27 16:48:10 +0000
commit8b9505f1d4b139a71df3c184afa99bfd5bd9bc0b (patch)
tree1fcf98952ad0f9fba0d102951b40f1745c40b7d7 /bitbake
parentd842e9e738e14fc54c21434755033d6eb6b6f3f2 (diff)
downloadpoky-8b9505f1d4b139a71df3c184afa99bfd5bd9bc0b.tar.gz
bitbake: tests/fetch: add npm tests
This commit adds some tests to validate the npm fetcher: - bb.tests.fetch.NPMTest.test_npm - bb.tests.fetch.NPMTest.test_npm_bad_checksum - bb.tests.fetch.NPMTest.test_npm_destsuffix_downloadfilename - bb.tests.fetch.NPMTest.test_npm_mirrors - bb.tests.fetch.NPMTest.test_npm_no_network_no_tarball - bb.tests.fetch.NPMTest.test_npm_no_network_with_tarball - bb.tests.fetch.NPMTest.test_npm_package_invalid - bb.tests.fetch.NPMTest.test_npm_package_none - bb.tests.fetch.NPMTest.test_npm_premirrors - bb.tests.fetch.NPMTest.test_npm_registry_alternate - bb.tests.fetch.NPMTest.test_npm_registry_invalid - bb.tests.fetch.NPMTest.test_npm_registry_none - bb.tests.fetch.NPMTest.test_npm_version_invalid - bb.tests.fetch.NPMTest.test_npm_version_latest - bb.tests.fetch.NPMTest.test_npm_version_none (Bitbake rev: b166bd3cc6cc1ca63e885319091f17daaaaa2537) 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.py183
1 files changed, 183 insertions, 0 deletions
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
index fa0c5c5ae3..5eeb64c512 100644
--- a/bitbake/lib/bb/tests/fetch.py
+++ b/bitbake/lib/bb/tests/fetch.py
@@ -2037,3 +2037,186 @@ class GitLfsTest(FetcherTest):
2037 ud.method._find_git_lfs = lambda d: False 2037 ud.method._find_git_lfs = lambda d: False
2038 shutil.rmtree(self.gitdir, ignore_errors=True) 2038 shutil.rmtree(self.gitdir, ignore_errors=True)
2039 fetcher.unpack(self.d.getVar('WORKDIR')) 2039 fetcher.unpack(self.d.getVar('WORKDIR'))
2040
2041class NPMTest(FetcherTest):
2042 def skipIfNoNpm():
2043 import shutil
2044 if not shutil.which('npm'):
2045 return unittest.skip('npm not installed, tests being skipped')
2046 return lambda f: f
2047
2048 @skipIfNoNpm()
2049 @skipIfNoNetwork()
2050 def test_npm(self):
2051 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2052 fetcher = bb.fetch.Fetch([url], self.d)
2053 ud = fetcher.ud[fetcher.urls[0]]
2054 fetcher.download()
2055 self.assertTrue(os.path.exists(ud.localpath))
2056 self.assertTrue(os.path.exists(ud.localpath + '.done'))
2057 self.assertTrue(os.path.exists(ud.resolvefile))
2058 fetcher.unpack(self.unpackdir)
2059 unpackdir = os.path.join(self.unpackdir, 'npm')
2060 self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
2061
2062 @skipIfNoNpm()
2063 @skipIfNoNetwork()
2064 def test_npm_bad_checksum(self):
2065 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2066 # Fetch once to get a tarball
2067 fetcher = bb.fetch.Fetch([url], self.d)
2068 ud = fetcher.ud[fetcher.urls[0]]
2069 fetcher.download()
2070 self.assertTrue(os.path.exists(ud.localpath))
2071 # Modify the tarball
2072 bad = b'bad checksum'
2073 with open(ud.localpath, 'wb') as f:
2074 f.write(bad)
2075 # Verify that the tarball is fetched again
2076 fetcher.download()
2077 badsum = hashlib.sha512(bad).hexdigest()
2078 self.assertTrue(os.path.exists(ud.localpath + '_bad-checksum_' + badsum))
2079 self.assertTrue(os.path.exists(ud.localpath))
2080
2081 @skipIfNoNpm()
2082 @skipIfNoNetwork()
2083 def test_npm_premirrors(self):
2084 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2085 # Fetch once to get a tarball
2086 fetcher = bb.fetch.Fetch([url], self.d)
2087 ud = fetcher.ud[fetcher.urls[0]]
2088 fetcher.download()
2089 self.assertTrue(os.path.exists(ud.localpath))
2090 # Setup the mirror
2091 mirrordir = os.path.join(self.tempdir, 'mirror')
2092 bb.utils.mkdirhier(mirrordir)
2093 os.replace(ud.localpath, os.path.join(mirrordir, os.path.basename(ud.localpath)))
2094 self.d.setVar('PREMIRRORS', 'https?$://.*/.* file://%s/\n' % mirrordir)
2095 self.d.setVar('BB_FETCH_PREMIRRORONLY', '1')
2096 # Fetch again
2097 self.assertFalse(os.path.exists(ud.localpath))
2098 fetcher.download()
2099 self.assertTrue(os.path.exists(ud.localpath))
2100
2101 @skipIfNoNpm()
2102 @skipIfNoNetwork()
2103 def test_npm_mirrors(self):
2104 # Fetch once to get a tarball
2105 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2106 fetcher = bb.fetch.Fetch([url], self.d)
2107 ud = fetcher.ud[fetcher.urls[0]]
2108 fetcher.download()
2109 self.assertTrue(os.path.exists(ud.localpath))
2110 # Setup the mirror
2111 mirrordir = os.path.join(self.tempdir, 'mirror')
2112 bb.utils.mkdirhier(mirrordir)
2113 os.replace(ud.localpath, os.path.join(mirrordir, os.path.basename(ud.localpath)))
2114 self.d.setVar('MIRRORS', 'https?$://.*/.* file://%s/\n' % mirrordir)
2115 # Update the resolved url to an invalid url
2116 with open(ud.resolvefile, 'r') as f:
2117 url = f.read()
2118 uri = URI(url)
2119 uri.path = '/invalid'
2120 with open(ud.resolvefile, 'w') as f:
2121 f.write(str(uri))
2122 # Fetch again
2123 self.assertFalse(os.path.exists(ud.localpath))
2124 fetcher.download()
2125 self.assertTrue(os.path.exists(ud.localpath))
2126
2127 @skipIfNoNpm()
2128 @skipIfNoNetwork()
2129 def test_npm_destsuffix_downloadfilename(self):
2130 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0;destsuffix=foo/bar;downloadfilename=foo-bar.tgz'
2131 fetcher = bb.fetch.Fetch([url], self.d)
2132 fetcher.download()
2133 self.assertTrue(os.path.exists(os.path.join(self.dldir, 'foo-bar.tgz')))
2134 fetcher.unpack(self.unpackdir)
2135 unpackdir = os.path.join(self.unpackdir, 'foo', 'bar')
2136 self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
2137
2138 def test_npm_no_network_no_tarball(self):
2139 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2140 self.d.setVar('BB_NO_NETWORK', '1')
2141 fetcher = bb.fetch.Fetch([url], self.d)
2142 with self.assertRaises(bb.fetch2.NetworkAccess):
2143 fetcher.download()
2144
2145 @skipIfNoNpm()
2146 @skipIfNoNetwork()
2147 def test_npm_no_network_with_tarball(self):
2148 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2149 # Fetch once to get a tarball
2150 fetcher = bb.fetch.Fetch([url], self.d)
2151 fetcher.download()
2152 # Disable network access
2153 self.d.setVar('BB_NO_NETWORK', '1')
2154 # Fetch again
2155 fetcher.download()
2156 fetcher.unpack(self.unpackdir)
2157 unpackdir = os.path.join(self.unpackdir, 'npm')
2158 self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
2159
2160 @skipIfNoNpm()
2161 @skipIfNoNetwork()
2162 def test_npm_registry_alternate(self):
2163 url = 'npm://registry.freajs.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2164 fetcher = bb.fetch.Fetch([url], self.d)
2165 fetcher.download()
2166 fetcher.unpack(self.unpackdir)
2167 unpackdir = os.path.join(self.unpackdir, 'npm')
2168 self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
2169
2170 @skipIfNoNpm()
2171 @skipIfNoNetwork()
2172 def test_npm_version_latest(self):
2173 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=latest'
2174 fetcher = bb.fetch.Fetch([url], self.d)
2175 fetcher.download()
2176 fetcher.unpack(self.unpackdir)
2177 unpackdir = os.path.join(self.unpackdir, 'npm')
2178 self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json')))
2179
2180 @skipIfNoNpm()
2181 @skipIfNoNetwork()
2182 def test_npm_registry_invalid(self):
2183 url = 'npm://registry.invalid.org;package=@savoirfairelinux/node-server-example;version=1.0.0'
2184 fetcher = bb.fetch.Fetch([url], self.d)
2185 with self.assertRaises(bb.fetch2.FetchError):
2186 fetcher.download()
2187
2188 @skipIfNoNpm()
2189 @skipIfNoNetwork()
2190 def test_npm_package_invalid(self):
2191 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/invalid;version=1.0.0'
2192 fetcher = bb.fetch.Fetch([url], self.d)
2193 with self.assertRaises(bb.fetch2.FetchError):
2194 fetcher.download()
2195
2196 @skipIfNoNpm()
2197 @skipIfNoNetwork()
2198 def test_npm_version_invalid(self):
2199 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=invalid'
2200 with self.assertRaises(bb.fetch2.ParameterError):
2201 fetcher = bb.fetch.Fetch([url], self.d)
2202
2203 @skipIfNoNpm()
2204 @skipIfNoNetwork()
2205 def test_npm_registry_none(self):
2206 url = 'npm://;package=@savoirfairelinux/node-server-example;version=1.0.0'
2207 with self.assertRaises(bb.fetch2.MalformedUrl):
2208 fetcher = bb.fetch.Fetch([url], self.d)
2209
2210 @skipIfNoNpm()
2211 @skipIfNoNetwork()
2212 def test_npm_package_none(self):
2213 url = 'npm://registry.npmjs.org;version=1.0.0'
2214 with self.assertRaises(bb.fetch2.MissingParameterError):
2215 fetcher = bb.fetch.Fetch([url], self.d)
2216
2217 @skipIfNoNpm()
2218 @skipIfNoNetwork()
2219 def test_npm_version_none(self):
2220 url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example'
2221 with self.assertRaises(bb.fetch2.MissingParameterError):
2222 fetcher = bb.fetch.Fetch([url], self.d)