Skip to content

Commit

Permalink
fix and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiasac committed Dec 27, 2024
1 parent 91ff273 commit 7c70ea9
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 33 deletions.
49 changes: 30 additions & 19 deletions connector/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,11 @@ func TestHTTPConnector_distribution(t *testing.T) {
var body []struct {
Rows []struct {
Value struct {
Errors []internal.DistributedError `json:"errors"`
Results []internal.DistributedResult[[]distributedResultData] `json:"results"`
Headers map[string]string `json:"headers"`
Response struct {
Errors []internal.DistributedError `json:"errors"`
Results []internal.DistributedResult[[]distributedResultData] `json:"results"`
} `json:"response"`
} `json:"__value"`
} `json:"rows"`
}
Expand All @@ -589,14 +592,14 @@ func TestHTTPConnector_distribution(t *testing.T) {

assert.Equal(t, 1, len(body))
row := body[0].Rows[0]
assert.Equal(t, 0, len(row.Value.Errors))
assert.Equal(t, 2, len(row.Value.Results))
assert.Equal(t, 0, len(row.Value.Response.Errors))
assert.Equal(t, 2, len(row.Value.Response.Results))

slices.SortFunc(row.Value.Results, func(a internal.DistributedResult[[]distributedResultData], b internal.DistributedResult[[]distributedResultData]) int {
slices.SortFunc(row.Value.Response.Results, func(a internal.DistributedResult[[]distributedResultData], b internal.DistributedResult[[]distributedResultData]) int {
return strings.Compare(a.Server, b.Server)
})

assert.DeepEqual(t, expectedResults, row.Value.Results)
assert.DeepEqual(t, expectedResults, row.Value.Response.Results)

assert.Equal(t, int32(1), mock.catCount)
assert.Equal(t, int32(1), mock.dogCount)
Expand Down Expand Up @@ -653,8 +656,11 @@ func TestHTTPConnector_distribution(t *testing.T) {
var body struct {
OperationResults []struct {
Result struct {
Errors []internal.DistributedError `json:"errors"`
Results []internal.DistributedResult[[]distributedResultData] `json:"results"`
Headers map[string]string `json:"headers"`
Response struct {
Errors []internal.DistributedError `json:"errors"`
Results []internal.DistributedResult[[]distributedResultData] `json:"results"`
} `json:"response"`
} `json:"result"`
} `json:"operation_results"`
}
Expand All @@ -663,14 +669,14 @@ func TestHTTPConnector_distribution(t *testing.T) {
}

row := body.OperationResults[0].Result
assert.Equal(t, 0, len(row.Errors))
assert.Equal(t, 2, len(row.Results))
assert.Equal(t, 0, len(row.Response.Errors))
assert.Equal(t, 2, len(row.Response.Results))

slices.SortFunc(row.Results, func(a internal.DistributedResult[[]distributedResultData], b internal.DistributedResult[[]distributedResultData]) int {
slices.SortFunc(row.Response.Results, func(a internal.DistributedResult[[]distributedResultData], b internal.DistributedResult[[]distributedResultData]) int {
return strings.Compare(a.Server, b.Server)
})

assert.DeepEqual(t, expectedResults, row.Results)
assert.DeepEqual(t, expectedResults, row.Response.Results)
assert.Equal(t, int32(1), mock.catCount)
assert.Equal(t, int32(1), mock.dogCount)
})
Expand Down Expand Up @@ -718,15 +724,20 @@ func TestHTTPConnector_distribution(t *testing.T) {
assertHTTPResponse(t, res, http.StatusOK, schema.QueryResponse{
{
Rows: []map[string]any{

{"__value": map[string]any{
"errors": []any{},
"results": []any{
map[string]any{
"data": []any{
map[string]any{"name": "cat"},
"headers": map[string]any{
"Content-Length": "17",
"Content-Type": "application/json",
},
"response": map[string]any{
"errors": []any{},
"results": []any{
map[string]any{
"data": []any{
map[string]any{"name": "cat"},
},
"server": string("cat"),
},
"server": string("cat"),
},
},
}},
Expand Down
1 change: 0 additions & 1 deletion connector/internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func (client *HTTPClient) Send(ctx context.Context, selection schema.NestedField
}

result = client.createHeaderForwardingResponse(result, headers)

if len(selection) > 0 {
var err error
result, err = utils.EvalNestedColumnFields(selection, result)
Expand Down
15 changes: 15 additions & 0 deletions connector/testdata/patch/config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# yaml-language-server: $schema=../../../ndc-http-schema/jsonschema/configuration.schema.json
strict: true
concurrency:
query: 1
mutation: 1
http: 1
forwardHeaders:
enabled: true
argumentField: null
responseHeaders:
headersField: headers
resultField: response
forwardHeaders:
- Content-Type
- Content-Length
files:
- file: ../auth/schema.yaml
spec: ndc
Expand Down
40 changes: 37 additions & 3 deletions ndc-http-schema/command/testdata/auth/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@
"type": "named"
},
"type": "array"
},
"original_result_type": {
"element_type": {
"name": "Pet",
"type": "named"
},
"type": "array"
}
},
"findPetsByStatus": {
Expand Down Expand Up @@ -113,6 +120,13 @@
"type": "named"
},
"type": "array"
},
"original_result_type": {
"element_type": {
"name": "Pet",
"type": "named"
},
"type": "array"
}
},
"petRetry": {
Expand All @@ -130,6 +144,13 @@
"type": "named"
},
"type": "array"
},
"original_result_type": {
"element_type": {
"name": "Pet",
"type": "named"
},
"type": "array"
}
}
},
Expand Down Expand Up @@ -225,9 +246,7 @@
"type": "named"
}
},
"http": {
"type": null
}
"http": {}
},
"id": {
"type": {
Expand Down Expand Up @@ -403,6 +422,10 @@
"result_type": {
"name": "Pet",
"type": "named"
},
"original_result_type": {
"name": "Pet",
"type": "named"
}
},
"createModel": {
Expand Down Expand Up @@ -436,6 +459,13 @@
"type": "named"
},
"type": "array"
},
"original_result_type": {
"element_type": {
"name": "ProgressResponse",
"type": "named"
},
"type": "array"
}
},
"putPetXml": {
Expand Down Expand Up @@ -465,6 +495,10 @@
"result_type": {
"name": "PetXml",
"type": "named"
},
"original_result_type": {
"name": "PetXml",
"type": "named"
}
}
},
Expand Down
76 changes: 73 additions & 3 deletions ndc-http-schema/command/testdata/patch/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@
"result_type": {
"name": "FindPetsHeadersResponse",
"type": "named"
},
"original_result_type": {
"element_type": {
"name": "Pet",
"type": "named"
},
"type": "array"
}
},
"findPetsByStatus": {
Expand Down Expand Up @@ -163,6 +170,13 @@
"result_type": {
"name": "FindPetsByStatusHeadersResponse",
"type": "named"
},
"original_result_type": {
"element_type": {
"name": "Pet",
"type": "named"
},
"type": "array"
}
},
"findPetsByStatusDistributed": {
Expand Down Expand Up @@ -220,6 +234,13 @@
"result_type": {
"name": "FindPetsByStatusDistributedHeadersResponse",
"type": "named"
},
"original_result_type": {
"element_type": {
"name": "Pet",
"type": "named"
},
"type": "array"
}
},
"findPetsDistributed": {
Expand Down Expand Up @@ -256,6 +277,13 @@
"result_type": {
"name": "FindPetsDistributedHeadersResponse",
"type": "named"
},
"original_result_type": {
"element_type": {
"name": "Pet",
"type": "named"
},
"type": "array"
}
},
"petRetry": {
Expand Down Expand Up @@ -291,6 +319,13 @@
"result_type": {
"name": "PetRetryHeadersResponse",
"type": "named"
},
"original_result_type": {
"element_type": {
"name": "Pet",
"type": "named"
},
"type": "array"
}
},
"petRetryDistributed": {
Expand Down Expand Up @@ -326,6 +361,13 @@
"result_type": {
"name": "PetRetryDistributedHeadersResponse",
"type": "named"
},
"original_result_type": {
"element_type": {
"name": "Pet",
"type": "named"
},
"type": "array"
}
}
},
Expand Down Expand Up @@ -933,9 +975,7 @@
"type": "named"
}
},
"http": {
"type": null
}
"http": {}
},
"id": {
"type": {
Expand Down Expand Up @@ -1213,6 +1253,10 @@
"result_type": {
"name": "AddPetHeadersResponse",
"type": "named"
},
"original_result_type": {
"name": "Pet",
"type": "named"
}
},
"addPetDistributed": {
Expand Down Expand Up @@ -1272,6 +1316,10 @@
"result_type": {
"name": "AddPetDistributedHeadersResponse",
"type": "named"
},
"original_result_type": {
"name": "Pet",
"type": "named"
}
},
"createModel": {
Expand Down Expand Up @@ -1322,6 +1370,13 @@
"result_type": {
"name": "CreateModelHeadersResponse",
"type": "named"
},
"original_result_type": {
"element_type": {
"name": "ProgressResponse",
"type": "named"
},
"type": "array"
}
},
"createModelDistributed": {
Expand Down Expand Up @@ -1372,6 +1427,13 @@
"result_type": {
"name": "CreateModelDistributedHeadersResponse",
"type": "named"
},
"original_result_type": {
"element_type": {
"name": "ProgressResponse",
"type": "named"
},
"type": "array"
}
},
"putPetXml": {
Expand Down Expand Up @@ -1421,6 +1483,10 @@
"result_type": {
"name": "PutPetXmlHeadersResponse",
"type": "named"
},
"original_result_type": {
"name": "PetXml",
"type": "named"
}
},
"putPetXmlDistributed": {
Expand Down Expand Up @@ -1470,6 +1536,10 @@
"result_type": {
"name": "PutPetXmlDistributedHeadersResponse",
"type": "named"
},
"original_result_type": {
"name": "PetXml",
"type": "named"
}
}
},
Expand Down
6 changes: 3 additions & 3 deletions ndc-http-schema/configuration/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,9 @@ func cloneOperationInfo(operation rest.OperationInfo, req *rest.Request) rest.Op
}

originalResultType := operation.OriginalResultType
if len(operation.OriginalResultType) == 0 {
originalResultType = operation.ResultType
}
// if len(operation.OriginalResultType) == 0 {
// originalResultType = operation.ResultType
// }

return rest.OperationInfo{
Request: req,
Expand Down
Loading

0 comments on commit 7c70ea9

Please sign in to comment.