Skip to content

Commit

Permalink
fix(DatasetRef): update to allow hashes, and fix bugs that PeerID int…
Browse files Browse the repository at this point in the history
…roduced

Merge pull request #303 from qri-io/hashClean
  • Loading branch information
b5 authored Mar 8, 2018
2 parents 18a7fe9 + 45b7b98 commit d6d683d
Show file tree
Hide file tree
Showing 18 changed files with 24,665 additions and 42 deletions.
14 changes: 8 additions & 6 deletions api/datasets.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (h *DatasetHandlers) ZipDatasetHandler(w http.ResponseWriter, r *http.Reque
}

func (h *DatasetHandlers) zipDatasetHandler(w http.ResponseWriter, r *http.Request) {
args, err := DatasetRefFromPath(r.URL.Path[len("/export/"):])
args, err := DatasetRefFromPath(r.URL.Path[len("/export"):])
if err != nil {
util.WriteErrResponse(w, http.StatusBadRequest, err)
return
Expand Down Expand Up @@ -208,10 +208,12 @@ func (h *DatasetHandlers) getHandler(w http.ResponseWriter, r *http.Request) {
util.WriteErrResponse(w, http.StatusBadRequest, err)
return
}
if args.Name == "" {
util.WriteErrResponse(w, http.StatusBadRequest, errors.New("no dataset name or hash given"))

if err = repo.CanonicalizeDatasetRef(h.repo, &args); err != nil {
util.WriteErrResponse(w, http.StatusInternalServerError, err)
return
}

err = h.Get(&args, res)
if err != nil {
util.WriteErrResponse(w, http.StatusInternalServerError, err)
Expand Down Expand Up @@ -382,7 +384,7 @@ func (h *DatasetHandlers) initHandler(w http.ResponseWriter, r *http.Request) {
}

func (h *DatasetHandlers) addHandler(w http.ResponseWriter, r *http.Request) {
ref, err := DatasetRefFromPath(r.URL.Path[len("/add/"):])
ref, err := DatasetRefFromPath(r.URL.Path[len("/add"):])
if err != nil {
util.WriteErrResponse(w, http.StatusBadRequest, err)
return
Expand Down Expand Up @@ -507,7 +509,7 @@ func (h *DatasetHandlers) saveHandler(w http.ResponseWriter, r *http.Request) {
}

func (h *DatasetHandlers) removeHandler(w http.ResponseWriter, r *http.Request) {
p, err := DatasetRefFromPath(r.URL.Path[len("/remove/"):])
p, err := DatasetRefFromPath(r.URL.Path[len("/remove"):])
if err != nil {
util.WriteErrResponse(w, http.StatusBadRequest, err)
return
Expand All @@ -525,7 +527,7 @@ func (h *DatasetHandlers) removeHandler(w http.ResponseWriter, r *http.Request)
return
}

util.WriteResponse(w, ref.Dataset)
util.WriteResponse(w, ref)
}

// RenameReqParams is an encoding struct
Expand Down
6 changes: 3 additions & 3 deletions api/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ func (h *HistoryHandlers) LogHandler(w http.ResponseWriter, r *http.Request) {
}

func (h *HistoryHandlers) logHandler(w http.ResponseWriter, r *http.Request) {
args, err := DatasetRefFromPath(r.URL.Path[len("/history/"):])
args, err := DatasetRefFromPath(r.URL.Path[len("/history"):])
if err != nil {
util.WriteErrResponse(w, http.StatusBadRequest, err)
return
}

if args.Name == "" {
util.WriteErrResponse(w, http.StatusBadRequest, fmt.Errorf("name of dataset needed"))
if args.Name == "" && args.Path == "" {
util.WriteErrResponse(w, http.StatusBadRequest, fmt.Errorf("name of dataset or path needed"))
return
}

Expand Down
6 changes: 2 additions & 4 deletions api/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,13 @@ func (mh *RootHandler) Handler(w http.ResponseWriter, r *http.Request) {
}

res := repo.DatasetRef{}

err := mh.dsh.Get(&ref, &res)
if err != nil {
util.WriteErrResponse(w, http.StatusInternalServerError, err)
return
}
if res.Name == "" {
util.WriteErrResponse(w, http.StatusNotFound, errors.New("cannot find peer dataset"))
return
}

if res.IsEmpty() {
util.WriteErrResponse(w, http.StatusNotFound, errors.New("cannot find peer dataset"))
return
Expand Down
24 changes: 24 additions & 0 deletions api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,44 @@ func TestServerRoutes(t *testing.T) {
}{
{"GET", "/status", "", "statusResponse.json", 200},
{"GET", "/list", "", "listResponse.json", 200},

// profile
{"POST", "/profile", "profileRequest.json", "profileResponse.json", 200},
{"GET", "/profile", "", "profileResponse.json", 200},
{"GET", "/me", "", "profileResponse.json", 200},

{"POST", "/add", "addRequestFromURL.json", "addResponseFromURL.json", 200},

// get dataset
{"GET", "/me/family_relationships", "", "getResponseFamilyRelationships.json", 200},
{"GET", "/me/family_relationships/at/map/QmfMTGQKjCcy5nEJwMCQNaqNHVGFTyMdhvWk9pQUXSBD3Z", "", "getResponseFamilyRelationships.json", 200},
{"GET", "/at/map/QmfMTGQKjCcy5nEJwMCQNaqNHVGFTyMdhvWk9pQUXSBD3Z", "", "getResponseFamilyRelationships.json", 200},

{"POST", "/rename", "renameRequest.json", "renameResponse.json", 200},

{"GET", "/export/me/cities", "", "", 200},

{"POST", "/save/me/cities", "saveMetaRequest.json", "saveMetaResponse.json", 200},

// history
{"GET", "/history/me/cities", "", "historyResponse.json", 200},
{"GET", "/history/me/cities/at/map/QmVZJTaRsiSc5UkpBSzH4yFQXvKKWGkjvGh5rNzueWDNQa", "", "historyResponsePath.json", 200},
{"GET", "/history/at/map/QmY6DkbrhHEBSMb1DqqPSUhuVo3BoNadAEGDxSveBZKDrk", "", "historyResponseAt.json", 200},

{"GET", "/export/me/cities", "", "", 200},
{"GET", "/export/me/cities/at/map/QmVZJTaRsiSc5UkpBSzH4yFQXvKKWGkjvGh5rNzueWDNQa", "", "", 200},
{"GET", "/export/at/map/QmVZJTaRsiSc5UkpBSzH4yFQXvKKWGkjvGh5rNzueWDNQa", "", "", 200},

// diff
{"GET", "/diff", "diffRequest.json", "diffResponse.json", 200},
{"GET", "/diff", "diffRequestPlusMinusColor.json", "diffResponsePlusMinusColor.json", 200},

// remove
{"POST", "/remove/me/cities/at/map/QmY6DkbrhHEBSMb1DqqPSUhuVo3BoNadAEGDxSveBZKDrk", "", "removeResponseWithPath.json", 200},
{"POST", "/remove/at/map/QmRLpDXcrccTzNCwWXyyHRZCmSzDxPoMX91KtLW3szmmkX", "", "removeResponseByPath.json", 200},

{"GET", "/connect/", "", "", 400},

// blatently checking all options for easy test coverage bump
{"OPTIONS", "/add", "", "", 200},
{"OPTIONS", "/add/", "", "", 200},
Expand Down
2 changes: 1 addition & 1 deletion api/testdata/diffRequest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"left":"me/cities@/map/QmQyHfc5iro93F5caS9XhkzEf5o6uq1Zz2jxc3Qu2cWNP2", "right":"me/cities@/map/QmY6DkbrhHEBSMb1DqqPSUhuVo3BoNadAEGDxSveBZKDrk"}
{"left":"me/cities@/map/QmbnworAqqiMBGRoQGfnseRJmsK31UGSAFtWD3Doh4b6xq", "right":"me/cities@/map/QmVZJTaRsiSc5UkpBSzH4yFQXvKKWGkjvGh5rNzueWDNQa"}
2 changes: 1 addition & 1 deletion api/testdata/diffRequestPlusMinusColor.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"left":"me/cities@/map/QmQyHfc5iro93F5caS9XhkzEf5o6uq1Zz2jxc3Qu2cWNP2", "right":"me/cities@/map/QmY6DkbrhHEBSMb1DqqPSUhuVo3BoNadAEGDxSveBZKDrk","format":"plusMinusColor"}
{"left":"me/cities@/map/QmbnworAqqiMBGRoQGfnseRJmsK31UGSAFtWD3Doh4b6xq", "right":"me/cities@/map/QmVZJTaRsiSc5UkpBSzH4yFQXvKKWGkjvGh5rNzueWDNQa","format":"plusMinusColor"}
48 changes: 46 additions & 2 deletions api/testdata/diffResponse.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,54 @@
},
{
"Position": "title",
"Value": "Updated Title"
"Value": "test title"
}
],
"structure": []
"structure": [
{
"Position": "checksum",
"OldValue": "QmVYgdpvgnq3FABZFVWUgxr7UCwNSRJz97vBU9YX5g5pQ4",
"NewValue": "QmY3dTEQLQFe3VTMi646N5NK2TRijPtCS2fi85z72owHPD",
"Diff": [
{}
]
},
{
"Position": "entries",
"OldValue": 5,
"NewValue": 6
},
{
"Position": "length",
"OldValue": 154,
"NewValue": 186
},
{
"Position": "schema",
"Deltas": [
{
"Position": "items",
"Deltas": [
{
"Position": "items",
"Deltas": [
{
"Position": 3,
"Deltas": [
{
"Position": "type",
"OldValue": "boolean",
"NewValue": "string"
}
]
}
]
}
]
}
]
}
]
},
"meta": {
"code": 200
Expand Down
2 changes: 1 addition & 1 deletion api/testdata/diffResponsePlusMinusColor.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"data": " {\n \"description\": \"test description\",\n\u001b[30;41m- \"keywords\": null,\u001b[0m\n\u001b[30;42m+ \"keywords\": [\u001b[0m\n\u001b[30;42m+ : \"keyword1\",\u001b[0m\n\u001b[30;42m+ : \"keyword2\"\u001b[0m\n\u001b[30;42m+ ],\u001b[0m\n \"license\": {\n \"type\": \"\",\n \"url\": \"\"\n },\n \"qri\": \"md:0\"\n\u001b[30;42m+ \"title\": \"Updated Title\"\u001b[0m\n }\n",
"data": " {\n\u001b[30;41m- \"checksum\": \"QmVYgdpvgnq3FABZFVWUgxr7UCwNSRJz97vBU9YX5g5pQ4\",\u001b[0m\n\u001b[30;42m+ \"checksum\": \"QmY3dTEQLQFe3VTMi646N5NK2TRijPtCS2fi85z72owHPD\",\u001b[0m\n\u001b[30;41m- \"entries\": 5,\u001b[0m\n\u001b[30;42m+ \"entries\": 6,\u001b[0m\n \"errCount\": 1,\n \"format\": \"csv\",\n \"formatConfig\": {\n \"headerRow\": true\n },\n\u001b[30;41m- \"length\": 154,\u001b[0m\n\u001b[30;42m+ \"length\": 186,\u001b[0m\n \"qri\": \"st:0\",\n \"schema\": {\n \"items\": {\n \"items\": [\n 0: {\n \"title\": \"city\",\n \"type\": \"string\"\n },\n 1: {\n \"title\": \"pop\",\n \"type\": \"integer\"\n },\n 2: {\n \"title\": \"avg_age\",\n \"type\": \"number\"\n },\n 3: {\n \"title\": \"in_usa\",\n\u001b[30;41m- \"type\": \"boolean\"\u001b[0m\n\u001b[30;42m+ \"type\": \"string\"\u001b[0m\n }\n ],\n \"type\": \"array\"\n },\n \"type\": \"array\"\n }\n }\n",
"meta": {
"code": 200
}
Expand Down
Loading

0 comments on commit d6d683d

Please sign in to comment.