Skip to content

Commit e8094ea

Browse files
author
Ilya Radchenko
committed
Merge pull request #27 from saraf/unit
Running Test from Configure project page crashes
2 parents 1e5a808 + f9ef527 commit e8094ea

File tree

3 files changed

+71
-18
lines changed

3 files changed

+71
-18
lines changed

lib/webapp.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ module.exports = {
4848
var uri = util.format('projects/%d/repository/blobs/%s?filepath=%s', repo_id, branch, filename);
4949

5050
api.get(account.config, uri, function (err, data, res) {
51-
done(err, res.text);
51+
if(err) {
52+
return done(err, null);
53+
}
54+
else {
55+
done(err, res.text);
56+
}
5257
});
5358
},
5459

test/mocks/gitlab_webapp_getfile.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,21 @@ module.exports = function () {
3333
'x-runtime': '0.013665',
3434
'content-encoding': 'gzip'
3535
});
36+
37+
//--------------------------------------------------------------------------------------
38+
//Simulate a scenario where the project does not contain a strider.json
39+
//For this purpose we have added another project named priproject2 with id 8
40+
nock('http://localhost:80')
41+
.get('/api/v3/projects/8/repository/blobs/master')
42+
.query({"private_token":"zRtVsmeznn7ySatTrnrp","per_page":"100","filepath":"strider.json"})
43+
.reply(404, ["1f8b0800000000000003ab56ca4d2d2e4e4c4f55b2523231305170cbcc4955f0cb2f5170cb2fcd4b51aa0500db72e71020000000"], { server: 'nginx',
44+
date: 'Mon, 24 Aug 2015 06:28:17 GMT',
45+
'content-type': 'application/json',
46+
'transfer-encoding': 'chunked',
47+
connection: 'close',
48+
status: '404 Not Found',
49+
'cache-control': 'no-cache',
50+
'x-request-id': '9e221d4c-9109-4291-929b-2e7cb1e4f057',
51+
'x-runtime': '0.022119',
52+
'content-encoding': 'gzip' });
3653
};

test/test_webapp.js

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ var providerConfig = {
4949
auth: {type: 'ssh'}
5050
};
5151

52+
var providerConfigForProjectWithMissingStriderJson =
53+
{ whitelist: [],
54+
pull_requests: 'none',
55+
repo: 'http://nodev/stridertester/priproject2',
56+
owner:
57+
{ avatar_url: 'http://www.gravatar.com/avatar/3f671ed86ed3d21ed3640c7a016b0997?s=40&d=identicon',
58+
state: 'active',
59+
id: 3,
60+
username: 'stridertester',
61+
name: 'Strider Tester' },
62+
url: 'git@nodev:stridertester/priproject2.git',
63+
scm: 'git',
64+
auth: { type: 'ssh' }
65+
};
66+
5267
var repoProject = {
5368
name: 'stridertester/privproject1',
5469
display_name: 'stridertester/privproject1',
@@ -127,35 +142,51 @@ describe('gitlab webapp', function () {
127142
nock.cleanAll();
128143
});
129144

145+
var filename = "strider.json";
130146

131-
it('should get a json file correctly', function (done) {
132-
var filename = "strider.json";
147+
var ref = {
148+
branch: 'master',
149+
};
133150

134-
var ref = {
135-
branch: 'master',
136-
};
151+
//getFile only uses account.config
152+
var account = {
153+
config: {
154+
api_key: 'zRtVsmeznn7ySatTrnrp',
155+
api_url: 'http://localhost:80/api/v3'
156+
}
157+
};
137158

138-
//getFile only uses account.config
139-
var account = {
140-
config: {
141-
api_key: 'zRtVsmeznn7ySatTrnrp',
142-
api_url: 'http://localhost:80/api/v3'
143-
}
144-
};
145159

160+
//getFile only uses project.provider.repo_id
161+
var project = {
162+
provider: {
163+
repo_id: '5'
164+
}
165+
};
146166

147-
//getFile only uses project.provider.repo_id
148-
var project = {
149-
provider: {
150-
repo_id: '5',
151-
}
167+
//project with strider.json missing
168+
var projectWithMissingStriderJson ={
169+
provider: {
170+
repo_id: '8'
152171
}
172+
};
173+
153174

175+
it('should get a json file correctly', function (done) {
154176
webapp.getFile(filename, ref, account, providerConfig, project, function (err, text) {
155177
expect(text).to.be.a('string');
156178
done();
157179
});
158180
});
181+
182+
//created a project priproject2 of type node.js, but not having a strider.json for this test
183+
it('should not crash, but return an error if the file could not be found', function(done) {
184+
webapp.getFile(filename, ref, account, providerConfigForProjectWithMissingStriderJson, projectWithMissingStriderJson, function (err, text) {
185+
expect(err).to.be.ok();
186+
expect(text).to.not.be.ok();
187+
done();
188+
});
189+
});
159190
});
160191

161192
//--------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)