Skip to content

Commit

Permalink
Fix integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Apr 11, 2023
1 parent 2c950d9 commit e9f8d68
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
1 change: 1 addition & 0 deletions pkg/odo/cli/dev/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ func (o *DevOptions) Run(ctx context.Context) (err error) {

err = o.clientset.StateClient.Init(ctx)
if err != nil {
err = fmt.Errorf("unable to save state file: %v", err)
return err
}

Expand Down
18 changes: 6 additions & 12 deletions pkg/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,8 @@ func (o *State) read(platform string) (Content, error) {
if err != nil {
return Content{}, err
}
err = json.Unmarshal(jsonContent, &content)
if err != nil {
return Content{}, err
}
// Ignore error, to handle empty file
_ = json.Unmarshal(jsonContent, &content)
if content.Platform == platform {
break
} else {
Expand Down Expand Up @@ -194,10 +192,8 @@ func (o *State) isFreeOrOwnedBy(pid int) (bool, error) {
return false, err
}
var savedContent Content
err = json.Unmarshal(jsonContent, &savedContent)
if err != nil {
return false, err
}
// Ignore error, to handle empty file
_ = json.Unmarshal(jsonContent, &savedContent)
if savedContent.PID == 0 {
// PID is 0 in file, it is free
return true, nil
Expand Down Expand Up @@ -240,10 +236,8 @@ func (o *State) checkFirstInPlatform(ctx context.Context) error {
return err
}
var content Content
err = json.Unmarshal(jsonContent, &content)
if err != nil {
return err
}
// Ignore error, to handle empty file
_ = json.Unmarshal(jsonContent, &content)
if content.Platform == platform {
if content.PID == pid {
continue
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/cmd_dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ var _ = Describe("odo dev command tests", func() {
stdout := res.Out()
stderr := res.Err()
Expect(stdout).To(ContainSubstring("Cleaning"))
Expect(stderr).To(ContainSubstring("unable to save forwarded ports to state file"))
Expect(stderr).To(ContainSubstring("unable to save state file"))
})
})

Expand Down

0 comments on commit e9f8d68

Please sign in to comment.