-
Notifications
You must be signed in to change notification settings - Fork 66
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
feat(publish): Support for custom VCL logic #893
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a32aaef
feat(publish): support custom vcl
kptdobe 5dbad80
feat(publish): Add tests for custom-vcl
kptdobe aa7407e
Merge branch 'master' into support-custom-vcl
kptdobe 4af608d
feat(publish): fix the tests and make code a stronger
kptdobe d0f7367
Update test/testRemotePublishCmd.customvcl.js
kptdobe 8500b1e
fix(publish): integrate feedback
kptdobe 3396e98
fix(publish): fix broken test
kptdobe c612403
Merge branch 'master' into support-custom-vcl
kptdobe aa400b3
fix(publish): fix the tests
kptdobe 01670dc
fix(publish): Tentative to increase codecov
kptdobe 9cae098
fix(publish): Add one more test
kptdobe 5a1fd86
fix(publish): test more code
kptdobe fd4d23b
fix(publish): assert throws error
kptdobe 41c380d
fix(publish): correct the resolution path
kptdobe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# | ||
# Copyright 2019 Adobe. All rights reserved. | ||
# This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. You may obtain a copy | ||
# of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed under | ||
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
# OF ANY KIND, either express or implied. See the License for the specific language | ||
# governing permissions and limitations under the License. | ||
# | ||
|
||
sub hlx_type_pipeline_before { | ||
# THIS WILL DO SOME CUSTOM CODE | ||
} | ||
|
||
sub hlx_type_pipeline_after { | ||
# THIS WILL DO SOME CUSTOM CODE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# | ||
# Copyright 2019 Adobe. All rights reserved. | ||
# This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. You may obtain a copy | ||
# of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed under | ||
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
# OF ANY KIND, either express or implied. See the License for the specific language | ||
# governing permissions and limitations under the License. | ||
# | ||
|
||
sub hlx_type_pipeline_before { | ||
# THIS WILL DO SOME CUSTOM CODE | ||
} | ||
|
||
sub hlx_type_pipeline_after { | ||
# THIS WILL DO SOME CUSTOM CODE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
/* | ||
* Copyright 2018 Adobe. All rights reserved. | ||
* This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
|
||
/* eslint-env mocha */ | ||
|
||
const assert = require('assert'); | ||
const fs = require('fs-extra'); | ||
const nock = require('nock'); | ||
const path = require('path'); | ||
const proxyquire = require('proxyquire'); | ||
const sinon = require('sinon'); | ||
const shell = require('shelljs'); | ||
const { Logger } = require('@adobe/helix-shared'); | ||
const { createTestRoot } = require('./utils.js'); | ||
|
||
const RemotePublishCommand = require('../src/remotepublish.cmd'); | ||
|
||
describe('hlx publish --custom-vcl (check params)', () => { | ||
it('hlx publish (no custom-vcl)', () => { | ||
const remote = new RemotePublishCommand() | ||
.withCustomVCLs(); | ||
|
||
// eslint-disable-next-line no-underscore-dangle | ||
assert.equal(remote._vcl, null); | ||
}); | ||
|
||
it('hlx publish --custom-vcl fixtures/vcl/extensions.vcl', async () => { | ||
const e = path.resolve(__dirname, 'fixtures/vcl/extensions.vcl'); | ||
const remote = new RemotePublishCommand() | ||
.withCustomVCLs([e]); | ||
|
||
// eslint-disable-next-line no-underscore-dangle | ||
assert.deepEqual(remote._vcl, { | ||
extensions: (await fs.readFile(e, 'utf8')).toString(), | ||
}); | ||
}); | ||
|
||
it('hlx publish --custom-vcl fixtures/vcl/extensions.vcl --custom-vcl fixtures/vcl/another.vcl', async () => { | ||
const e = path.resolve(__dirname, 'fixtures/vcl/extensions.vcl'); | ||
const a = path.resolve(__dirname, 'fixtures/vcl/another.vcl'); | ||
const remote = new RemotePublishCommand() | ||
.withCustomVCLs([e, a]); | ||
|
||
// eslint-disable-next-line no-underscore-dangle | ||
assert.deepEqual(remote._vcl, { | ||
extensions: (await fs.readFile(e, 'utf8')).toString(), | ||
another: (await fs.readFile(e, 'utf8')).toString(), | ||
}); | ||
}); | ||
|
||
it('hlx publish --custom-vcl fixtures/vcl/unexisting.vcl', async () => { | ||
const e = path.resolve(__dirname, 'fixtures/vcl/unexisting.vcl'); | ||
function throwsError() { | ||
new RemotePublishCommand().withCustomVCLs([e]); | ||
} | ||
assert.throws(throwsError); | ||
}); | ||
}); | ||
|
||
describe('hlx publish --custom-vcl (check requests)', () => { | ||
let ProxiedRemotePublishCommand; | ||
let writeDictItem; | ||
let purgeAll; | ||
let testRoot; | ||
let pwd; | ||
let vcl; | ||
let scope; | ||
let remote; | ||
|
||
beforeEach('Setting up Fake Server', async function bef() { | ||
this.timeout(5000); | ||
writeDictItem = sinon.fake.resolves(true); | ||
purgeAll = sinon.fake.resolves(true); | ||
|
||
ProxiedRemotePublishCommand = proxyquire('../src/remotepublish.cmd', { | ||
'@adobe/fastly-native-promises': () => ({ | ||
transact: fn => fn(3), | ||
writeDictItem, | ||
purgeAll, | ||
}), | ||
}); | ||
|
||
|
||
// ensure to reset nock to avoid conflicts with PollyJS | ||
nock.restore(); | ||
nock.cleanAll(); | ||
nock.activate(); | ||
|
||
scope = nock('https://adobeioruntime.net') | ||
.post('/api/v1/web/helix/default/publish', (body) => { | ||
({ vcl } = body); | ||
return true; | ||
}) | ||
.reply(200, {}) | ||
.post('/api/v1/web/helix/default/addlogger') | ||
.reply(200, {}); | ||
|
||
// set up a fake git repo. | ||
testRoot = await createTestRoot(); | ||
await fs.copy(path.resolve(__dirname, 'fixtures/filtered-master.yaml'), path.resolve(testRoot, 'helix-config.yaml')); | ||
|
||
// throw a Javascript error when any shell.js command encounters an error | ||
shell.config.fatal = true; | ||
|
||
// init git repo | ||
pwd = shell.pwd(); | ||
shell.cd(testRoot); | ||
shell.exec('git init'); | ||
shell.exec('git add -A'); | ||
shell.exec('git commit -m"initial commit."'); | ||
|
||
// set up command | ||
const logger = Logger.getTestLogger(); | ||
remote = await new ProxiedRemotePublishCommand(logger) | ||
.withWskAuth('fakeauth') | ||
.withWskNamespace('fakename') | ||
.withFastlyAuth('fake_auth') | ||
.withFastlyNamespace('fake_name') | ||
.withWskHost('doesn.t.matter') | ||
.withPublishAPI('https://adobeioruntime.net/api/v1/web/helix/default/publish') | ||
.withConfigFile(path.resolve(__dirname, 'fixtures/filtered.yaml')) | ||
.withDryRun(false); | ||
}); | ||
|
||
it('hlx publish (no custom-vcl)', async () => { | ||
await remote.run(); | ||
assert.equal(vcl, null); | ||
}); | ||
|
||
it('hlx publish --custom-vcl fixtures/vcl/extensions.vcl', async () => { | ||
const e = path.resolve(__dirname, 'fixtures/vcl/extensions.vcl'); | ||
remote.withCustomVCLs([e]); | ||
await remote.run(); | ||
|
||
assert.ok(vcl); | ||
assert.deepEqual(vcl, { | ||
extensions: fs.readFileSync(e).toString(), | ||
}); | ||
}); | ||
|
||
it('hlx publish --custom-vcl fixtures/vcl/extensions.vcl --custom-vcl fixtures/vcl/another.vcl', async () => { | ||
const e = path.resolve(__dirname, 'fixtures/vcl/extensions.vcl'); | ||
const a = path.resolve(__dirname, 'fixtures/vcl/another.vcl'); | ||
remote.withCustomVCLs([e, a]); | ||
await remote.run(); | ||
|
||
assert.ok(vcl); | ||
assert.deepEqual(vcl, { | ||
extensions: fs.readFileSync(e).toString(), | ||
another: fs.readFileSync(a).toString(), | ||
}); | ||
}); | ||
|
||
afterEach(async () => { | ||
scope.done(); | ||
nock.restore(); | ||
shell.cd(pwd); | ||
await fs.remove(testRoot); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async, please