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

Move to a modern testing infrastructure #304

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ishitatsuyuki
Copy link
Contributor

@ishitatsuyuki ishitatsuyuki commented Mar 21, 2018

Migrated to Jest, promisified things.

test/api.js Outdated
@@ -0,0 +1,173 @@
/* eslint-disable node/no-unsupported-features */
// Copyright © 2017 Jan Keromnes. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

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

@ishitatsuyuki Nit: year++ (2018). Also, feel welcome to add your name/identifier here if you want.
@jankeromnes Do you think we should generalize this to the Janitor team? (ie: Copyright (c) 2018 Team Janitor. All rights reserved.)

@ishitatsuyuki
Copy link
Contributor Author

One thing I'd like to mention is that I'm now just throwing unhandled promise rejection around for the boot process. I know that this should be fixed but I'm not sure which style is best.

Copy link
Member

@jankeromnes jankeromnes left a comment

Choose a reason for hiding this comment

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

Wow, thanks a lot for singlehandedly refactoring lib/boot.js, lib/docker.js, lib/machines.js and lib/certificates.js! I'm impressed.

I'm the future, please separate such refactoring into separate pull requests, but I think this was much needed and modernizes our code base a lot. So, again, thanks! 👍

'List all files that were modified (Kind: 0), added (1) or deleted (2) ' +
'in a given Docker container.',
'List all files that were modified (Kind: 0), added (1) or deleted (2) ' +
'in a given Docker container.',

Copy link
Member

Choose a reason for hiding this comment

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

Nit: Please re-indent these two lines.

app.js Outdated
boot.forwardHttp(),
boot.ensureHttpsCertificates(),
boot.ensureDockerTlsCertificates()
]).then(() => {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Please .catch(error => { log('[fail] could not start app', error); }) at the bottom.

boot.ensureDockerTlsCertificates(),
boot.verifyJanitorOAuth2Access()
])
.then(() => boot.registerDockerClient())
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I don't really like the line break before this line, but I'm not sure what coding style would look better. @nt1m would you have any suggestions here?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe remove the line break like so: ]).then(?

lib/boot.js Outdated
@@ -3,6 +3,10 @@

const fs = require('fs');
const http = require('http');
const {promisify} = require('util');
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Please add spaces within the brackets around promisify. Also, if ESLint doesn't complain about this, please look into enforcing this rule.

lib/boot.js Outdated
next();
});
const listen = promisify(forwarder.listen);
return listen.call(forwarder, ports.http);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: You lost a log along the way. Please add it back in a .then(() => {}) here.

lib/boot.js Outdated
https.ca = [ certificate.ca ];
return certificates.createHTTPSCertificate(parameters)
.then(({certificate, accountKey}) => {
https.ca = [certificate.ca];
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Please add back spaces within brackets and parents, or please champion a new coding style to be used consistently in the entire codebase (and please enforce whatever option you choose via eslint).

lib/boot.js Outdated
}
throw error;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Please only throw when the error isn't a ENOENT (otherwise you'll never be able to successfully start a server for the first time). Also, in general, please never change the code behavior while refactoring.

@@ -142,42 +120,41 @@ exports.ensureDockerTlsCertificates = function (next) {
let serverValid = false;

if (!caValid) {
resetAllCertificates();
await resetAllCertificates();
Copy link
Member

Choose a reason for hiding this comment

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

Nit: These function definitions inside a function were written because there was no async/await at the time. I think now you could just check for what's missing with if statements, and just await asynchronous stuff when necessary (removing functions like resetAllCertificates).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like the logic is a bit complex here; please forgive me to keep the original structure.

Copy link
Member

Choose a reason for hiding this comment

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

Ok sure, this can be done in a follow-up.

lib/boot.js Outdated
return;
}

clientValid = certificates.isValid({
ca: [ ca.crt ],
ca: [ca.crt],
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Please don't.

Copy link
Member

@jankeromnes jankeromnes left a comment

Choose a reason for hiding this comment

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

Another fresh batch of comments!

Thanks again for all the hard work! But unfortunately, refactoring large portions of the code base in the same pull request as another change makes for very long, painful and numerous review cycles.

In the future, please refactor files one by one, in dedicated pull requests. This should make the whole process faster and easier for everyone. 😄

join.js Outdated
boot.verifyJanitorOAuth2Access()
])
.then(() => boot.registerDockerClient())
.catch((err) => log('[fail] could not join cluster', err))
Copy link
Member

Choose a reason for hiding this comment

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

Nit: No need for parentheses around err. Also, please use the complete word error (it doesn't cost much, so we tend to use full words in this codebase).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add an eslint rule for this :)

boot.ensureDockerTlsCertificates(),
boot.verifyJanitorOAuth2Access()
])
.then(() => boot.registerDockerClient())
Copy link
Member

Choose a reason for hiding this comment

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

Maybe remove the line break like so: ]).then(?

.eslintrc.js Outdated
@@ -19,6 +19,8 @@ module.exports = {
"camelcase": "off",
"no-var": "error",
"prefer-const": "error",
"array-bracket-spacing": ["error", "always", {"objectsInArrays": false}],
"object-curly-spacing": ["error", "always"],
Copy link
Member

Choose a reason for hiding this comment

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

Thanks! But nit: Please respect this style in .eslintrc.js itself as well (by adding spaces inside your []).

boot.ensureHttpsCertificates(),
boot.ensureDockerTlsCertificates()
])
.catch(error => { log('[fail] could not start app', error); })
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Please remove the above line break like so: ]).catch(error => {.

@@ -3,6 +3,10 @@

const fs = require('fs');
const http = require('http');
const { promisify } = require('util');
const chmod = promisify(fs.chmod);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Please separate imports of different types into different blocks (i.e. here, please separate the require() and the promisify() blocks by an empty line).

lib/machines.js Outdated
db.save();
});
// Quickly authorize the user's public SSH keys to access this container.
deploySSHAuthorizedKeys(user, machine).then(() => {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Please rebase your pull request. This function no longer exists.

return;
}

docker.removeContainer({ host, container: containerId }, () => {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Shouldn't you use .then and .catch here, instead of sending 3 arguments to docker.removeContainer() ?

lib/machines.js Outdated
// Recycle the machine's name and ports.
machine.status = 'new';
machine.docker.container = '';
db.save();

log('destroy', containerId.slice(0, 16), 'success');
callback();
}, (error) => {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Please use catch and remove the extra parentheses.

lib/machines.js Outdated
});
};

// Reset a user machine's list of authorized SSH public keys.
function deploySSHAuthorizedKeys (user, machine, callback) {
async function deploySSHAuthorizedKeys (user, machine) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Please rebase. This function no longer exists.

const buffer = Buffer.concat(chunks);
const container = docker.getContainer(containerId);

resolve(await container.putArchive(buffer, { path }));
Copy link
Member

Choose a reason for hiding this comment

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

Nit: No need to mark this callback as async, because you don't need to await here (you can just resolve the Promise with another Promise and it should just work, also this probably removes the need for the try/catch).

Use Jest as test framework, and restructured ESLint config files so it applies to each directory separately.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants