Fix issue with parsing empty engine logs
@@ -697,7 +697,7 @@ type ProgramTester struct {
pythonBin string // the `python` binary we are using.
pipenvBin string // The `pipenv` binary we are using.
dotNetBin string // the `dotnet` binary we are using.
- eventLog string // The path to the event log for this test.
+ updateEventLog string // The path to the engine event log for `pulumi up` in this test.
maxStepTries int // The maximum number of times to retry a failed pulumi step.
tmpdir string // the temporary directory we use for our test environment
projdir string // the project directory we use for this run
@@ -718,7 +718,7 @@ func newProgramTester(t *testing.T, opts *ProgramTestOptions) *ProgramTester {
return &ProgramTester{
t: t,
opts: opts,
- eventLog: filepath.Join(os.TempDir(), string(stackName)+"-events.json"),
+ updateEventLog: filepath.Join(os.TempDir(), string(stackName)+"-events.json"),
maxStepTries: maxStepTries,
}
}
@@ -1320,7 +1320,7 @@ func (pt *ProgramTester) PreviewAndUpdate(dir string, name string, shouldFail, e
expectNopUpdate bool) error {
preview := []string{"preview", "--non-interactive"}
- update := []string{"up", "--non-interactive", "--yes", "--skip-preview", "--event-log", pt.eventLog}
+ update := []string{"up", "--non-interactive", "--yes", "--skip-preview", "--event-log", pt.updateEventLog}
if pt.opts.GetDebugUpdates() {
preview = append(preview, "-d")
update = append(update, "-d")
@@ -1580,22 +1580,9 @@ func (pt *ProgramTester) performExtraRuntimeValidation(
}
}
- // Read the event log.
- eventsFile, err := os.Open(pt.eventLog)
- if err != nil && !os.IsNotExist(err) {
- return fmt.Errorf("expected to be able to open event log file %s: %w", pt.eventLog, err)
- }
- defer contract.IgnoreClose(eventsFile)
- decoder, events := json.NewDecoder(eventsFile), []apitype.EngineEvent{}
- for {
- var event apitype.EngineEvent
- if err = decoder.Decode(&event); err != nil {
- if err == io.EOF {
- break
- }
- return fmt.Errorf("decoding engine event: %w", err)
- }
- events = append(events, event)
+ events, err := pt.readUpdateEventLog()
+ if err != nil {
+ return err
}
// Populate stack info object with all of this data to pass to the validation function
@@ -1613,6 +1600,35 @@ func (pt *ProgramTester) performExtraRuntimeValidation(
return nil
}
+func (pt *ProgramTester) readUpdateEventLog() ([]apitype.EngineEvent, error) {
+ events := []apitype.EngineEvent{}
+ eventsFile, err := os.Open(pt.updateEventLog)
+ if err != nil {
+ if os.IsNotExist(err) {
+ return events, nil
+ }
+ return events, fmt.Errorf("expected to be able to open event log file %s: %w",
+ pt.updateEventLog, err)
+ }
+
+ defer contract.IgnoreClose(eventsFile)
+
+ decoder := json.NewDecoder(eventsFile)
+ for {
+ var event apitype.EngineEvent
+ if err = decoder.Decode(&event); err != nil {
+ if err == io.EOF {
+ break
+ }
+ return events, fmt.Errorf("failed decoding engine event from log file %s: %w",
+ pt.updateEventLog, err)
+ }
+ events = append(events, event)
+ }
+
+ return events, nil
+}
+
// copyTestToTemporaryDirectory creates a temporary directory to run the test in and copies the test to it.
func (pt *ProgramTester) copyTestToTemporaryDirectory() (string, string, error) {
// Get the source dir and project info.
