Skip to content

Commit

Permalink
Merge pull request #3658 from tejal29/resetStatusCheckStateCorrectly
Browse files Browse the repository at this point in the history
Fix npe when resetting status check state
  • Loading branch information
nkubala committed Feb 6, 2020
2 parents 4423935 + b050b84 commit 2718cfa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
16 changes: 10 additions & 6 deletions pkg/skaffold/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,8 @@ func emptyStateWithArtifacts(builds map[string]string) proto.State {
DeployState: &proto.DeployState{
Status: NotStarted,
},
StatusCheckState: &proto.StatusCheckState{
Status: NotStarted,
Resources: map[string]string{},
},
ForwardedPorts: make(map[int32]*proto.PortEvent),
StatusCheckState: emptyStatusCheckState(),
ForwardedPorts: make(map[int32]*proto.PortEvent),
FileSyncState: &proto.FileSyncState{
Status: NotStarted,
},
Expand Down Expand Up @@ -507,8 +504,15 @@ func ResetStateOnBuild() {
func ResetStateOnDeploy() {
newState := handler.getState()
newState.DeployState.Status = NotStarted
newState.StatusCheckState.Status = NotStarted
newState.StatusCheckState = emptyStatusCheckState()
newState.ForwardedPorts = map[int32]*proto.PortEvent{}
newState.DebuggingContainers = nil
handler.setState(newState)
}

func emptyStatusCheckState() *proto.StatusCheckState {
return &proto.StatusCheckState{
Status: NotStarted,
Resources: map[string]string{},
}
}
22 changes: 17 additions & 5 deletions pkg/skaffold/event/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"testing"
"time"

"github.com/google/go-cmp/cmp/cmpopts"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/GoogleContainerTools/skaffold/proto"
"github.com/GoogleContainerTools/skaffold/testutil"
Expand Down Expand Up @@ -355,10 +357,10 @@ func TestResetStateOnBuild(t *testing.T) {
},
},
DeployState: &proto.DeployState{Status: NotStarted},
StatusCheckState: &proto.StatusCheckState{Status: NotStarted},
StatusCheckState: &proto.StatusCheckState{Status: NotStarted, Resources: map[string]string{}},
FileSyncState: &proto.FileSyncState{Status: NotStarted},
}
testutil.CheckDeepEqual(t, expected, handler.getState())
testutil.CheckDeepEqual(t, expected, handler.getState(), cmpopts.EquateEmpty())
}

func TestResetStateOnDeploy(t *testing.T) {
Expand Down Expand Up @@ -388,8 +390,18 @@ func TestResetStateOnDeploy(t *testing.T) {
"image1": Complete,
},
},
DeployState: &proto.DeployState{Status: NotStarted},
StatusCheckState: &proto.StatusCheckState{Status: NotStarted},
DeployState: &proto.DeployState{Status: NotStarted},
StatusCheckState: &proto.StatusCheckState{Status: NotStarted,
Resources: map[string]string{},
},
}
testutil.CheckDeepEqual(t, expected, handler.getState(), cmpopts.EquateEmpty())
}

func TestEmptyStateCheckState(t *testing.T) {
actual := emptyStatusCheckState()
expected := &proto.StatusCheckState{Status: NotStarted,
Resources: map[string]string{},
}
testutil.CheckDeepEqual(t, expected, handler.getState())
testutil.CheckDeepEqual(t, expected, actual, cmpopts.EquateEmpty())
}

0 comments on commit 2718cfa

Please sign in to comment.