From 518c94cd4235a3b0049a491fdffe958145ffe7b6 Mon Sep 17 00:00:00 2001 From: Benjamin Bennett Date: Mon, 22 Jan 2024 08:19:46 +0000 Subject: [PATCH] Adding return statements (#266) --- statecheck/expect_known_output_value.go | 4 ++++ statecheck/expect_known_output_value_at_path.go | 4 ++++ statecheck/expect_known_value.go | 8 ++++++++ statecheck/expect_sensitive_value.go | 8 ++++++++ 4 files changed, 24 insertions(+) diff --git a/statecheck/expect_known_output_value.go b/statecheck/expect_known_output_value.go index 64c47f819..951a36400 100644 --- a/statecheck/expect_known_output_value.go +++ b/statecheck/expect_known_output_value.go @@ -27,10 +27,14 @@ func (e expectKnownOutputValue) CheckState(ctx context.Context, req CheckStateRe if req.State == nil { resp.Error = fmt.Errorf("state is nil") + + return } if req.State.Values == nil { resp.Error = fmt.Errorf("state does not contain any state values") + + return } for address, oc := range req.State.Values.Outputs { diff --git a/statecheck/expect_known_output_value_at_path.go b/statecheck/expect_known_output_value_at_path.go index 9fb8cc4f1..1cdfcea79 100644 --- a/statecheck/expect_known_output_value_at_path.go +++ b/statecheck/expect_known_output_value_at_path.go @@ -28,10 +28,14 @@ func (e expectKnownOutputValueAtPath) CheckState(ctx context.Context, req CheckS if req.State == nil { resp.Error = fmt.Errorf("state is nil") + + return } if req.State.Values == nil { resp.Error = fmt.Errorf("state does not contain any state values") + + return } for address, oc := range req.State.Values.Outputs { diff --git a/statecheck/expect_known_value.go b/statecheck/expect_known_value.go index 96662c32a..86a741417 100644 --- a/statecheck/expect_known_value.go +++ b/statecheck/expect_known_value.go @@ -28,14 +28,20 @@ func (e expectKnownValue) CheckState(ctx context.Context, req CheckStateRequest, if req.State == nil { resp.Error = fmt.Errorf("state is nil") + + return } if req.State.Values == nil { resp.Error = fmt.Errorf("state does not contain any state values") + + return } if req.State.Values.RootModule == nil { resp.Error = fmt.Errorf("state does not contain a root module") + + return } for _, resourceChange := range req.State.Values.RootModule.Resources { @@ -62,6 +68,8 @@ func (e expectKnownValue) CheckState(ctx context.Context, req CheckStateRequest, if err := e.knownValue.CheckValue(result); err != nil { resp.Error = fmt.Errorf("error checking value for attribute at path: %s.%s, err: %s", e.resourceAddress, e.attributePath.String(), err) + + return } } diff --git a/statecheck/expect_sensitive_value.go b/statecheck/expect_sensitive_value.go index 447a2cb27..938238b25 100644 --- a/statecheck/expect_sensitive_value.go +++ b/statecheck/expect_sensitive_value.go @@ -26,14 +26,20 @@ func (e expectSensitiveValue) CheckState(ctx context.Context, req CheckStateRequ if req.State == nil { resp.Error = fmt.Errorf("state is nil") + + return } if req.State.Values == nil { resp.Error = fmt.Errorf("state does not contain any state values") + + return } if req.State.Values.RootModule == nil { resp.Error = fmt.Errorf("state does not contain a root module") + + return } for _, resourceChange := range req.State.Values.RootModule.Resources { @@ -71,11 +77,13 @@ func (e expectSensitiveValue) CheckState(ctx context.Context, req CheckStateRequ isSensitive, ok := result.(bool) if !ok { resp.Error = fmt.Errorf("invalid path: the path value cannot be asserted as bool") + return } if !isSensitive { resp.Error = fmt.Errorf("attribute at path is not sensitive") + return } }