Skip to content

Commit

Permalink
Adding address and path to state check errors (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
bendbennett committed Jan 15, 2024
1 parent a79aea8 commit f5abf73
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion statecheck/expect_known_output_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (e expectKnownOutputValue) CheckState(ctx context.Context, req CheckStateRe
}

if err := e.knownValue.CheckValue(result); err != nil {
resp.Error = err
resp.Error = fmt.Errorf("error checking value for output at path: %s, err: %s", e.outputAddress, err)

return
}
Expand Down
2 changes: 1 addition & 1 deletion statecheck/expect_known_output_value_at_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (e expectKnownOutputValueAtPath) CheckState(ctx context.Context, req CheckS
}

if err := e.knownValue.CheckValue(result); err != nil {
resp.Error = err
resp.Error = fmt.Errorf("error checking value for output at path: %s.%s, err: %s", e.outputAddress, e.outputPath.String(), err)

return
}
Expand Down
10 changes: 6 additions & 4 deletions statecheck/expect_known_output_value_at_path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1442,14 +1442,16 @@ func TestExpectKnownOutputValueAtPath_CheckState_UnknownAttributeType(t *testing
State: &tfjson.State{
Values: &tfjson.StateValues{
Outputs: map[string]*tfjson.StateOutput{
"float32_output": {
Value: float32(123),
"obj": {
Value: map[string]any{
"float32_output": float32(123),
},
},
},
},
},
},
expectedErr: fmt.Errorf("expected json.Number value for Int64Exact check, got: float32"),
expectedErr: fmt.Errorf("error checking value for output at path: obj.float32_output, err: expected json.Number value for Int64Exact check, got: float32"),
},
}

Expand All @@ -1459,7 +1461,7 @@ func TestExpectKnownOutputValueAtPath_CheckState_UnknownAttributeType(t *testing
t.Run(name, func(t *testing.T) {
t.Parallel()

e := statecheck.ExpectKnownOutputValueAtPath("float32_output", tfjsonpath.Path{}, testCase.knownValue)
e := statecheck.ExpectKnownOutputValueAtPath("obj", tfjsonpath.New("float32_output"), testCase.knownValue)

resp := statecheck.CheckStateResponse{}

Expand Down
2 changes: 1 addition & 1 deletion statecheck/expect_known_output_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ func TestExpectKnownOutputValue_CheckState_UnknownAttributeType(t *testing.T) {
},
},
},
expectedErr: fmt.Errorf("expected json.Number value for Int64Exact check, got: float32"),
expectedErr: fmt.Errorf("error checking value for output at path: float32_output, err: expected json.Number value for Int64Exact check, got: float32"),
},
}

Expand Down
2 changes: 1 addition & 1 deletion statecheck/expect_known_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (e expectKnownValue) CheckState(ctx context.Context, req CheckStateRequest,
}

if err := e.knownValue.CheckValue(result); err != nil {
resp.Error = err
resp.Error = fmt.Errorf("error checking value for attribute at path: %s.%s, err: %s", e.resourceAddress, e.attributePath.String(), err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion statecheck/expect_known_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ func TestExpectKnownValue_CheckState_UnknownAttributeType(t *testing.T) {
},
},
},
expectedErr: fmt.Errorf("expected json.Number value for Int64Exact check, got: float32"),
expectedErr: fmt.Errorf("error checking value for attribute at path: example_resource.test.attribute, err: expected json.Number value for Int64Exact check, got: float32"),
},
}

Expand Down

0 comments on commit f5abf73

Please sign in to comment.