Skip to content

Commit 98bd1de

Browse files
authored
Fix possible nil dereference (#3869)
* Protecting against possible nil dereference Related to #2100 Signed-off-by: David Gageot <[email protected]> * Simplify code Signed-off-by: David Gageot <[email protected]>
1 parent 35326cc commit 98bd1de

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

integration/rpc_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func TestGetStateRPC(t *testing.T) {
255255
var grpcState *proto.State
256256
for i := 0; i < readRetries; i++ {
257257
grpcState = retrieveRPCState(ctx, t, client)
258-
if checkBuildAndDeployComplete(*grpcState) {
258+
if grpcState != nil && checkBuildAndDeployComplete(*grpcState) {
259259
success = true
260260
break
261261
}
@@ -291,23 +291,22 @@ func TestGetStateHTTP(t *testing.T) {
291291
}
292292

293293
func retrieveRPCState(ctx context.Context, t *testing.T, client proto.SkaffoldServiceClient) *proto.State {
294-
var grpcState *proto.State
295-
var err error
296294
attempts := 0
297295
for {
298-
grpcState, err = client.GetState(ctx, &empty.Empty{})
299-
if err == nil {
300-
break
301-
}
302-
if attempts < connectionRetries {
303-
attempts++
296+
grpcState, err := client.GetState(ctx, &empty.Empty{})
297+
if err != nil {
298+
if attempts >= connectionRetries {
299+
t.Fatalf("error retrieving state: %v\n", err)
300+
}
301+
304302
t.Logf("waiting for connection...")
303+
attempts++
305304
time.Sleep(waitTime)
306305
continue
307306
}
308-
t.Fatalf("error retrieving state: %v\n", err)
307+
308+
return grpcState
309309
}
310-
return grpcState
311310
}
312311

313312
func retrieveHTTPState(t *testing.T, httpAddr string) proto.State {
@@ -361,6 +360,7 @@ func checkBuildAndDeployComplete(state proto.State) bool {
361360
return false
362361
}
363362
}
363+
364364
return state.DeployState.Status == event.Complete
365365
}
366366

0 commit comments

Comments
 (0)