Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiasac committed Sep 28, 2024
1 parent eb56757 commit 60f2c9b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 20 deletions.
26 changes: 9 additions & 17 deletions connector/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ type mockState struct{}
type mockConnector struct{}

var mockCapabilities = schema.CapabilitiesResponse{
Version: "^0.1.0",
Version: "^0.1.6",
Capabilities: schema.Capabilities{
Query: schema.QueryCapabilities{
Aggregates: schema.LeafCapability{},
Variables: schema.LeafCapability{},
Aggregates: map[string]any{},
Variables: map[string]any{},
},
Relationships: schema.RelationshipCapabilities{
OrderByAggregate: schema.LeafCapability{},
RelationComparisons: schema.LeafCapability{},
Relationships: &schema.RelationshipCapabilities{
OrderByAggregate: map[string]any{},
RelationComparisons: map[string]any{},
},
},
}
Expand Down Expand Up @@ -182,13 +182,6 @@ func httpPostJSON(url string, body any) (*http.Response, error) {
return http.Post(url, "application/json", bytes.NewBuffer(bodyBytes))
}

func assertHTTPResponseStatus(t *testing.T, name string, res *http.Response, statusCode int) {
if res.StatusCode != statusCode {
t.Errorf("\n%s: expected status %d, got %d", name, statusCode, res.StatusCode)
t.FailNow()
}
}

func assertHTTPResponse[B any](t *testing.T, res *http.Response, statusCode int, expectedBody B) {
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
Expand Down Expand Up @@ -305,7 +298,7 @@ func TestServerConnector(t *testing.T) {
t.Errorf("expected no error, got %s", err)
t.FailNow()
}
assertHTTPResponseStatus(t, "GET /health", res, http.StatusOK)
assert.Equal(t, res.StatusCode, http.StatusOK)
})

t.Run("GET /metrics", func(t *testing.T) {
Expand Down Expand Up @@ -334,12 +327,11 @@ func TestServerConnector(t *testing.T) {
}
assertHTTPResponse(t, res, http.StatusOK, schema.QueryResponse{
{
Aggregates: schema.RowSetAggregates{},
Rows: []map[string]any{
{
"id": 1,
"id": float64(1),
"title": "Hello world",
"author_id": 1,
"author_id": float64(1),
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion example/reference/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (mc *Connector) GetCapabilities(configuration *Configuration) schema.Capabi
OrderBy: schema.LeafCapability{},
},
},
Relationships: schema.RelationshipCapabilities{
Relationships: &schema.RelationshipCapabilities{
OrderByAggregate: schema.LeafCapability{},
RelationComparisons: schema.LeafCapability{},
},
Expand Down
2 changes: 1 addition & 1 deletion schema/schema.generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func TestQueryRequest(t *testing.T) {
"bar_count": NewAggregateColumnCount("id", true, []string{"bar"}).Encode(),
},
},
CollectionRelationships: QueryRequestCollectionRelationships{},
},
},
{
Expand Down Expand Up @@ -549,7 +550,7 @@ func TestQueryRequest(t *testing.T) {
},
Predicate: NewExpressionExists(
NewExpressionBinaryComparisonOperator(
*NewComparisonTargetColumn("last_name", nil, nil),
*NewComparisonTargetColumn("last_name", nil, []PathElement{}),
"like",
NewComparisonValueScalar("s"),
),
Expand Down
1 change: 1 addition & 0 deletions typegen/regenerate-schema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fi
schema.generated.json

# patch some custom types because of the limitation of the generation tool
sed -i 's/Relationships interface{}/Relationships *RelationshipCapabilities/g' ../schema/schema.generated.go
sed -i 's/type Field interface{}//g' ../schema/schema.generated.go
sed -i 's/type Argument interface{}//g' ../schema/schema.generated.go
sed -i 's/type RelationshipArgument interface{}//g' ../schema/schema.generated.go
Expand Down

0 comments on commit 60f2c9b

Please sign in to comment.