move nock to setup and teardown

This commit is contained in:
Alif Rachmawadi 2019-08-17 14:06:24 +07:00
parent b148f5000d
commit da6a33ef99
No known key found for this signature in database
GPG key ID: 79DA63C0F3A55BB1

View file

@ -41,53 +41,54 @@ describe('installer tests', () => {
} }
}, 100000); }, 100000);
it('Acquires latest release version of go 1.10 if using 1.10 and no matching version is installed', async () => { describe('the latest release of a go version', () => {
nock('https://api.github.com') beforeEach(() => {
.get('/repos/golang/go/git/refs/tags') nock('https://api.github.com')
.replyWithFile(200, path.join(dataDir, 'golang-tags.json')); .get('/repos/golang/go/git/refs/tags')
.replyWithFile(200, path.join(dataDir, 'golang-tags.json'));
});
await installer.getGo('1.10'); afterEach(() => {
const goDir = path.join(toolDir, 'go', '1.10.8', os.arch()); nock.cleanAll();
nock.enableNetConnect();
});
expect(fs.existsSync(`${goDir}.complete`)).toBe(true); it('Acquires latest release version of go 1.10 if using 1.10 and no matching version is installed', async () => {
if (IS_WINDOWS) { await installer.getGo('1.10');
expect(fs.existsSync(path.join(goDir, 'bin', 'go.exe'))).toBe(true); const goDir = path.join(toolDir, 'go', '1.10.8', os.arch());
} else {
expect(fs.existsSync(path.join(goDir, 'bin', 'go'))).toBe(true);
}
}, 100000);
it('Acquires latest release version of go 1.10 if using 1.10.x and no matching version is installed', async () => { expect(fs.existsSync(`${goDir}.complete`)).toBe(true);
nock('https://api.github.com') if (IS_WINDOWS) {
.get('/repos/golang/go/git/refs/tags') expect(fs.existsSync(path.join(goDir, 'bin', 'go.exe'))).toBe(true);
.replyWithFile(200, path.join(dataDir, 'golang-tags.json')); } else {
expect(fs.existsSync(path.join(goDir, 'bin', 'go'))).toBe(true);
}
}, 100000);
await installer.getGo('1.10.x'); it('Acquires latest release version of go 1.10 if using 1.10.x and no matching version is installed', async () => {
const goDir = path.join(toolDir, 'go', '1.10.8', os.arch()); await installer.getGo('1.10.x');
const goDir = path.join(toolDir, 'go', '1.10.8', os.arch());
expect(fs.existsSync(`${goDir}.complete`)).toBe(true); expect(fs.existsSync(`${goDir}.complete`)).toBe(true);
if (IS_WINDOWS) { if (IS_WINDOWS) {
expect(fs.existsSync(path.join(goDir, 'bin', 'go.exe'))).toBe(true); expect(fs.existsSync(path.join(goDir, 'bin', 'go.exe'))).toBe(true);
} else { } else {
expect(fs.existsSync(path.join(goDir, 'bin', 'go'))).toBe(true); expect(fs.existsSync(path.join(goDir, 'bin', 'go'))).toBe(true);
} }
}, 100000); }, 100000);
it('Acquires latest release version of go if using 1.x and no matching version is installed', async () => { it('Acquires latest release version of go if using 1.x and no matching version is installed', async () => {
nock('https://api.github.com') await installer.getGo('1.x');
.get('/repos/golang/go/git/refs/tags') const goDir = path.join(toolDir, 'go', '1.13.0-beta1', os.arch());
.replyWithFile(200, path.join(dataDir, 'golang-tags.json'));
await installer.getGo('1.x'); expect(fs.existsSync(`${goDir}.complete`)).toBe(true);
const goDir = path.join(toolDir, 'go', '1.13.0-beta1', os.arch()); if (IS_WINDOWS) {
expect(fs.existsSync(path.join(goDir, 'bin', 'go.exe'))).toBe(true);
expect(fs.existsSync(`${goDir}.complete`)).toBe(true); } else {
if (IS_WINDOWS) { expect(fs.existsSync(path.join(goDir, 'bin', 'go'))).toBe(true);
expect(fs.existsSync(path.join(goDir, 'bin', 'go.exe'))).toBe(true); }
} else { }, 100000);
expect(fs.existsSync(path.join(goDir, 'bin', 'go'))).toBe(true); });
}
}, 100000);
it('Throws if no location contains correct go version', async () => { it('Throws if no location contains correct go version', async () => {
let thrown = false; let thrown = false;
@ -104,7 +105,7 @@ describe('installer tests', () => {
await io.mkdirP(goDir); await io.mkdirP(goDir);
fs.writeFileSync(`${goDir}.complete`, 'hello'); fs.writeFileSync(`${goDir}.complete`, 'hello');
// This will throw if it doesn't find it in the cache (because no such version exists) // This will throw if it doesn't find it in the cache (because no such version exists)
await installer.getGo('250.0.0'); await installer.getGo('250.0');
return; return;
}); });