Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiasac committed Mar 21, 2024
1 parent 8da44be commit 120f919
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.PHONY: format
format:
gofmt -w -s .

.PHONY: test
test:
go test -v -race -timeout 3m ./...

# Install golangci-lint tool to run lint locally
# https://golangci-lint.run/usage/install
.PHONY: lint
lint:
golangci-lint run
27 changes: 10 additions & 17 deletions rest/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"log/slog"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -90,7 +89,6 @@ func TestRESTConnector_configurationFailure(t *testing.T) {
func TestRESTConnector_authentication(t *testing.T) {
apiKey := "random_api_key"
bearerToken := "random_bearer_token"
slog.SetLogLoggerLevel(slog.LevelDebug)
server := createMockServer(t, apiKey, bearerToken)
defer server.Close()

Expand Down Expand Up @@ -132,26 +130,21 @@ func TestRESTConnector_authentication(t *testing.T) {

t.Run("auth_api_key", func(t *testing.T) {
reqBody := []byte(`{
"operation": "addPet",
"query": {
"fields": {
"__value": {
"type": "column",
"column": "__value"
}
"operations": [
{
"type": "procedure",
"name": "addPet",
"arguments": {}
}
},
"arguments": {},
],
"collection_relationships": {}
}`)

res, err := http.Post(fmt.Sprintf("%s/mutation", testServer.URL), "application/json", bytes.NewBuffer(reqBody))
assertNoError(t, err)
assertHTTPResponse(t, res, http.StatusOK, schema.QueryResponse{
{
Rows: []map[string]any{
{"__value": map[string]any{}},
},
assertHTTPResponse(t, res, http.StatusOK, schema.MutationResponse{
OperationResults: []schema.MutationOperationResults{
schema.NewProcedureResult(map[string]any{}).Encode(),
},
})
})
Expand Down Expand Up @@ -256,7 +249,7 @@ func test_createServer(t *testing.T, dir string) *connector.Server[Configuration
c := NewRESTConnector()
server, err := connector.NewServer(c, &connector.ServerOptions{
Configuration: dir,
})
}, connector.WithoutRecovery())
if err != nil {
t.Errorf("failed to start server: %s", err)
t.FailNow()
Expand Down
2 changes: 0 additions & 2 deletions rest/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package rest

import (
"fmt"
"log"
"net/url"
"strings"

Expand Down Expand Up @@ -100,7 +99,6 @@ func (rm RESTMetadata) buildURL(endpoint string) string {
}

func (rm RESTMetadata) applySecurity(req *rest.Request) (*rest.Request, error) {
log.Println("security", req.URL, req.Security)
if req.Security.IsEmpty() {
req.Security = rm.settings.Security
}
Expand Down

0 comments on commit 120f919

Please sign in to comment.