-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add replace program utility #94
Conversation
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 really like where this is heading - to make working with inline YAML programs really easy. I think we could do with a little more design around the end-to-end process of testing YAML programs.
One assumption that's baked in right now is that we're always driving the test from a physical source directory. For YAML programs there's no real requirement for this. Perhaps we could introduce a new top-level test constructor for dealing with inline tests better? Something like this perhaps ...
test := NewPulumiInlineTest(t, opttest.AttachProviderBinary("gcp", "../bin"))
test.WritePulumiYaml(`
name: yaml_empty
runtime: yaml
outputs:
output: "output"
`)
test.InstallStack("my-stack")
update := test.Up()
t.Log(update.StdOut)
I expect the next step from here would be some additional utilities for YAML programs to be able to perform targeted updates.
test := NewPulumiInlineTest(t, opttest.AttachProviderBinary("gcp", "../bin"))
test.WritePulumiYaml(`
name: yaml_empty
runtime: yaml
outputs:
output: "output"
`)
test.Up()
test.UpdatePulumiYaml(
yaml.AddResource("my-resource", yaml.Resource{
Type: "aws:s3:Bucket",
})
A side question here: are there Go types available for the valid YAML constructs that we could leverage here instead of reverting to strings?
I wonder if either instead of For example: test.UpdatePulumiYaml(func(source string) string {
return `
name: yaml_empty
runtime: yaml
outputs:
output: "output"
`
}) Which then allows targeted updates: test.UpdatePulumiYaml(func(source string) string {
return strings.ReplaceAll(source, "toBeReplaced", "newValue")
}) |
I think that's for individual tests to implement as needed - it's easy enough to add something like
I don't think we need to add all the possible methods to the testing library but I've found I am using |
Discussed offline with @danielrbradley, I've added a ReadYaml utility and have removed the tab replacement in favour of an early error and a suggested program. The tab replacement could be ugly with mixed spaces and tabs. |
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.
Notes from sync review.
In a follow-up PR, we'll add a new NewInlinePulumiTest
constructor which takes the pulumiYaml string instead of the source directory 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.
Looks good once the TestReadProgram is passing
This PR has been shipped in release v0.1.3. |
This adds a ReplaceProgram utility to pulumitest which replaces the Pulumi program used by the test.
I've written this quite a few times now, so it seems like a good candidate as a utility - should be useful when testing updates.