Skip to content

Commit c33ae73

Browse files
committed
Expanded testing to cover host configuration with an object.
- added app1.3 - identical to app1 but using host, staging_host and development_host configuration with an object. - expanded and refactored versioning testing. - modified bucket switching script to work with new package.json format.
1 parent b6aba88 commit c33ae73

File tree

11 files changed

+730
-273
lines changed

11 files changed

+730
-273
lines changed

scripts/set-bucket.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,32 @@ dirs.forEach((dir) => {
1818
const pkg = require(`${root}/${dir}/package.json`); // relative path
1919

2020
// bucket specified as part of s3 virtual host format (auto detected by node-pre-gyp)
21-
const keys = ['host', 'staging_host', 'production_host'];
21+
const keys = ['host', 'development_host', 'staging_host', 'production_host'];
2222
keys.forEach((item) => {
23-
if (pkg.binary[item]) {
24-
23+
// hosts may be specified as strings (old format)
24+
if (pkg.binary[item] && typeof pkg.binary[item] === 'string') {
2525
// match the bucket part of the url
2626
const match = pkg.binary[item].match(/^https:\/\/(.+)(?:\.s3[-.].*)$/i);
2727
if (match) {
2828
pkg.binary[item] = pkg.binary[item].replace(match[1], bucket);
2929
console.log(`Success: set ${dir} ${item} to ${pkg.binary[item]}`);
3030
}
3131
}
32+
33+
if (pkg.binary[item] && typeof pkg.binary[item] === 'object') {
34+
// match the bucket part of the url
35+
const match = pkg.binary[item].endpoint.match(/^https:\/\/(.+)(?:\.s3[-.].*)$/i);
36+
if (match) {
37+
pkg.binary[item].endpoint = pkg.binary[item].endpoint.replace(match[1], bucket);
38+
console.log(`Success: set ${dir} ${item} to ${pkg.binary[item]}`);
39+
}
40+
if (pkg.binary[item].bucket) {
41+
pkg.binary[item].bucket = bucket;
42+
console.log(`Set ${dir} bucket to ${pkg.binary[item].bucket}`);
43+
}
44+
}
3245
});
33-
// bucket is specified explicitly
46+
// bucket may be specified explicitly on binary ()old format
3447
if (pkg.binary.bucket) {
3548
pkg.binary.bucket = bucket;
3649
console.log(`Set ${dir} bucket to ${pkg.binary.bucket}`);

test/app1.1/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Test app
22

33
Demonstrates a simple configuration that uses node-pre-gyp.
4-
Identical to app1 but using production and staging binary host option.
4+
Identical to app1 but using production and staging binary host option as string (legacy)

test/app1.2/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Test app
22

33
Demonstrates a simple configuration that uses node-pre-gyp.
4-
Identical to app1 but using explicit host, region, bucket options.
4+
Identical to app1 but using explicit host, region, bucket options defined on the binary (legacy).

test/app1.3/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
build/
3+
lib/binding/
4+
node_modules
5+
npm-debug.log

test/app1.3/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Test app
2+
3+
Demonstrates a simple configuration that uses node-pre-gyp.
4+
Identical to app1 but using host, staging_host and development_host configuration with an object.

test/app1.3/app1.3.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <napi.h>
2+
3+
Napi::Value get_hello(Napi::CallbackInfo const& info) {
4+
Napi::Env env = info.Env();
5+
Napi::EscapableHandleScope scope(env);
6+
return scope.Escape(Napi::String::New(env, "hello"));
7+
}
8+
9+
Napi::Object start(Napi::Env env, Napi::Object exports) {
10+
exports.Set("hello", Napi::Function::New(env, get_hello));
11+
return exports;
12+
}
13+
14+
NODE_API_MODULE(app1, start)

test/app1.3/binding.gyp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"targets": [
3+
{
4+
"target_name": "<(module_name)",
5+
"sources": [ "<(module_name).cc" ],
6+
'product_dir': '<(module_path)',
7+
'include_dirs': ["../../node_modules/node-addon-api/"],
8+
'cflags!': [ '-fno-exceptions' ],
9+
'cflags_cc!': [ '-fno-exceptions' ],
10+
"xcode_settings": {
11+
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
12+
"CLANG_CXX_LIBRARY": "libc++"
13+
},
14+
'msvs_settings': {
15+
'VCCLCompilerTool': { 'ExceptionHandling': 1 },
16+
}
17+
}
18+
]
19+
}

test/app1.3/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var binary = require('node-pre-gyp');
2+
var path = require('path')
3+
var binding_path = binary.find(path.resolve(path.join(__dirname,'./package.json')));
4+
var binding = require(binding_path);
5+
6+
require('assert').equal(binding.hello(),"hello");

test/app1.3/package.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "node-pre-gyp-test-app1.3",
3+
"author": "Dane Springmeyer <springmeyer>",
4+
"description": "node-pre-gyp test",
5+
"repository": {
6+
"type": "git",
7+
"url": "git://github.com/mapbox/node-pre-gyp.git"
8+
},
9+
"license": "BSD-3-Clause",
10+
"version": "0.1.0",
11+
"main": "./index.js",
12+
"binary": {
13+
"module_name": "app1.3",
14+
"module_path": "./lib/binding/",
15+
"host": {
16+
"endpoint": "https://s3.us-east-1.amazonaws.com",
17+
"bucket": "npg-mock-bucket",
18+
"region": "us-east-1",
19+
"s3ForcePathStyle": true
20+
},
21+
"staging_host": {
22+
"endpoint": "https://s3.us-east-1.amazonaws.com",
23+
"bucket": "npg-mock-bucket",
24+
"region": "us-east-1",
25+
"s3ForcePathStyle": true
26+
},
27+
"development_host": {
28+
"endpoint": "https://s3.us-east-1.amazonaws.com",
29+
"bucket": "npg-mock-bucket",
30+
"region": "us-east-1",
31+
"s3ForcePathStyle": true
32+
},
33+
"remote_path": "./node-pre-gyp/{name}/v{version}/{configuration}/{toolset}/",
34+
"package_name": "{node_abi}-{platform}-{arch}.tar.gz"
35+
},
36+
"scripts": {
37+
"install": "node-pre-gyp install --fallback-to-build",
38+
"test": "node index.js"
39+
}
40+
}

test/s3.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ const apps = [
3636
'base': ['binding/app1.2.node']
3737
}
3838
},
39+
{
40+
'name': 'app1.3',
41+
'args': '',
42+
'files': {
43+
'base': ['binding/app1.3.node']
44+
}
45+
},
3946
{
4047
'name': 'app2',
4148
'args': '--custom_include_path=../include --debug',

0 commit comments

Comments
 (0)