Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hhvm] #1499 - update hhvm service #1508

Merged
merged 9 commits into from
Feb 19, 2018
Merged

Conversation

bkdotcom
Copy link
Contributor

@shields-ci
Copy link

shields-ci commented Feb 16, 2018

Messages
📖

✨ Thanks for your contribution to Shields, @bkdotcom!

Generated by 🚫 dangerJS

@chris48s
Copy link
Member

Thanks for submitting a PR for this. I'll submit comments for review shortly

Copy link
Member

@chris48s chris48s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left a few minor inline comments.

Additionally, could you possibly add a small test suite for your code. This will help to verify that the code works correctly and will hopefully allow an error like the one you've reported in #1499 to be flagged up earlier in future.

A minimal test suite for this badge should cover the following cases:

  • expected behaviour
  • package not found
  • connection error
  • unexpected response

There is documentation on writing tests in https://github.com/badges/shields/blob/master/service-tests/README.md but something like https://github.com/badges/shields/blob/master/service-tests/requires.js or https://github.com/badges/shields/blob/master/service-tests/shippable.js would be a good example to crib from for this badge.

If you create your tests in a file called hhvm.js, edit your PR title to something like "[hhvm] my pull request title" and Circle CI will run the tests for that service when you push additional commits.

Thanks again.

server.js Outdated
var verInfo = {};
for (var i = 0, count = data.versions.length; i < count; i++) {
verInfo = data.versions[i];
if (verInfo.name == branch) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use a strict comparison here please (triple equals)

server.js Outdated
verInfo = data.versions[i];
if (verInfo.name == branch) {
switch (verInfo.travis.hhvm) {
case 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This switch statement would be easier to read if the cases were indented by a block (sorry to leave feedback on indenting :( this should really be picked up by a linting rule!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do (I copy/pasted a switch statement from elsewhere in the code)

server.js Outdated
// Remove the leading slash.
apiUrl += '?branch=' + branch.slice(1);
}
var apiUrl = 'https://php-eye.com/api/v1/package/'+user+'.json';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update the variable declarations to use the ES6 style let and const as applicable while you're working on this code.

@bkdotcom
Copy link
Contributor Author

I'll create some tests asap when I actually have time to get the environment up and running... so far the edits were simply done on github.com

@bkdotcom bkdotcom changed the title #1499 - update hhvm service [hhvm] #1499 - update hhvm service Feb 16, 2018
Copy link
Member

@chris48s chris48s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. Thanks for adding tests. This is shaping up nicely. I've left a few more comments about the tests but I think we're fairly close to a final check and getting this merged :)


t.create('invalid package name')
.get('/frodo/is-not-a-package.json')
.expectJSON({ name: 'hhvm', value: 'invalid' });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'invalid' label should be used when there is a problem generating the response (e.g: the json response could not be parsed). There is a handy fixture you can import using const { invalidJSON } = require('./helpers/response-fixtures'); which allows you to mock an invalid response like this

t.create('cdnjs (unexpected response)')
.get('/v/jquery.json')
.intercept(nock => nock('https://api.cdnjs.com')
.get('/libraries/jquery?fields=version')
.reply(invalidJSON)
)
.expectJSON({name: 'cdnjs', value: 'invalid'});

In the case where the package or branch is not found, we should return a 'not found' rather than 'invalid'. It looks like where the repo is not found, php-eye returns a 404: https://php-eye.com/api/v1/package/frodo/not-a-package.json This is the most common case so we have a handler for it checkErrorResponse which can be used like this

shields/server.js

Lines 6157 to 6160 in 75503ec

if (checkErrorResponse(badgeData, err, res, 'repo not found')) {
sendBadge(format, badgeData);
return;
}
In this case, it would also be helpful to have distinct 'repo not found'/'package not found' and 'branch not found' messages.

checkErrorResponse will also handle the 'inaccessible' case, so you can remove the if (err != null) ... block and replace with a block like the one above.


t.create('get symfony status (default branch - not tested)')
.get('/symfony/symfony.json')
.expectJSONTypes(Joi.object().keys({ name: 'hhvm', value: 'not tested' }));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit of project convention: We use .expectJSON() if we're comparing the response to an object literal and .expectJSONTypes() if we're checking the type of the response keys or validating against a regex.


t.create('gets yii 1.1.19 status')
.get('/yiisoft/yii/1.1.19.json')
.expectJSON({ name: 'hhvm', value: 'partially tested' });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit concerned that these tests may be a bit brittle or tied to particular projects. I also initially found the way the service tests are done on this project a bit confusing (there's some good discussion on it in this issue. It can be a bit tricky when your tests depend on external services but the sweet spot we're aiming for is that we want the tests to fail if php-eye change their JSON format or move their endpoint, but the tests shouldn't tell us the service integration is broken if Yii framework decide to change their approach to testing on HHVM, for example.

I'd suggest that the valid test cases (with/without branch) should just check against a regex like /^(tested|partially tested|not tested|maybe untested)$/. If you also want to test the logic that leads to particular responses, you could use a test with a mocked response like this one:

t.create('homebrew (valid, mocked response)')
.get('/v/cake.json')
.intercept(nock => nock('http://formulae.brew.sh')
.get('/formula/cake/version')
.reply(200, {stable: '0.23.0', devel: null, head: null})
)
.expectJSON({name: 'homebrew', value: 'v0.23.0'});
so it is less brittle.

How does that sound?

better tests:  including invalidJSON fixture
@bkdotcom
Copy link
Contributor Author

@chris48s thanks for the feedback, I believe I've incorporated all of your suggestions

Copy link
Member

@chris48s chris48s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thanks very much. I think this is good to merge but one of the maintainers will need to take it over the line.

@RedSparr0w
Copy link
Member

Thanks for contributing, changes look good to me.
Merged!

Thanks for reviewing @chris48s 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants