@na1647/offshore-adapter-tests 0.0.0-stage → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc +35 -0
  3. package/.travis.yml +32 -0
  4. package/CHANGELOG.md +24 -0
  5. package/Dockerfile +7 -0
  6. package/LICENSE.md +11 -0
  7. package/README.md +71 -2
  8. package/docker-compose.yml +32 -0
  9. package/features/autoIncrement/README.md +37 -0
  10. package/features/autoIncrement/core/autoIncrement.test.js +151 -0
  11. package/features/autoIncrement/sequential/autoIncrementSequential.test.js +104 -0
  12. package/features/autoIncrement/support/autoInc.fixture.js +25 -0
  13. package/features/compositePrimaryKey/core/compositePrimaryKey.test.js +67 -0
  14. package/features/compositePrimaryKey/support/fixture.js +24 -0
  15. package/features/compositeUnique/core/compositeUnique.test.js +67 -0
  16. package/features/compositeUnique/support/fixture.js +30 -0
  17. package/features/crossAdapter/core/crossAdapter.js +119 -0
  18. package/features/crossAdapter/support/bootstrap.js +106 -0
  19. package/features/sequences/core/sequences.test.js +110 -0
  20. package/features/sequences/support/mariadb.js +23 -0
  21. package/features/sequences/support/oracle.js +23 -0
  22. package/features/sequences/support/postgres.js +23 -0
  23. package/features/spatial/core/geojson.test.js +68 -0
  24. package/features/spatial/support/fixtures.js +82 -0
  25. package/features/spatial/support/models.js +45 -0
  26. package/features/unique/README.md +18 -0
  27. package/features/unique/core/unique.test.js +107 -0
  28. package/features/unique/support/unique.fixture.js +26 -0
  29. package/interfaces/associations/belongsTo/create.js +41 -0
  30. package/interfaces/associations/belongsTo/create.nested.customPK.js +61 -0
  31. package/interfaces/associations/belongsTo/create.nested.js +52 -0
  32. package/interfaces/associations/belongsTo/dynamicFinder.js +213 -0
  33. package/interfaces/associations/belongsTo/find.populate.js +145 -0
  34. package/interfaces/associations/belongsTo/findOne.populate.js +84 -0
  35. package/interfaces/associations/belongsTo/modifiers.js +275 -0
  36. package/interfaces/associations/belongsTo/multipleForeignKeys.js +70 -0
  37. package/interfaces/associations/belongsTo/update.nested.customPK.js +141 -0
  38. package/interfaces/associations/belongsTo/update.nested.js +174 -0
  39. package/interfaces/associations/deep.associations.test.js +437 -0
  40. package/interfaces/associations/find.associations.test.js +92 -0
  41. package/interfaces/associations/hasMany/add.js +106 -0
  42. package/interfaces/associations/hasMany/create.nested.customPK.js +113 -0
  43. package/interfaces/associations/hasMany/create.nested.js +96 -0
  44. package/interfaces/associations/hasMany/find.populate.customPK.js +75 -0
  45. package/interfaces/associations/hasMany/find.populate.js +219 -0
  46. package/interfaces/associations/hasMany/find.populate.where.js +148 -0
  47. package/interfaces/associations/hasMany/findOne.populate.js +88 -0
  48. package/interfaces/associations/hasMany/modifiers.js +560 -0
  49. package/interfaces/associations/hasMany/multipleForeignKeys.js +113 -0
  50. package/interfaces/associations/hasMany/remove.js +96 -0
  51. package/interfaces/associations/hasMany/update.nested.customPK.js +148 -0
  52. package/interfaces/associations/hasMany/update.nested.js +202 -0
  53. package/interfaces/associations/manyToMany/add.js +136 -0
  54. package/interfaces/associations/manyToMany/create.nested.customPK.js +109 -0
  55. package/interfaces/associations/manyToMany/create.nested.js +96 -0
  56. package/interfaces/associations/manyToMany/destroy.js +128 -0
  57. package/interfaces/associations/manyToMany/find.populate.js +109 -0
  58. package/interfaces/associations/manyToMany/find.populate.where.js +75 -0
  59. package/interfaces/associations/manyToMany/find.populate.withSchema.js +91 -0
  60. package/interfaces/associations/manyToMany/findOne.populate.js +86 -0
  61. package/interfaces/associations/manyToMany/modifiers.js +558 -0
  62. package/interfaces/associations/manyToMany/remove.js +103 -0
  63. package/interfaces/associations/manyToMany/update.js +105 -0
  64. package/interfaces/associations/manyToMany/update.nested.customPK.js +315 -0
  65. package/interfaces/associations/manyToMany/update.nested.js +355 -0
  66. package/interfaces/associations/manyToManyThrough/add.js +109 -0
  67. package/interfaces/associations/manyToManyThrough/create.nested.customPK.js +118 -0
  68. package/interfaces/associations/manyToManyThrough/create.nested.js +114 -0
  69. package/interfaces/associations/manyToManyThrough/find.populate.customPK.js +76 -0
  70. package/interfaces/associations/manyToManyThrough/find.populate.js +120 -0
  71. package/interfaces/associations/manyToManyThrough/find.populate.where.js +157 -0
  72. package/interfaces/associations/manyToManyThrough/findOne.populate.js +93 -0
  73. package/interfaces/associations/manyToManyThrough/modifiers.js +560 -0
  74. package/interfaces/associations/manyToManyThrough/multipleForeignKeys.js +118 -0
  75. package/interfaces/associations/manyToManyThrough/remove.js +98 -0
  76. package/interfaces/associations/manyToManyThrough/update.nested.customPK.js +150 -0
  77. package/interfaces/associations/manyToManyThrough/update.nested.js +202 -0
  78. package/interfaces/associations/oneToOne/create.js +41 -0
  79. package/interfaces/associations/oneToOne/create.nested.customPK.js +61 -0
  80. package/interfaces/associations/oneToOne/create.nested.js +52 -0
  81. package/interfaces/associations/oneToOne/dynamicFinder.js +68 -0
  82. package/interfaces/associations/oneToOne/find.populate.js +127 -0
  83. package/interfaces/associations/oneToOne/findOne.populate.js +83 -0
  84. package/interfaces/associations/oneToOne/modifiers.js +275 -0
  85. package/interfaces/associations/oneToOne/multipleForeignKeys.js +69 -0
  86. package/interfaces/associations/oneToOne/update.nested.customPK.js +141 -0
  87. package/interfaces/associations/oneToOne/update.nested.js +174 -0
  88. package/interfaces/associations/support/bootstrap.js +82 -0
  89. package/interfaces/associations/support/fixtures/belongsTo.child.customPK.fixture.js +25 -0
  90. package/interfaces/associations/support/fixtures/belongsTo.child.fixture.js +25 -0
  91. package/interfaces/associations/support/fixtures/belongsTo.parent.customPK.fixture.js +26 -0
  92. package/interfaces/associations/support/fixtures/belongsTo.parent.fixture.js +28 -0
  93. package/interfaces/associations/support/fixtures/crud.fixture.js +53 -0
  94. package/interfaces/associations/support/fixtures/deep.address.fixture.js +21 -0
  95. package/interfaces/associations/support/fixtures/deep.breakdown.fixture.js +23 -0
  96. package/interfaces/associations/support/fixtures/deep.company.fixture.js +29 -0
  97. package/interfaces/associations/support/fixtures/deep.country.fixture.js +25 -0
  98. package/interfaces/associations/support/fixtures/deep.departement.fixture.js +24 -0
  99. package/interfaces/associations/support/fixtures/deep.driver.fixture.js +32 -0
  100. package/interfaces/associations/support/fixtures/deep.ride.fixture.js +23 -0
  101. package/interfaces/associations/support/fixtures/deep.seller.fixture.js +33 -0
  102. package/interfaces/associations/support/fixtures/deep.taxi.fixture.js +36 -0
  103. package/interfaces/associations/support/fixtures/hasMany.child.fixture.js +33 -0
  104. package/interfaces/associations/support/fixtures/hasMany.customPK.fixture.js +22 -0
  105. package/interfaces/associations/support/fixtures/hasMany.parent.fixture.js +28 -0
  106. package/interfaces/associations/support/fixtures/hasManyThrough.child.customPK.fixture.js +32 -0
  107. package/interfaces/associations/support/fixtures/hasManyThrough.parent.customPK.fixture.js +23 -0
  108. package/interfaces/associations/support/fixtures/hasManyThrough.stadium.fixture.js +20 -0
  109. package/interfaces/associations/support/fixtures/hasManyThrough.team.fixture.js +35 -0
  110. package/interfaces/associations/support/fixtures/hasManyThrough.through.customPK.fixture.js +18 -0
  111. package/interfaces/associations/support/fixtures/hasManyThrough.venue.fixture.js +18 -0
  112. package/interfaces/associations/support/fixtures/manyToMany.driver.customPK.fixture.js +22 -0
  113. package/interfaces/associations/support/fixtures/manyToMany.driver.fixture.js +25 -0
  114. package/interfaces/associations/support/fixtures/manyToMany.driver.withSchema.fixture.js +25 -0
  115. package/interfaces/associations/support/fixtures/manyToMany.taxi.customPK.fixture.js +21 -0
  116. package/interfaces/associations/support/fixtures/manyToMany.taxi.fixture.js +30 -0
  117. package/interfaces/associations/support/fixtures/manyToMany.taxi.withSchema.fixture.js +24 -0
  118. package/interfaces/associations/support/fixtures/multipleAssociations.fixture.js +54 -0
  119. package/interfaces/associations/support/fixtures/multipleOneToOneAssociations.fixture.js +40 -0
  120. package/interfaces/associations/support/fixtures/multipleThroughAssociations.fixture.js +79 -0
  121. package/interfaces/associations/support/fixtures/oneToOne.customPK.fixture.js +47 -0
  122. package/interfaces/associations/support/fixtures/oneToOne.fixture.js +52 -0
  123. package/interfaces/associations/support/fixtures.js +41 -0
  124. package/interfaces/datastore/datastore.test.js +63 -0
  125. package/interfaces/migratable/definition.test.js +65 -0
  126. package/interfaces/migratable/migrate.alter.test.js +55 -0
  127. package/interfaces/migratable/migrate.create.test.js +120 -0
  128. package/interfaces/migratable/migrate.drop.test.js +47 -0
  129. package/interfaces/migratable/migrate.safe.test.js +25 -0
  130. package/interfaces/migratable/schema.test.js +117 -0
  131. package/interfaces/migratable/support/bootstrap.js +55 -0
  132. package/interfaces/migratable/support/bootstrapFn.js +54 -0
  133. package/interfaces/migratable/support/fixtures/alter.fixture.js +12 -0
  134. package/interfaces/migratable/support/fixtures/create.fixture.js +12 -0
  135. package/interfaces/migratable/support/fixtures/crud.fixture.js +53 -0
  136. package/interfaces/migratable/support/fixtures/custom.fixture.js +17 -0
  137. package/interfaces/migratable/support/fixtures/drop.fixture.js +12 -0
  138. package/interfaces/migratable/support/fixtures/safe.fixture.js +12 -0
  139. package/interfaces/migratable/support/fixtures/schema.fixture.js +23 -0
  140. package/interfaces/queryable/caseInsensitive.test.js +196 -0
  141. package/interfaces/queryable/count.test.js +51 -0
  142. package/interfaces/queryable/dynamicFinders.test.js +179 -0
  143. package/interfaces/queryable/findLike.test.js +34 -0
  144. package/interfaces/queryable/findOneLike.test.js +28 -0
  145. package/interfaces/queryable/modifiers/average.modifier.test.js +55 -0
  146. package/interfaces/queryable/modifiers/contains.modifier.test.js +82 -0
  147. package/interfaces/queryable/modifiers/endsWith.modifier.test.js +82 -0
  148. package/interfaces/queryable/modifiers/greaterThan.modifier.test.js +335 -0
  149. package/interfaces/queryable/modifiers/groupBy.modifier.test.js +123 -0
  150. package/interfaces/queryable/modifiers/in.modifier.test.js +76 -0
  151. package/interfaces/queryable/modifiers/lessThan.modifier.test.js +223 -0
  152. package/interfaces/queryable/modifiers/like.modifier.test.js +50 -0
  153. package/interfaces/queryable/modifiers/limit.modifier.test.js +60 -0
  154. package/interfaces/queryable/modifiers/max.modifier.test.js +68 -0
  155. package/interfaces/queryable/modifiers/min.modifier.test.js +68 -0
  156. package/interfaces/queryable/modifiers/not.modifier.test.js +80 -0
  157. package/interfaces/queryable/modifiers/notIn.modifier.test.js +69 -0
  158. package/interfaces/queryable/modifiers/or.modifier.test.js +142 -0
  159. package/interfaces/queryable/modifiers/select.modifier.test.js +118 -0
  160. package/interfaces/queryable/modifiers/skip.modifier.test.js +59 -0
  161. package/interfaces/queryable/modifiers/sort.modifier.test.js +160 -0
  162. package/interfaces/queryable/modifiers/startsWith.modifier.test.js +83 -0
  163. package/interfaces/queryable/modifiers/sum.modifier.test.js +68 -0
  164. package/interfaces/queryable/support/bootstrap.js +80 -0
  165. package/interfaces/queryable/support/fixtures/crud.fixture.js +54 -0
  166. package/interfaces/scalable/README.md +19 -0
  167. package/interfaces/scalable/crud.test.js +73 -0
  168. package/interfaces/scalable/queries.test.js +9 -0
  169. package/interfaces/scalable/support/crud.fixture.js +60 -0
  170. package/interfaces/semantic/create.test.js +110 -0
  171. package/interfaces/semantic/createEach.test.js +50 -0
  172. package/interfaces/semantic/destroy.js +147 -0
  173. package/interfaces/semantic/find.test.js +91 -0
  174. package/interfaces/semantic/findOne.test.js +60 -0
  175. package/interfaces/semantic/findOrCreate.test.js +91 -0
  176. package/interfaces/semantic/findOrCreateEach.test.js +75 -0
  177. package/interfaces/semantic/support/bootstrap.js +85 -0
  178. package/interfaces/semantic/support/fixtures/crud.fixture.js +66 -0
  179. package/interfaces/semantic/support/fixtures/validations.fixture.js +23 -0
  180. package/interfaces/semantic/types/array.type.js +28 -0
  181. package/interfaces/semantic/types/binary.type.js +34 -0
  182. package/interfaces/semantic/types/boolean.type.js +80 -0
  183. package/interfaces/semantic/types/date.type.js +53 -0
  184. package/interfaces/semantic/types/datetime.type.js +48 -0
  185. package/interfaces/semantic/types/float.type.js +40 -0
  186. package/interfaces/semantic/types/integer.type.js +40 -0
  187. package/interfaces/semantic/types/json.type.js +29 -0
  188. package/interfaces/semantic/types/string.type.js +40 -0
  189. package/interfaces/semantic/types/text.type.js +34 -0
  190. package/interfaces/semantic/types/time.type.js +52 -0
  191. package/interfaces/semantic/update.test.js +157 -0
  192. package/interfaces/sql/find.test.js +73 -0
  193. package/interfaces/sql/query.test.js +40 -0
  194. package/interfaces/sql/support/bootstrap.js +82 -0
  195. package/interfaces/sql/support/fixtures/crud.fixture.js +57 -0
  196. package/interfaces/transactable/commit.test.js +438 -0
  197. package/interfaces/transactable/crossAdapter.test.js +346 -0
  198. package/interfaces/transactable/deep.test.js +100 -0
  199. package/interfaces/transactable/rollback.test.js +221 -0
  200. package/interfaces/transactable/support/bootstrap.js +55 -0
  201. package/interfaces/transactable/support/bootstrapFn.js +51 -0
  202. package/interfaces/transactable/support/fixtures/customer.fixture.js +29 -0
  203. package/interfaces/transactable/support/fixtures/payment.fixture.js +24 -0
  204. package/interfaces/transactable/support/fixtures/receipt.fixture.js +20 -0
  205. package/interfaces/transactable/support/fixtures/store.fixture.js +22 -0
  206. package/interfaces/transactable/support/fixtures/storecustomer.fixture.js +14 -0
  207. package/lib/index.js +155 -0
  208. package/lib/utils.js +39 -0
  209. package/package.json +58 -4
  210. package/test/integration/README.md +26 -0
  211. package/test/integration/config/offshore-memory.js +8 -0
  212. package/test/integration/config/offshore-sql-mariadb.js +15 -0
  213. package/test/integration/config/offshore-sql-mysql.js +21 -0
  214. package/test/integration/config/offshore-sql-oracle.js +19 -0
  215. package/test/integration/config/offshore-sql-postgres.js +27 -0
  216. package/test/integration/config/offshore-sql-sqlite3.js +19 -0
  217. package/test/integration/runner.js +83 -0
  218. package/test/integration/runnerDispatcher.js +163 -0
  219. package/test/load/README.md +20 -0
  220. package/test/load/index.js +33 -0
  221. package/test/load/runner.js +160 -0
  222. package/test/load/support/bootstrap.js +69 -0
  223. package/test/load/support/fixtures/pet.js +8 -0
  224. package/test/load/support/fixtures/user.js +9 -0
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Module Dependencies
3
+ */
4
+
5
+ var bootstrapFn = require('./bootstrapFn');
6
+ var asynk = require('asynk');
7
+
8
+ /////////////////////////////////////////////////////
9
+ // TEST SETUP
10
+ ////////////////////////////////////////////////////
11
+
12
+ var offshore, ontology;
13
+
14
+ before(function(done) {
15
+
16
+ bootstrapFn(function(err, obj) {
17
+ if (err) {
18
+ console.log('Ontology loading error : ', err);
19
+ }
20
+
21
+ ontology = obj.ontology;
22
+ offshore = obj.offshore;
23
+
24
+ Object.keys(ontology.collections).forEach(function(key) {
25
+ var globalName = key.charAt(0).toUpperCase() + key.slice(1);
26
+ global.Transactable[globalName] = ontology.collections[key];
27
+ });
28
+
29
+ // Store the Offshore object as a global so it can be used in the tests
30
+ global.Transactable.offshore = offshore;
31
+
32
+ done();
33
+ });
34
+ });
35
+
36
+ after(function(done) {
37
+ function dropCollection(item, next) {
38
+ if (!Adapter.hasOwnProperty('drop')) {
39
+ return next();
40
+ }
41
+
42
+ ontology.collections[item].drop(function(err) {
43
+ if (err) {
44
+ return next(err);
45
+ }
46
+ next();
47
+ });
48
+ }
49
+ asynk.each(Object.keys(ontology.collections), dropCollection).serie().asCallback(function(err) {
50
+ if (err) {
51
+ return done(err);
52
+ }
53
+ offshore.teardown(done);
54
+ });
55
+ });
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Module Dependencies
3
+ */
4
+
5
+ var Offshore = require(process.env.offshorePath || 'offshore');
6
+ var _ = require('lodash');
7
+
8
+ // Require Fixtures
9
+ var fixtures = {
10
+ Customer: require('./fixtures/customer.fixture'),
11
+ Payment: require('./fixtures/payment.fixture'),
12
+ Receipt: require('./fixtures/receipt.fixture'),
13
+ Store: require('./fixtures/store.fixture'),
14
+ StoreCustomer: require('./fixtures/storecustomer.fixture')
15
+ };
16
+
17
+
18
+ module.exports = function(newFixtures, cb) {
19
+ if(!cb) {
20
+ cb = newFixtures;
21
+ newFixtures = undefined;
22
+ }
23
+ newFixtures = newFixtures || {};
24
+ fixtures = _.defaults(newFixtures, fixtures);
25
+
26
+ var offshore = new Offshore();
27
+
28
+ Object.keys(fixtures).forEach(function(key) {
29
+ var collection = fixtures[key];
30
+ _.keys(collection.attributes).forEach(function(attr) {
31
+ // skip collection
32
+ if (collection.attributes[attr].collection) {
33
+ return;
34
+ }
35
+ // skip functions
36
+ if (_.isFunction(collection.attributes[attr])) {
37
+ return;
38
+ }
39
+ // add columnName
40
+ collection.attributes[attr].columnName = collection.identity + _.capitalize(attr);
41
+ });
42
+ offshore.loadCollection(Offshore.Collection.extend(collection));
43
+ });
44
+ var connections = { transactable: Connections.test , transactable2: Connections.test2};
45
+
46
+ offshore.initialize({ adapters: { wl_tests: Adapter, wl_tests2: Adapter }, connections: connections }, function(err, _ontology) {
47
+ if(err) return cb(err);
48
+ cb(null, { offshore: offshore, ontology: _ontology });
49
+ });
50
+
51
+ };
@@ -0,0 +1,29 @@
1
+ module.exports = {
2
+ tableName: 'customerTrxTable',
3
+ identity: 'customer',
4
+ connection: 'transactable',
5
+ migrate: 'alter',
6
+ attributes: {
7
+ id: {
8
+ type: 'integer',
9
+ primaryKey: true,
10
+ unique: true,
11
+ autoIncrement: true
12
+ },
13
+ name: {
14
+ type: 'string'
15
+ },
16
+ capital: {
17
+ type: 'integer'
18
+ },
19
+ payments: {
20
+ collection: 'Payment',
21
+ via: 'a_customer'
22
+ },
23
+ stores:{
24
+ collection: 'store',
25
+ via: 'customer',
26
+ through: 'storecustomer'
27
+ }
28
+ }
29
+ };
@@ -0,0 +1,24 @@
1
+ module.exports = {
2
+ tableName: 'paymentTrxTable',
3
+ identity: 'payment',
4
+ connection: 'transactable2',
5
+ migrate: 'alter',
6
+ attributes: {
7
+ id: {
8
+ type: 'integer',
9
+ primaryKey: true,
10
+ unique: true,
11
+ autoIncrement: true
12
+ },
13
+ type: {
14
+ type: 'string'
15
+ },
16
+ a_customer: {
17
+ model: 'Customer'
18
+ },
19
+ receipts: {
20
+ collection: 'Receipt',
21
+ via: 'a_payment'
22
+ }
23
+ }
24
+ };
@@ -0,0 +1,20 @@
1
+ module.exports = {
2
+ tableName: 'receiptTrxTable',
3
+ identity: 'receipt',
4
+ connection: 'transactable',
5
+ migrate: 'alter',
6
+ attributes: {
7
+ id: {
8
+ type: 'integer',
9
+ primaryKey: true,
10
+ unique: true,
11
+ autoIncrement: true
12
+ },
13
+ label: {
14
+ type: 'string'
15
+ },
16
+ a_payment: {
17
+ model: 'Payment'
18
+ }
19
+ }
20
+ };
@@ -0,0 +1,22 @@
1
+ module.exports = {
2
+ tableName: 'storeTrxTable',
3
+ identity: 'store',
4
+ connection: 'transactable',
5
+ migrate: 'alter',
6
+ attributes: {
7
+ id: {
8
+ type: 'integer',
9
+ primaryKey: true,
10
+ unique: true,
11
+ autoIncrement: true
12
+ },
13
+ name: {
14
+ type: 'string'
15
+ },
16
+ customers:{
17
+ collection: 'customer',
18
+ via: 'store',
19
+ through: 'storecustomer'
20
+ }
21
+ }
22
+ };
@@ -0,0 +1,14 @@
1
+ module.exports = {
2
+ tableName: 'storeCustomerTrxTable',
3
+ identity: 'storecustomer',
4
+ connection: 'transactable',
5
+ migrate: 'alter',
6
+ attributes: {
7
+ customer:{
8
+ model:'customer'
9
+ },
10
+ store: {
11
+ model: 'store'
12
+ }
13
+ }
14
+ };
package/lib/index.js ADDED
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Dependencies
3
+ */
4
+
5
+ var Path = require('path'),
6
+ _ = require('lodash'),
7
+ utils = require('./utils'),
8
+ crossAdapterRunner = require('../features/crossAdapter/core/crossAdapter'),
9
+ mocha = require('mocha');
10
+
11
+ /**
12
+ * Test Runner
13
+ *
14
+ * @param {Object} options
15
+ * @api public
16
+ */
17
+
18
+ module.exports = function(options) {
19
+
20
+ if(!options.adapter) throw new Error('Must supply an adapter');
21
+ if(!options.interfaces) throw new Error('Must supply a list of supported interfaces');
22
+ if(!Array.isArray(options.interfaces)) throw new Error('Must supply a list of supported interfaces');
23
+
24
+ this.adapter = options.adapter;
25
+ this.config = options.config || {};
26
+ this.interfaces = options.interfaces;
27
+ this.features = _.clone(options.features || []);
28
+
29
+ // cross-adapter is a special case since it requires a clean test cache for
30
+ // running existing associations tests
31
+ var crossAdapterIndex = this.features.indexOf('crossAdapter');
32
+ if (crossAdapterIndex === -1) {
33
+ crossAdapterIndex = this.features.indexOf('cross-adapter');
34
+ }
35
+ var runCrossAdapterTests;
36
+ if(crossAdapterIndex >= 0){
37
+ this.features.splice(crossAdapterIndex, 1);
38
+ runCrossAdapterTests = true;
39
+ }
40
+
41
+ // Attach config to adapter
42
+ // this.adapter.config = this.config;
43
+ global.Connections = {
44
+ 'test': this.config,
45
+ 'test2': _.clone(this.config)
46
+ };
47
+
48
+ global.Connections.test.adapter = 'wl_tests';
49
+ global.Connections.test2.adapter = 'wl_tests2';
50
+
51
+ // Globalize Adapter
52
+ global.Adapter = this.adapter;
53
+
54
+ // Build an array of files to test
55
+ var filter = '\\.(' + ['js'].join('|') + ')$';
56
+
57
+ var files = [];
58
+
59
+ this.interfaces.forEach(function(interface) {
60
+ var interfacePath = Path.resolve(__dirname,'../interfaces/' + interface);
61
+ files = files.concat(utils.fileLookup(interfacePath, filter, true));
62
+ });
63
+
64
+ this.features.forEach(function(feature) {
65
+ var parts = feature.split('.');
66
+ if (parts.length > 2) {
67
+ throw new Error("Only one level of sub-features is supported, please use only one '.': " + feature);
68
+ }
69
+
70
+ var featurePath = Path.resolve(__dirname,'../features/' + parts[0] + '/core');
71
+ if (require('fs').existsSync(featurePath)) {
72
+ files = files.concat(utils.fileLookup(featurePath, filter, true));
73
+
74
+ if (parts.length == 2) {
75
+ featurePath = Path.resolve(__dirname,'../features/' + parts[0] + '/' + parts[1]);
76
+ files = files.concat(utils.fileLookup(featurePath, filter, true));
77
+ }
78
+ }
79
+ });
80
+
81
+ // There might be duplicate files if multiple sub-features of a single feature is being tested.
82
+ files = _.uniq(files);
83
+
84
+ // Build a Mocha Runner
85
+ var test = new mocha(_.merge({
86
+ timeout: 6000
87
+ }, options.mocha||{}));
88
+
89
+ if (options.mochaChainableMethods){
90
+ _.forEach(options.mochaChainableMethods, function(arg, method){
91
+ test[method](arg);
92
+ });
93
+ }
94
+
95
+ // Set Global Placeholders for Ontologies
96
+ global.Associations = {};
97
+ global.Semantic = {};
98
+ global.Queryable = {};
99
+ global.Migratable = {};
100
+ global.Sql = {};
101
+ global.Transactable = {};
102
+ global.adapterFeatures = this.features;
103
+
104
+ // Allow Adapter to be a global without warning about a leak
105
+ test.globals([Adapter, Connections, Associations, Semantic, Queryable, Sql, adapterFeatures]);
106
+ test.files = files;
107
+
108
+ var exit = function(err, failOnError){
109
+ if (err && failOnError) {
110
+ var exitCode = isNaN(err) ? 1 : err;
111
+ process.exit(exitCode);
112
+ } else {
113
+ process.exit(0);
114
+ }
115
+ };
116
+
117
+ console.time('time elapsed');
118
+ var runner = test.run(function(err) {
119
+ console.timeEnd('time elapsed');
120
+ if (runCrossAdapterTests){
121
+ crossAdapterRunner.cleanTestCache(test.files);
122
+ crossAdapterRunner(options, function(crossAdapterErr){
123
+ if (crossAdapterErr) {
124
+ return exit(crossAdapterErr, options.failOnError);
125
+ }
126
+ exit(err, options.failOnError);
127
+ });
128
+ } else {
129
+ exit(err, options.failOnError);
130
+ }
131
+
132
+ });
133
+
134
+ if (options.childProcess) {
135
+ runner.on('pass', function (test) {
136
+ process.send({
137
+ file: test.file,
138
+ title: test.title,
139
+ state: test.state,
140
+ duration: test.duration
141
+ });
142
+ });
143
+
144
+ runner.on('fail', function (test, error) {
145
+ console.error(test.err);
146
+ process.send({
147
+ file: test.file,
148
+ title: test.title,
149
+ state: test.state,
150
+ duration: test.duration,
151
+ err: test.err
152
+ });
153
+ });
154
+ }
155
+ };
package/lib/utils.js ADDED
@@ -0,0 +1,39 @@
1
+ var fs = require('fs'),
2
+ Path = require('path');
3
+
4
+ /**
5
+ * File Loader
6
+ *
7
+ * @param {String} path
8
+ * @param {String} filter
9
+ * @param {Boolean} recursive
10
+ * @return {Array}
11
+ */
12
+
13
+ exports.fileLookup = function fileLookup(path, filter, recursive) {
14
+ var files = [];
15
+
16
+ if (!fs.existsSync(path)) path += '.js';
17
+
18
+ // Check if path is a file or directory
19
+ var stat = fs.statSync(path);
20
+ if (stat.isFile()) return path;
21
+
22
+ fs.readdirSync(path).forEach(function(file) {
23
+ file = Path.join(path, file);
24
+
25
+ // If file is a directory, recursivly call function again
26
+ var stat = fs.statSync(file);
27
+ if (stat.isDirectory()) {
28
+ if (recursive) files = files.concat(fileLookup(file, filter, recursive));
29
+ return;
30
+ }
31
+
32
+ var re = new RegExp(filter);
33
+
34
+ if (!stat.isFile() || !re.test(file) || Path.basename(file)[0] == '.') return;
35
+ files.push(file);
36
+ });
37
+
38
+ return files;
39
+ };
package/package.json CHANGED
@@ -1,6 +1,60 @@
1
1
  {
2
2
  "name": "@na1647/offshore-adapter-tests",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "description": "Integration tests for offshore adapters",
4
+ "version": "1.2.0",
5
+ "author": {
6
+ "name": "Nicolas A.",
7
+ "email": "na164711@gmail.com",
8
+ "url": "https://github.com/na1647",
9
+ "contribution": "Added support for sequences and MariaDB (Ajout gestion des séquences et de mariadb)"
10
+ },
11
+ "contributors": [
12
+ {
13
+ "name": "Alexandre Tiertant",
14
+ "url": "https://github.com/atiertant",
15
+ "description": "Original author of the project"
16
+ }
17
+ ],
18
+ "dependencies": {
19
+ "asynk": "0.0.12",
20
+ "bluebird": "3.5.1",
21
+ "lodash": "4.17.10",
22
+ "mocha": "~5.2.0",
23
+ "offshore-memory": "~0.1.0",
24
+ "should": "13.2.1",
25
+ "offshore": "~1.0.0"
26
+ },
27
+ "devDependencies": {
28
+ "coveralls": "^3.0.0",
29
+ "eslint": "~5.0.1",
30
+ "istanbul": "0.4.5",
31
+ "jpath": "0.0.20",
32
+ "npm": "6.1.0",
33
+ "nyc": "~13.0.0",
34
+ "offshore-sql": "~1.0.0"
35
+ },
36
+ "keywords": [
37
+ "orm",
38
+ "tests",
39
+ "offshore",
40
+ "adapters",
41
+ "sql"
42
+ ],
43
+ "repository": "git+https://github.com/na1647/offshore-adapter-tests.git",
44
+ "homepage": "https://github.com/na1647/offshore-adapter-tests",
45
+ "main": "./lib/index.js",
46
+ "scripts": {
47
+ "test": "nyc node test/integration/runnerDispatcher.js",
48
+ "coveralls": "nyc report --reporter=text-lcov | coveralls",
49
+ "lint": "eslint ./",
50
+ "test-load": "node test/load",
51
+ "docker": "docker-compose run adapter bash"
52
+ },
53
+ "engines": {
54
+ "node": "*"
55
+ },
56
+ "license": "MIT",
57
+ "bugs": {
58
+ "url": "https://github.com/na1647/offshore-adapter-tests/issues/new"
59
+ }
60
+ }
@@ -0,0 +1,26 @@
1
+ Integration tests
2
+ ==========================
3
+ [![Build Status](https://travis-ci.org/balderdashy/offshore-adapter-tests.svg?branch=master)](https://travis-ci.org/balderdashy/offshore-adapter-tests)
4
+
5
+ A set of integration tests that test the official adapters against offshore core edge version: [example](https://travis-ci.org/balderdashy/offshore-adapter-tests/jobs/56168135#L1326).
6
+
7
+
8
+ ## Goals
9
+
10
+ * Detect if a change in offshore core breaks the API;
11
+ * Detect if a change in offshore-adapter-tests breaks any official adapter tests;
12
+ * Test using the edge versions of offshore core, offshore-adapter-tests and the adapters to ensure the current snapshot of all these are working together and consequently are OK to release;
13
+ * make it easier for offshore core developers to test changes against all official adapters (it's not fun to setup all these dbs and run tests 6 times).
14
+
15
+
16
+ ## What's the difference between these tests and the ones ran by the individual adapters?
17
+
18
+ The adapters are configured to run their tests against the **stable** versions of offshore core and offshore-adapter-tests. From an adapter point of view, this makes sense since the adapter is only responsible for supporting the stable versions of its dependencies. These tests run against offshore core **edge** version (latest in github) and the objective is to prevent changes in offshore core to accidently break the adapters.
19
+
20
+
21
+ ## Why not have these tests ran in offshore core builds?
22
+
23
+ These tests will likely break more often as they are dependent on the adapters themselves so there is a risk for false positives and we don't want to add noise to the offshore core builds. Still, a subset of these adapter tests has been added to offshore ([PR #896](https://github.com/balderdashy/offshore/pull/896)). It only tests offshore core against sails-memory and it constitutes a *canary test* to detect API breaks.
24
+
25
+
26
+ For more details check the following PRs: [#36](https://github.com/balderdashy/offshore-adapter-tests/pull/36), [#39](https://github.com/balderdashy/offshore-adapter-tests/pull/39).
@@ -0,0 +1,8 @@
1
+ var package = require('../../../node_modules/offshore-memory/package.json');
2
+ module.exports = {
3
+ name: 'offshore-memory',
4
+ adapter: require('../../../node_modules/offshore-memory'),
5
+ interfaces: package['offshoreAdapter'].interfaces,
6
+ features: package['offshoreAdapter'].features || [],
7
+ schema: false
8
+ };
@@ -0,0 +1,15 @@
1
+ var package = require('../../../node_modules/offshore-sql/package.json');
2
+ module.exports = {
3
+ name: 'offshore-sql (Mariadb)',
4
+ adapter: require('../../../node_modules/offshore-sql'),
5
+ interfaces: package['offshoreAdapter'].interfaces,
6
+ features: package['offshoreAdapter'].features || [],
7
+ config: {
8
+ host: process.env.MYSQL_PORT_3306_TCP_ADDR || 'localhost',
9
+ port: 3306,
10
+ user: process.env.MYSQL_ENV_MYSQL_USER || 'root',
11
+ password: process.env.MYSQL_ENV_MYSQL_PASSWORD || '',
12
+ database: process.env.MYSQL_ENV_MYSQL_DATABASE || 'offshoresql',
13
+ dbType: 'mariadb'
14
+ }
15
+ };
@@ -0,0 +1,21 @@
1
+ var package = require('../../../node_modules/offshore-sql/package.json');
2
+
3
+ // NA -> car les séquences ne sont pas gérées par mysql
4
+ var features = (package['offshoreAdapter'].features || []).filter(function(feature) {
5
+ return feature !== 'sequences';;
6
+ });
7
+
8
+ module.exports = {
9
+ name: 'offshore-sql (Mysql)',
10
+ adapter: require('../../../node_modules/offshore-sql'),
11
+ interfaces: package['offshoreAdapter'].interfaces,
12
+ features: package['offshoreAdapter'].features || [],
13
+ config: {
14
+ host: process.env.MYSQL_PORT_3306_TCP_ADDR || 'localhost',
15
+ port: 3306,
16
+ user: process.env.MYSQL_ENV_MYSQL_USER || 'root',
17
+ password: process.env.MYSQL_ENV_MYSQL_PASSWORD || '',
18
+ database: process.env.MYSQL_ENV_MYSQL_DATABASE || 'offshoresql',
19
+ dbType: 'mysql'
20
+ }
21
+ };
@@ -0,0 +1,19 @@
1
+ var package = require('../../../node_modules/offshore-sql/package.json');
2
+ var features = (package['offshoreAdapter'].features || []).filter(function(feature) {
3
+ return feature !== 'autoIncrement.sequential';
4
+ });
5
+ module.exports = {
6
+ name: 'offshore-sql (Oracle)',
7
+ adapter: require('../../../node_modules/offshore-sql'),
8
+ interfaces: package['offshoreAdapter'].interfaces,
9
+ features: features,
10
+ config: {
11
+ host: 'localhost',
12
+ port: 1521,
13
+ user: 'travis',
14
+ password: 'travis',
15
+ database: 'xe',
16
+ dbType: 'oracle',
17
+ stmtCacheSize: 0
18
+ }
19
+ };
@@ -0,0 +1,27 @@
1
+ var package = require('../../../node_modules/offshore-sql/package.json');
2
+
3
+ // Disable sequential auto-increment tests, because postgre does not behave like MySql in this case
4
+ // it does not leave gap in IDs
5
+ // var features = package['offshoreAdapter'].features;
6
+ // if(features.indexOf('autoIncrement.sequential') !== -1) {
7
+ // features.splice(features.indexOf('autoIncrement.sequential'), 1);
8
+ // }
9
+ // NA -> Remplacer par filter pour ne pas toucher le tableau initial
10
+ var features = (package['offshoreAdapter'].features || []).filter(function(feature) {
11
+ return feature !== 'autoIncrement.sequential';
12
+ });
13
+
14
+ module.exports = {
15
+ name: 'offshore-sql (PostgreSql)',
16
+ adapter: require('../../../node_modules/offshore-sql'),
17
+ interfaces: package['offshoreAdapter'].interfaces || [],
18
+ features: package['offshoreAdapter'].features || [],
19
+ config: {
20
+ host: 'localhost',
21
+ port: 5432,
22
+ user: 'postgres',
23
+ password: '',
24
+ database: 'offshorepg',
25
+ dbType: 'postgres'
26
+ }
27
+ };
@@ -0,0 +1,19 @@
1
+ var package = require('../../../node_modules/offshore-sql/package.json');
2
+ // NA -> car les séquences ne sont pas gérées par sqlite3
3
+ var features = (package['offshoreAdapter'].features || []).filter(function(feature) {
4
+ return feature !== 'sequences';;
5
+ });
6
+ module.exports = {
7
+ name: 'offshore-sql (Sqlite3)',
8
+ adapter: require('../../../node_modules/offshore-sql'),
9
+ // sqlite3 only support one thread in writing mode so can't pass transactable tests
10
+ interfaces: _.filter(package['offshoreAdapter'].interfaces, function(interface) {
11
+ return interface !== 'transactable';
12
+ }),
13
+ features: package['offshoreAdapter'].features || [],
14
+ config: {
15
+ filename: './db.sqlite',
16
+ dbType: 'sqlite3'
17
+ },
18
+ useNullAsDefault: true
19
+ };