-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
create var file for template variables #7511
Conversation
Tasks/PackerBuildV0/src/utilities.ts
Outdated
res[key] = value | ||
}); | ||
let content: string = JSON.stringify(res); | ||
tl.writeFile(filePath, content); |
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.
There is already a writeFile utility which will be useful in l0 mocking
templateVariables.forEach((value: string, key: string) => { | ||
res[key] = value | ||
}); | ||
let content: string = JSON.stringify(res); |
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.
Please test with special characters in values - space, quotes etc
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.
Tested this on ubuntu 18.04 and win 10. The var file created had whitespaces and quotes in its path.
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.
You should also test for variable values containing special chars. They should be properly escaped when using Json.Stringify and packer should be able to consume them successfully
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.
done.
Tasks/PackerBuildV0/src/utilities.ts
Outdated
@@ -84,6 +84,17 @@ export function readJsonFile(filePath: string): string { | |||
return content; | |||
} | |||
|
|||
export function createTemplateVarFile (templateVariables: Map<string, string>): string { | |||
let filePath: string = path.resolve(tl.getVariable('Agent.TempDirectory'), Math.random().toString(36).replace('0.', '') + '.json'); |
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.
Instead of random, you can also use Date.now() which is good enough
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.
I tried using Date.now(), but since we create 2 separate var files one after the other, there were name collisions a few times. That is why I am using to Math.random.
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.
ok
I believe you will need to modify UTs. |
@@ -1,132 +0,0 @@ | |||
import ma = require('vsts-task-lib/mock-answer'); |
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.
Hey @bishal-pdMSFT , I noticed that this file isn't being referenced anywhere. There is a typo in the filename ( notice the Linuxs ). There is another file with the correct name already present. Can you confirm if this isn't required ?
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.
If it is not being used anywhere, please delete it
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.
done
@@ -54,23 +54,23 @@ let a: any = <any>{ | |||
"code": 0, | |||
"stdout": "{ \"some-key\": \"some-value\" }" | |||
}, | |||
"packer validate -var resource_group=testrg -var storage_account=teststorage -var image_publisher=Canonical -var image_offer=UbuntuServer -var image_sku=14.04.4-LTS -var location=South India -var capture_name_prefix=Release-1 -var skip_clean=true -var script_relative_path=dir3/somedir/deploy.sh -var package_path=/tmp/dir1/somedir/dir2 -var package_name=dir2 -var script_arguments=\"subdir 1\" false -var subscription_id=sId -var client_id=spId -var client_secret=spKey -var tenant_id=tenant -var object_id= /tmp/tempdir/100/default.linux.template-fixed.json": { |
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.
You should modify test to ensure that these parameters are present in var file. I think test mocks Write-File to write to console. You can grep console output to ensure that this content is correct.
In this task, passing correct parameters is the most important aspect. Hence we need to test them thoroughly.
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.
added 2 tests for this. first one verifies for default template, the other one for custom template
No description provided.