Move to a modern testing infrastructure#304
Move to a modern testing infrastructure#304ishitatsuyuki wants to merge 4 commits intoJanitorTechnology:masterfrom
Conversation
test/api.js
Outdated
| @@ -0,0 +1,173 @@ | |||
| /* eslint-disable node/no-unsupported-features */ | |||
| // Copyright © 2017 Jan Keromnes. All rights reserved. | |||
There was a problem hiding this comment.
@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.)
472961a to
e1a7a60
Compare
|
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. |
jankeromnes
left a comment
There was a problem hiding this comment.
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! 👍
| 'in a given Docker container.', | ||
| 'List all files that were modified (Kind: 0), added (1) or deleted (2) ' + | ||
| 'in a given Docker container.', | ||
|
|
There was a problem hiding this comment.
Nit: Please re-indent these two lines.
app.js
Outdated
| boot.forwardHttp(), | ||
| boot.ensureHttpsCertificates(), | ||
| boot.ensureDockerTlsCertificates() | ||
| ]).then(() => { |
There was a problem hiding this comment.
Nit: Please .catch(error => { log('[fail] could not start app', error); }) at the bottom.
| boot.ensureDockerTlsCertificates(), | ||
| boot.verifyJanitorOAuth2Access() | ||
| ]) | ||
| .then(() => boot.registerDockerClient()) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Maybe remove the line break like so: ]).then(?
lib/boot.js
Outdated
|
|
||
| const fs = require('fs'); | ||
| const http = require('http'); | ||
| const {promisify} = require('util'); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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
| log('[fail] could not read docker-tls certificates', error); | ||
| return; | ||
| } | ||
| throw error; |
There was a problem hiding this comment.
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.
|
|
||
| if (!caValid) { | ||
| resetAllCertificates(); | ||
| await resetAllCertificates(); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
It looks like the logic is a bit complex here; please forgive me to keep the original structure.
There was a problem hiding this comment.
Ok sure, this can be done in a follow-up.
lib/boot.js
Outdated
|
|
||
| clientValid = certificates.isValid({ | ||
| ca: [ ca.crt ], | ||
| ca: [ca.crt], |
868e66e to
0136bf6
Compare
jankeromnes
left a comment
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
I'll add an eslint rule for this :)
| boot.ensureDockerTlsCertificates(), | ||
| boot.verifyJanitorOAuth2Access() | ||
| ]) | ||
| .then(() => boot.registerDockerClient()) |
There was a problem hiding this comment.
Maybe remove the line break like so: ]).then(?
.eslintrc.js
Outdated
| "no-var": "error", | ||
| "prefer-const": "error", | ||
| "array-bracket-spacing": ["error", "always", {"objectsInArrays": false}], | ||
| "object-curly-spacing": ["error", "always"], |
There was a problem hiding this comment.
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); }) |
There was a problem hiding this comment.
Nit: Please remove the above line break like so: ]).catch(error => {.
| const fs = require('fs'); | ||
| const http = require('http'); | ||
| const { promisify } = require('util'); | ||
| const chmod = promisify(fs.chmod); |
There was a problem hiding this comment.
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(() => { |
There was a problem hiding this comment.
Nit: Please rebase your pull request. This function no longer exists.
| return; | ||
| } | ||
|
|
||
| docker.removeContainer({ host, container: containerId }, () => { |
There was a problem hiding this comment.
Nit: Shouldn't you use .then and .catch here, instead of sending 3 arguments to docker.removeContainer() ?
lib/machines.js
Outdated
|
|
||
| log('destroy', containerId.slice(0, 16), 'success'); | ||
| callback(); | ||
| }, (error) => { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Nit: Please rebase. This function no longer exists.
| const buffer = Buffer.concat(chunks); | ||
| const container = docker.getContainer(containerId); | ||
|
|
||
| resolve(await container.putArchive(buffer, { path })); |
There was a problem hiding this comment.
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.
Migrated to Jest, promisified things.