Skip to content

Commit

Permalink
Elaborate code based on PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
t0yv0 committed Aug 25, 2023
1 parent 80bac60 commit 4cacd60
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions examples/provider_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,26 @@ func newProviderUpgradeInfo(t *testing.T) providerUpgradeInfo {
return info
}

func importState(t *testing.T, pt *integration.ProgramTester, stateFile string) {
func currentStackName(t *testing.T, pt *integration.ProgramTester) string {
tempDir := t.TempDir()
curStateFile := filepath.Join(tempDir, "temp-state.json")
pt.RunPulumiCommand("stack", "export", "--file", curStateFile)
curState := readFile(t, curStateFile)
return parseStackName(t, curState)
}

func fixupStackName(t *testing.T, pt *integration.ProgramTester, stateFile string) string {
tempDir := t.TempDir()
newStateFile := filepath.Join(tempDir, "new-state.json")
pt.RunPulumiCommand("stack", "export", "--file", newStateFile)
stackName := parseStackName(t, readFile(t, newStateFile))
fixedState := withUpdatedStackName(t, stackName, readFile(t, stateFile))
stackName := currentStackName(t, pt)
state := readFile(t, stateFile)
fixedState := withUpdatedStackName(t, stackName, state)
fixedStateFile := filepath.Join(tempDir, "fixed-state.json")
writeFile(t, fixedStateFile, []byte(fixedState))
return fixedStateFile
}

func importState(t *testing.T, pt *integration.ProgramTester, stateFile string) {
fixedStateFile := fixupStackName(t, pt, stateFile)
pt.RunPulumiCommand("stack", "import", "--file", fixedStateFile)
}

Expand Down

0 comments on commit 4cacd60

Please sign in to comment.