UNPKG

8.4 kBPlain TextView Raw
1import CachingUrlFetcher from '../src/CachingUrlFetcher'
2import fs from 'fs'
3import { fixture } from './test-functions'
4
5export default class MockUrlFetcher extends CachingUrlFetcher {
6 async fetchUrl (url: string, options: any = { json: true }): Promise<any> {
7 if (url.indexOf('sysreqs.r-hub.io/pkg') !== -1) {
8 return this.getRSysReqs(url)
9 }
10
11 if (url.indexOf('crandb.r-pkg.org') !== -1) {
12 return this.getCranDb(url)
13 }
14
15 if (url.indexOf('pypi.org/pypi/') !== -1) {
16 return this.getPyPi(url)
17 }
18
19 if (url.indexOf('registry.npmjs.org/') !== -1) {
20 return this.getNpmRegistry(url)
21 }
22
23 console.warn(`Unhandled URL in Mock fetcher: ${url}`)
24
25 return super.fetchUrl(url, options)
26 }
27
28 getRSysReqs (url: string): any {
29 if (url === 'https://sysreqs.r-hub.io/pkg/xml2') {
30 return [{
31 'libxml2': {
32 'sysreqs': 'libxml2',
33 'platforms': { 'DEB': 'libxml2-dev', 'OSX/brew': null, 'RPM': 'libxml2-devel' }
34 }
35 }]
36 }
37
38 if (url === 'https://sysreqs.r-hub.io/pkg/haven') {
39 return [{
40 'gnumake': {
41 'sysreqs': ['GNU make', 'GNU Make'],
42 'platforms': { 'DEB': 'make', 'OSX/brew': null, 'RPM': 'make' }
43 }
44 }]
45 }
46
47 if (url === 'https://sysreqs.r-hub.io/pkg/curl') {
48 return [{
49 'libcurl': {
50 'sysreqs': 'libcurl',
51 'platforms': { 'DEB': 'libcurl4-openssl-dev', 'OSX/brew': null, 'RPM': 'libcurl-devel' }
52 }
53 }, {
54 'openssl': {
55 'sysreqs': 'OpenSSL',
56 'platforms': { 'DEB': 'libssl-dev', 'OSX/brew': 'openssl@1.1', 'RPM': 'openssl-devel' }
57 }
58 }]
59 }
60
61 if (url === 'https://sysreqs.r-hub.io/pkg/gsl') {
62 return [
63 {
64 "libgsl": {
65 "sysreqs": [
66 "/Gnu Scientific Library/i",
67 "/\\bgsl\\b/"
68 ],
69 "platforms": {
70 "DEB": [
71 {
72 "distribution": "Ubuntu",
73 "releases": [
74 "precise",
75 "trusty",
76 "vivid",
77 "wily"
78 ],
79 "runtime": "libgsl0ldbl",
80 "buildtime": "libgsl0-dev"
81 },
82 {
83 "distribution": "Ubuntu",
84 "runtime": "libgsl2",
85 "buildtime": "libgsl-dev"
86 },
87 {
88 "distribution": "Debian",
89 "releases": [
90 "squeeze",
91 "wheezy",
92 "jessie"
93 ],
94 "runtime": "libgsl0ldbl",
95 "buildtime": "libgsl0-dev"
96 },
97 {
98 "distribution": "Debian",
99 "runtime": "libgsl2",
100 "buildtime": "libgsl-dev"
101 }
102 ],
103 "OSX/brew": "gsl",
104 "RPM": {
105 "runtime": "gsl",
106 "buildtime": "gsl-devel"
107 }
108 }
109 }
110 }
111 ]
112 }
113
114 return []
115 }
116
117 getCranDb (url: string): any {
118 if (url === 'http://crandb.r-pkg.org/curl') {
119 return {
120 Package: 'curl',
121 Version: '3.2',
122 SystemRequirements: 'libcurl: libcurl-devel (rpm) or\nlibcurl4-openssl-dev (deb).'
123 }
124 }
125
126 if (url === 'http://crandb.r-pkg.org/haven') {
127 return {
128 Package: 'haven',
129 Version: '1.1.2',
130 SystemRequirements: 'GNU make'
131 }
132 }
133
134 if (url === 'http://crandb.r-pkg.org/rio') {
135 return {
136 Package: 'rio',
137 Version: '0.5.10',
138 Imports: {
139 tools: '*',
140 stats: '*',
141 utils: '*',
142 foreign: '*',
143 haven: '>= 1.1.0',
144 curl: '>= 0.6',
145 'data.table': '>= 1.9.8',
146 readxl: '>= 0.1.1',
147 openxlsx: '*',
148 tibble: '*'
149 }
150 }
151 }
152
153 if (url === 'http://crandb.r-pkg.org/car') {
154 return {
155 Package: 'rio',
156 Version: '0.5.10',
157 Imports: {
158 abind: '*',
159 MASS: '*',
160 mgcv: '*',
161 nnet: '*',
162 pbkrtest: '>= 0.4-4',
163 quantreg: '*',
164 grDevices: '*',
165 utils: '*',
166 stats: '*',
167 graphics: '*',
168 maptools: '*',
169 rio: '*',
170 lme4: '*',
171 nlme: '*'
172 }
173 }
174 }
175
176 if (url === 'http://crandb.r-pkg.org/gsl') {
177 return {
178 "Author": "Robin K. S. Hankin; qrng functions by Duncan Murdoch and\nmultimin by Andrew Clausen",
179 "Date": "2016-12-14",
180 "Date/Publication": "2017-01-05 11:13:10",
181 "Depends": {
182 "R": ">= 2.10.0"
183 },
184 "Description": "\nAn R wrapper for the special functions and quasi random number\ngenerators of the Gnu Scientific Library\n(http://www.gnu.org/software/gsl/). See gsl-package.Rd for details of\noverall package organization, and Misc.Rd for some functions that are\nwidely used in the package, and some tips on installation.",
185 "License": "GPL (>= 2)",
186 "Maintainer": "Robin K. S. Hankin <hankin.robin@gmail.com>",
187 "NeedsCompilation": "yes",
188 "Package": "gsl",
189 "Packaged": "2017-01-05 07:48:21 UTC; rksh",
190 "Repository": "CRAN",
191 "SystemRequirements": "Gnu Scientific Library version >= 1.12",
192 "Title": "Wrapper for the Gnu Scientific Library",
193 "Version": "1.9-10.3",
194 "crandb_file_date": "2017-01-05 10:14:53",
195 "date": "2017-01-05T10:13:10+00:00",
196 "releases": []
197 }
198 }
199
200
201 return {}
202 }
203
204 getPyPi (url: string): any {
205 if (url === 'https://pypi.org/pypi/arrow/json') {
206 return {
207 info: {
208 author: 'Joe Bloggs',
209 author_email: 'joe.bloggs@example.com',
210 project_url: 'http://www.example.com/project',
211 classifiers: [
212 'Development Status :: 5 - Production/Stable',
213 'Intended Audience :: Developers',
214 'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)',
215 'License :: OSI Approved :: Zope Public License',
216 'Operating System :: Microsoft :: Windows',
217 'Operating System :: Unix',
218 'Programming Language :: C',
219 'Programming Language :: Python',
220 'Programming Language :: Python :: 2',
221 'Programming Language :: Python :: 2.6',
222 'Programming Language :: Python :: 2.7',
223 'Programming Language :: Python :: 3',
224 'Programming Language :: Python :: 3.2',
225 'Programming Language :: Python :: 3.3',
226 'Programming Language :: Python :: 3.4',
227 'Programming Language :: Python :: 3.5',
228 'Programming Language :: Python :: 3.6',
229 'Programming Language :: Python :: Implementation :: CPython',
230 'Programming Language :: SQL',
231 'Topic :: Database',
232 'Topic :: Database :: Front-Ends',
233 'Topic :: Software Development',
234 'Topic :: Software Development :: Libraries :: Python Modules'
235 ],
236 keywords: 'test keywords list',
237 license: 'Free Software License',
238 long_description: 'This is the long description that will be used in priority over description',
239 description: 'This probably won\'t be used'
240 }
241 }
242 }
243
244 return {}
245 }
246
247 getNpmRegistry (url: string): any {
248 if (url === 'https://registry.npmjs.org/is-sorted/latest') {
249 return JSON.parse(fs.readFileSync(fixture('is-sorted.json'), 'utf8'))
250 }
251
252 if (url === 'https://registry.npmjs.org/array-swap/latest') {
253 return JSON.parse(fs.readFileSync(fixture('array-swap.json'), 'utf8'))
254 }
255
256 if (url.indexOf('https://registry.npmjs.org/mkdirp/') !== -1) {
257 return { name: 'mkdirp', version: '0.5.1' }
258 }
259
260 if (url.indexOf('https://registry.npmjs.org/is-array/') !== -1) {
261 return { name: 'is-array', version: '1.0.1' }
262 }
263
264 if (url.indexOf('https://registry.npmjs.org/rimraf/') !== -1) {
265 return { name: 'rimraf', version: '2.6.2' }
266 }
267
268 if (url.indexOf('https://registry.npmjs.org/array-swap/') !== -1) {
269 return { name: 'array-swap', version: '0.0.2' }
270 }
271
272 return null
273 }
274}