diff options
author | Jon Bratseth <bratseth@gmail.com> | 2021-08-24 21:58:47 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2021-08-24 21:58:47 +0200 |
commit | f4e1ac3c1ea67bf1599838764988cf3ad2aa8357 (patch) | |
tree | 0d283426600dec5c30932fdf1b73d5c926f35763 /client | |
parent | fe557fc926fd40305d9f04f9fd749d39cfbc4ea1 (diff) |
Test put id and no id specified
Diffstat (limited to 'client')
-rw-r--r-- | client/go/cmd/document.go | 8 | ||||
-rw-r--r-- | client/go/cmd/document_test.go | 13 | ||||
-rw-r--r-- | client/go/cmd/testdata/A-Head-Full-of-Dreams-With-Put.json | 15 |
3 files changed, 32 insertions, 4 deletions
diff --git a/client/go/cmd/document.go b/client/go/cmd/document.go index f2d7b80289d..1d3cb2feb58 100644 --- a/client/go/cmd/document.go +++ b/client/go/cmd/document.go @@ -77,11 +77,11 @@ func post(documentId string, jsonFile string) { if documentId == "" { var doc map[string]interface{} json.Unmarshal(documentData, &doc) - documentId = doc["id"].(string) - if documentId == "" { + if doc["id"] != nil { + documentId = doc["id"].(string) + } else if doc["put"] != nil { documentId = doc["put"].(string) // document feeder format - } - if documentId == "" { + } else { util.Error("No document id given neither as argument or an 'id' key in the json file") return } diff --git a/client/go/cmd/document_test.go b/client/go/cmd/document_test.go index c3930247dcd..688e9f58080 100644 --- a/client/go/cmd/document_test.go +++ b/client/go/cmd/document_test.go @@ -27,6 +27,19 @@ func TestDocumentPostWithIdInDocumentShortForm(t *testing.T) { "mynamespace/music/docid/1", "testdata/A-Head-Full-of-Dreams-With-Id.json", t) } +func TestDocumentPostWithIdAsPutInDocument(t *testing.T) { + assertDocumentPost([]string{"document", "post", "testdata/A-Head-Full-of-Dreams-With-Put.json"}, + "mynamespace/music/docid/1", "testdata/A-Head-Full-of-Dreams-With-Put.json", t) +} + +func TestDocumentIdNotSpecified(t *testing.T) { + arguments := []string{"document", "post", "testdata/A-Head-Full-of-Dreams.json"} + client := &mockHttpClient{} + assert.Equal(t, + "\x1b[31mNo document id given neither as argument or an 'id' key in the json file\n", + executeCommand(t, client, arguments, []string{})) +} + func TestDocumentPostDocumentError(t *testing.T) { assertDocumentError(t, 401, "Document error") } diff --git a/client/go/cmd/testdata/A-Head-Full-of-Dreams-With-Put.json b/client/go/cmd/testdata/A-Head-Full-of-Dreams-With-Put.json new file mode 100644 index 00000000000..d6467073816 --- /dev/null +++ b/client/go/cmd/testdata/A-Head-Full-of-Dreams-With-Put.json @@ -0,0 +1,15 @@ +{ + "put": "mynamespace/music/docid/1", + "fields": { + "album": "A Head Full of Dreams", + "artist": "Coldplay", + "year": 2015, + "category_scores": { + "cells": [ + { "address" : { "cat" : "pop" }, "value": 1 }, + { "address" : { "cat" : "rock" }, "value": 0.2 }, + { "address" : { "cat" : "jazz" }, "value": 0 } + ] + } + } +} |