Skip to content

Commit

Permalink
Fix datahub tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsparrow committed Mar 11, 2024
1 parent 92a335d commit acd2bde
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ jobs:
pip install poetry
poetry install
poetry run pytest -s . || true
poetry run pytest -s .
docker-compose logs
31 changes: 14 additions & 17 deletions metadata/api/datahub/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ package datahub
import (
"bytes"
"encoding/json"
"fmt"
"io"
"log/slog"
"net/http"
"os"
"strings"

"metadata/ent"

Expand All @@ -20,18 +17,18 @@ type datahubApiServer struct {
log *slog.Logger
}

func writeRequestToFile(data *bytes.Buffer, id string) {
path := ".data/" + strings.ReplaceAll(id, "/", "__") + ".json"
fmt.Println("Writing path", path)
f, err := os.Create(path)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
f.Write(data.Bytes())
f.Close()
// func writeRequestToFile(data *bytes.Buffer, id string) {
// path := ".data/" + strings.ReplaceAll(id, "/", "__") + ".json"
// fmt.Println("Writing path", path)
// f, err := os.Create(path)
// if err != nil {
// fmt.Println(err)
// os.Exit(1)
// }
// f.Write(data.Bytes())
// f.Close()

}
// }

func (i *datahubApiServer) Entities(w http.ResponseWriter, r *http.Request) {
variables := mux.Vars(r)
Expand All @@ -51,8 +48,8 @@ func (i *datahubApiServer) Entities(w http.ResponseWriter, r *http.Request) {

for _, aspect := range req.Entity.Value.DatasetSnapshot.Aspects {
if aspect.SchemaMetadata != nil {
urn, _ := parseDatahubUrn(namespace, req.Entity.Value.DatasetSnapshot.Urn)
writeRequestToFile(&buf, "entity_"+urn.ToString())
// urn, _ := parseDatahubUrn(namespace, req.Entity.Value.DatasetSnapshot.Urn)
// writeRequestToFile(&buf, "entity_"+urn.ToString())
err := aspectHandler.HandleSchemaMetadata(*aspect.SchemaMetadata)

if err != nil {
Expand Down Expand Up @@ -89,7 +86,7 @@ func (i *datahubApiServer) Aspects(w http.ResponseWriter, r *http.Request) {
}

aspectHandler := CreateAspectHandler(req.Proposal.EntityUrn, req.Proposal.SystemMetadata.RunId, namespace, i.client, r.Context(), i.log)
writeRequestToFile(&buf, fmt.Sprintf("aspect_%s_%s", req.Proposal.EntityUrn, req.Proposal.AspectName))
// writeRequestToFile(&buf, fmt.Sprintf("aspect_%s_%s", req.Proposal.EntityUrn, req.Proposal.AspectName))
if err := aspectHandler.HandleJsonAspect(req.Proposal.AspectName, req.Proposal.Aspect.Value); err != nil {
i.log.Error("Error while handling aspect", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down

0 comments on commit acd2bde

Please sign in to comment.