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

Adds headers field for CheckHealthRequest #512

Merged
merged 2 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions backend/convert_from_protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,13 @@ func (f ConvertFromProtobuf) CallResourceResponse(protoResp *pluginv2.CallResour

// CheckHealthRequest converts protobuf version of a CheckHealthRequest to the SDK version.
func (f ConvertFromProtobuf) CheckHealthRequest(protoReq *pluginv2.CheckHealthRequest) *CheckHealthRequest {
if protoReq.Headers == nil {
protoReq.Headers = map[string]string{}
}

return &CheckHealthRequest{
PluginContext: f.PluginContext(protoReq.PluginContext),
Headers: protoReq.Headers,
}
}

Expand Down
28 changes: 28 additions & 0 deletions backend/convert_from_protobuf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,31 @@ func TestConvertFromProtobufQueryDataRequest(t *testing.T) {
//
require.Equal(t, requireCounter.Count, sdkWalker.FieldCount-6, "untested fields in conversion") // -6 Struct Fields
}

func TestConvertFromProtobufCheckHealthRequest(t *testing.T) {
t.Run("Should convert provided headers", func(t *testing.T) {
protoReq := &pluginv2.CheckHealthRequest{
PluginContext: protoPluginContext,
Headers: map[string]string{
"foo": "fooVal",
"bar": "barVal",
},
}

req := FromProto().CheckHealthRequest(protoReq)
require.NotNil(t, req)
require.NotNil(t, req.PluginContext)
require.Equal(t, protoPluginContext.OrgId, req.PluginContext.OrgID)
require.Equal(t, protoReq.Headers, req.Headers)
})

t.Run("Should handle nil-provided headers", func(t *testing.T) {
protoReq := &pluginv2.CheckHealthRequest{
PluginContext: protoPluginContext,
}

req := FromProto().CheckHealthRequest(protoReq)
require.NotNil(t, req)
require.NotNil(t, req.Headers)
})
}
1 change: 1 addition & 0 deletions backend/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (hs HealthStatus) String() string {
// CheckHealthRequest contains the healthcheck request
type CheckHealthRequest struct {
PluginContext PluginContext
Headers map[string]string
}

// CheckHealthResult contains the healthcheck response
Expand Down
Loading