1
mirror of https://github.com/jakejarvis/hugo-extended.git synced 2025-10-16 09:54:28 -04:00

feat: Allowing to overwrite the Download Repository aka Download Mirror (#120)

introduces downloadRepo as new installation option allowing to define a mirror-repository
This commit is contained in:
jweberde
2022-09-15 07:15:27 +02:00
committed by GitHub
parent 2ee3c6bbaf
commit cbb4db4792
3 changed files with 120 additions and 33 deletions

View File

@@ -1,7 +1,9 @@
import { strict as assert } from 'node:assert';
import process from 'node:process';
import binCheck from 'bin-check';
import { test } from 'uvu';
import { test, suite } from 'uvu';
import hugoBin from '../index.js';
import hugoLib from '../lib/index.js';
test('should return path to binary and work', () => {
return binCheck(hugoBin, ['version']).then(works => {
@@ -10,3 +12,75 @@ test('should return path to binary and work', () => {
});
test.run();
/**
* Verify Custom/Enterprise Repository overwrite.
*/
const hugoLibCustomRepoTestSuite = suite('hugo-bin overwrite download repository');
hugoLibCustomRepoTestSuite.before.each(() => {
// Ensure that the environment is cleaned before next test run.
delete process.env.npm_config_hugo_bin_build_tags;
delete process.env.npm_config_hugo_bin_download_repo;
});
hugoLibCustomRepoTestSuite('verify test env', () => {
assert.equal(process.env.npm_config_hugo_bin_build_tags, undefined);
assert.equal(process.env.npm_config_hugo_bin_download_repo, undefined);
})
// Default Repository - Test Cases
hugoLibCustomRepoTestSuite('should return default repository url - Repository: default - Extended: undefined', () => {
const repoSources = hugoLib(process.cwd())._src.map((v) => v.url);
repoSources.forEach((sourceUrl) => {
assert.ok(sourceUrl.startsWith('https://github.com/'));
});
});
hugoLibCustomRepoTestSuite('should return default repository url - Repository: default - Extended: empty', () => {
process.env.npm_config_hugo_bin_build_tags = '';
const repoSources = hugoLib(process.cwd())._src.map((v) => v.url);
repoSources.forEach((sourceUrl) => {
assert.ok(sourceUrl.startsWith('https://github.com/'));
});
});
hugoLibCustomRepoTestSuite('should return default repository url - Repository: default - Extended: extended', () => {
process.env.npm_config_hugo_bin_build_tags = 'extended';
const repoSources = hugoLib(process.cwd())._src.map((v) => v.url);
repoSources.forEach((sourceUrl) => {
assert.ok(sourceUrl.startsWith('https://github.com/'));
});
});
// Custom/Enterprise Repository Test Cases
hugoLibCustomRepoTestSuite('should return custom repository url - Repository: custom - Extended: undefined', () => {
process.env.npm_config_hugo_bin_download_repo = 'https://some1.example.com';
const repoSources = hugoLib(process.cwd())._src.map((v) => v.url);
repoSources.forEach((sourceUrl) => {
assert.ok(sourceUrl.startsWith('https://some1.example.com/'));
});
});
hugoLibCustomRepoTestSuite('should return custom repository url - Repository: custom - Extended: empty', () => {
process.env.npm_config_hugo_bin_build_tags = '';
process.env.npm_config_hugo_bin_download_repo = 'https://some2.example.com';
const repoSources = hugoLib(process.cwd())._src.map((v) => v.url);
repoSources.forEach((sourceUrl) => {
assert.ok(sourceUrl.startsWith('https://some2.example.com/'));
});
});
hugoLibCustomRepoTestSuite('should return custom repository url - Repository: custom - Extended: extended', () => {
process.env.npm_config_hugo_bin_build_tags = 'extended';
process.env.npm_config_hugo_bin_download_repo = 'https://some3.example.com';
const repoSources = hugoLib(process.cwd())._src.map((v) => v.url);
repoSources.forEach((sourceUrl) => {
assert.ok(sourceUrl.startsWith('https://some3.example.com/'));
});
});
hugoLibCustomRepoTestSuite.run();