Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assert that infer.Wraped providers can access the infer config #229

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions tests/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ func TestInferConfigWrap(t *testing.T) {
var baseConfigureWasCalled bool
var inferConfigureWasCalled bool

err := integration.NewServerWithContext(
var checkWasCalled bool

s := integration.NewServerWithContext(
context.WithValue(context.Background(),
ctxKey{},
&inferConfigureWasCalled),
Expand All @@ -58,14 +60,25 @@ func TestInferConfigWrap(t *testing.T) {
baseConfigureWasCalled = true
return nil
},
Check: func(ctx context.Context, _ p.CheckRequest) (p.CheckResponse, error) {
infer.GetConfig[*testConfig](ctx) // Will panic if config is missing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be clearer for the next person to have an assertion failure instead of a panic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up PR incoming.

checkWasCalled = true
return p.CheckResponse{}, nil
},
}, infer.Options{
Config: infer.Config[*testConfig](),
}),
).Configure(p.ConfigureRequest{
)

err := s.Configure(p.ConfigureRequest{
Args: resource.PropertyMap{"field": resource.NewProperty("foo")},
})
require.NoError(t, err)

_, err = s.Check(p.CheckRequest{})
require.NoError(t, err)

assert.True(t, baseConfigureWasCalled)
assert.True(t, inferConfigureWasCalled)
assert.True(t, checkWasCalled)
}
Loading