Skip to content
This repository
Browse code

[dist test] Rename config/auth.json to test/fixtures/test-config.json…

… and update tests accordingly
  • Loading branch information...
commit 7a4baf9e50ab62135060c365a2fe110fac3c33f5 1 parent e1fe632
Charlie Robbins authored August 22, 2011
2  .gitignore
... ...
@@ -1,5 +1,4 @@
1 1
 .DS_Store
2  
-config/auth.json
3 2
 autostart/
4 3
 autostart/*
5 4
 local/
@@ -10,6 +9,7 @@ packages/
10 9
 packages/*
11 10
 tmp/
12 11
 tmp/*
  12
+test/fixtures/test-config.json
13 13
 test/data/repositories/marak-*
14 14
 test/data/repositories/nodejitsu-*
15 15
 test/data/repositories/noob-*
0  config/.gitkeep
No changes.
6  config/auth.json.example
... ...
@@ -1,6 +0,0 @@
1  
-{
2  
-  "auth": {
3  
-    "username": "test-username",
4  
-    "apiKey": "test-apiKey"
5  
-  }
6  
-}
13  test/fixtures/test-config.json.example
... ...
@@ -0,0 +1,13 @@
  1
+{
  2
+  "auth": {
  3
+    "username": "test-username",
  4
+    "apiKey": "test-apiKey"
  5
+  },
  6
+  "loggly": {
  7
+    "subdomain": "your-subdomain",
  8
+    "inputs": {
  9
+      "haibu": "your-input-token-for-haibu-logs",
  10
+      "user": "your-input-token-for-user-logs"
  11
+    }
  12
+  }
  13
+}
50  test/helpers.js
@@ -15,56 +15,50 @@ var assert = require('assert'),
15 15
     haibu = require('../lib/haibu');
16 16
 
17 17
 var helpers = exports,
18  
-    configMissing = false,
19 18
     testConfig;
20 19
 
21  
-function showConfigError () {
22  
-  if (!configMissing) {
23  
-    console.log("Config file config/auth.json doesn't have valid data. Skipping remote tests");
24  
-    configMissing = true;
  20
+function showConfigWarning (requireAuth) {
  21
+  if ((!testConfig || !testConfig.auth || 
  22
+      testConfig.auth.username === 'test-username' ||
  23
+      testConfig.auth.apiKey === 'test-apiKey') 
  24
+      && requireAuth) {
  25
+    console.log("Config file test/fixtures/test-config.json doesn't have valid data. Skipping remote tests");
  26
+    process.exit(1);
25 27
   }
26 28
 }
27 29
 
28  
-helpers.loadConfig = function () {
29  
-  //
30  
-  // TODO (olauzon) load all /config/*.json at once in parallel
31  
-  //
32  
-  var configFile = path.join(__dirname, '..', 'config', 'auth.json');
33  
-
  30
+helpers.loadConfig = function (requireAuth) {
  31
+  function showConfig () {
  32
+    showConfigWarning();
  33
+    return testConfig;
  34
+  }
  35
+  
  36
+  if (testConfig) {
  37
+    return showConfig();
  38
+  }
  39
+  
34 40
   try {
35  
-    var stats = fs.statSync(configFile),
  41
+    var configFile = path.join(__dirname, 'fixtures', 'test-config.json'),
36 42
         config = JSON.parse(fs.readFileSync(configFile).toString());
37 43
 
38  
-    if ((config.auth.username === 'test-username') ||
39  
-        (config.auth.apiKey === 'test-apiKey')) {
40  
-      return showConfigError();
41  
-    }
42  
-
43 44
     testConfig = config;
44  
-    return config;
  45
+    return showConfig();
45 46
   }
46 47
   catch (ex) {
47  
-    return showConfigError();
  48
+    return showConfig();
48 49
   }
49 50
 };
50 51
 
51  
-Object.defineProperty(helpers, 'auth', {
52  
-  get: function () {
53  
-    if (helpers.loadConfig() !== null) {
54  
-      return helpers.loadConfig().auth;
55  
-    }
56  
-  }
57  
-});
58  
-
59 52
 helpers.cleanAutostart = function (callback) {
60 53
   exec('rm -rf ' + path.join(haibu.config.get('directories:autostart'), '*'), callback);
61 54
 };
62 55
 
63 56
 helpers.init = function (callback) {
  57
+  var config = helpers.loadConfig();
64 58
   helpers.cleanAutostart(function () {
65 59
     haibu.init({ env: 'development' }, function (err) {
66 60
       haibu.use(haibu.plugins.logger, {
67  
-        loggly: haibu.config.get('loggly'),
  61
+        loggly: config.loggly || haibu.config.get('loggly'),
68 62
         console: {
69 63
           level: 'silly',
70 64
           silent: true
50  test/repositories/remote-file-test.js
@@ -15,24 +15,28 @@ var assert = require('assert'),
15 15
     RemoteFile = require('../../lib/haibu/repositories/remote-file').RemoteFile;
16 16
 
17 17
 var ipAddress = '127.0.0.1', 
18  
-    port = 9000, remoteFile,
19  
-    app = {
20  
-      "name": "test",
21  
-      "user": "marak",
22  
-      "directories": {
23  
-        "home": "hellonode"
24  
-      },
25  
-      "repository": {
26  
-        "auth": helpers.auth,
27  
-        "protocol": "cloudfiles",
28  
-        "container": "nodejitsu-apps",
29  
-        "filename": "hellonode.tar.gz",
30  
-        "type": "tar"
31  
-      },
32  
-      "scripts": {
33  
-        "start": "server.js"
34  
-      }
35  
-    };
  18
+    port = 9000, 
  19
+    config = helpers.loadConfig(true),
  20
+    remoteFile,
  21
+    app;
  22
+    
  23
+app = {
  24
+  "name": "test",
  25
+  "user": "marak",
  26
+  "directories": {
  27
+    "home": "hellonode"
  28
+  },
  29
+  "repository": {
  30
+    "auth": config.auth,
  31
+    "protocol": "cloudfiles",
  32
+    "container": "nodejitsu-apps",
  33
+    "filename": "hellonode.tar.gz",
  34
+    "type": "tar"
  35
+  },
  36
+  "scripts": {
  37
+    "start": "server.js"
  38
+  }
  39
+};
36 40
 
37 41
 var suite = vows.describe('haibu/repositories/remote-file').addBatch(
38 42
   helpers.requireInit(function () {
@@ -92,9 +96,7 @@ var suite = vows.describe('haibu/repositories/remote-file').addBatch(
92 96
   }
93 97
 });
94 98
 
95  
-if (helpers.auth) { 
96  
-  //
97  
-  // If there is no config file, we can't run the remote tests
98  
-  //
99  
-  suite.export(module);
100  
-}
  99
+//
  100
+// Export the suite to the test module
  101
+//
  102
+suite.export(module);
67  test/repositories/tar-test.js
@@ -14,32 +14,37 @@ var assert = require('assert'),
14 14
 
15 15
 var ipAddress = '127.0.0.1', 
16 16
     port = 9000, 
17  
-    httpApp = {
18  
-      "name": "test",
19  
-      "user": "marak", 
20  
-      "repository": {
21  
-        "type": "tar",
22  
-        "protocol": "http",
23  
-        "url": "http://c0027507.cdn1.cloudfiles.rackspacecloud.com/hellonode.tar.gz"
24  
-      },
25  
-      "scripts": {
26  
-        "start": "server.js"
27  
-      }
28  
-    },
29  
-    cloudfilesApp = {
30  
-      "name": "test",
31  
-      "user": "charlie",
32  
-      "repository": {
33  
-        "type": "tar",
34  
-        "protocol": "cloudfiles",
35  
-        "filename": "hellonode.tar.gz",
36  
-        "container": "nodejitsu-apps",
37  
-        "auth": helpers.auth
38  
-      },
39  
-      "scripts": {
40  
-        "start": "server.js"
41  
-      }
42  
-    };
  17
+    cloudfilesApp,
  18
+    httpApp,
  19
+    config = helpers.loadConfig(true);
  20
+    
  21
+httpApp = {
  22
+  "name": "test",
  23
+  "user": "marak", 
  24
+  "repository": {
  25
+    "type": "tar",
  26
+    "protocol": "http",
  27
+    "url": "http://c0027507.cdn1.cloudfiles.rackspacecloud.com/hellonode.tar.gz"
  28
+  },
  29
+  "scripts": {
  30
+    "start": "server.js"
  31
+  }
  32
+};
  33
+
  34
+cloudfilesApp = {
  35
+  "name": "test",
  36
+  "user": "charlie",
  37
+  "repository": {
  38
+    "type": "tar",
  39
+    "protocol": "cloudfiles",
  40
+    "filename": "hellonode.tar.gz",
  41
+    "container": "nodejitsu-apps",
  42
+    "auth": config.auth
  43
+  },
  44
+  "scripts": {
  45
+    "start": "server.js"
  46
+  }
  47
+};
43 48
 
44 49
 // Create the vows test suite
45 50
 var suite = vows.describe('haibu/repositories/tar').addBatch(helpers.requireInit());
@@ -86,9 +91,7 @@ var suite = vows.describe('haibu/repositories/tar').addBatch(helpers.requireInit
86 91
   suite.addBatch(batch);
87 92
 });
88 93
 
89  
-if (helpers.auth) { 
90  
-  //
91  
-  // If there is no config file, we can't run the remote tests
92  
-  //
93  
-  suite.export(module);
94  
-}
  94
+//
  95
+// Export the suite to the test module
  96
+//
  97
+suite.export(module);
57  test/repositories/zip-test.js
@@ -14,32 +14,37 @@ var assert = require('assert'),
14 14
 
15 15
 var ipAddress = '127.0.0.1',
16 16
     port = 9000,
17  
-    httpApp = {
18  
-      "name": "test",
19  
-      "user": "marak",
20  
-      "repository": {
21  
-        "type": "zip",
22  
-        "protocol": "http",
23  
-        "url": "http://c0027507.cdn1.cloudfiles.rackspacecloud.com/hellonode.zip"
24  
-      },
25  
-      "scripts": {
26  
-        "start": "server.js"
27  
-      }
28  
-    },
29  
-    cloudfilesApp = {
30  
-      "name": "test",
31  
-      "user": "charlie",
32  
-      "repository": {
33  
-        "type": "zip",
34  
-        "protocol": "cloudfiles",
35  
-        "filename": "hellonode.zip",
36  
-        "container": "nodejitsu-apps",
37  
-        "auth": helpers.auth
38  
-      },
39  
-      "scripts": {
40  
-        "start": "server.js"
41  
-      }
42  
-    };
  17
+    config = helpers.loadConfig(true),
  18
+    cloudfilesApp,
  19
+    httpApp;
  20
+    
  21
+httpApp = {
  22
+  "name": "test",
  23
+  "user": "marak",
  24
+  "repository": {
  25
+    "type": "zip",
  26
+    "protocol": "http",
  27
+    "url": "http://c0027507.cdn1.cloudfiles.rackspacecloud.com/hellonode.zip"
  28
+  },
  29
+  "scripts": {
  30
+    "start": "server.js"
  31
+  }
  32
+};
  33
+
  34
+cloudfilesApp = {
  35
+  "name": "test",
  36
+  "user": "charlie",
  37
+  "repository": {
  38
+    "type": "zip",
  39
+    "protocol": "cloudfiles",
  40
+    "filename": "hellonode.zip",
  41
+    "container": "nodejitsu-apps",
  42
+    "auth": config.auth
  43
+  },
  44
+  "scripts": {
  45
+    "start": "server.js"
  46
+  }
  47
+};
43 48
 
44 49
 // Create the vows test suite
45 50
 var suite = vows.describe('haibu/repositories/zip').addBatch(

0 notes on commit 7a4baf9

Please sign in to comment.
Something went wrong with that request. Please try again.