diff options
author | Christopher Speller <crspeller@gmail.com> | 2017-07-20 15:22:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-20 15:22:49 -0700 |
commit | 58839cefb50e56ae5b157b37e9814ae83ceee70b (patch) | |
tree | 5de966481678096fc9567f74f96673b34a65127c /vendor/gopkg.in/olivere/elastic.v5/update_test.go | |
parent | e2f4492eadb5d3c58606b1fdd5774b63a07c236a (diff) | |
download | chat-58839cefb50e56ae5b157b37e9814ae83ceee70b.tar.gz chat-58839cefb50e56ae5b157b37e9814ae83ceee70b.tar.bz2 chat-58839cefb50e56ae5b157b37e9814ae83ceee70b.zip |
Upgrading server dependancies (#6984)
Diffstat (limited to 'vendor/gopkg.in/olivere/elastic.v5/update_test.go')
-rw-r--r-- | vendor/gopkg.in/olivere/elastic.v5/update_test.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/vendor/gopkg.in/olivere/elastic.v5/update_test.go b/vendor/gopkg.in/olivere/elastic.v5/update_test.go index 79fe415dd..8801bacb2 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/update_test.go +++ b/vendor/gopkg.in/olivere/elastic.v5/update_test.go @@ -5,6 +5,7 @@ package elastic import ( + "context" "encoding/json" "net/url" "testing" @@ -231,3 +232,70 @@ func TestUpdateViaDocAndUpsert(t *testing.T) { t.Errorf("expected\n%s\ngot:\n%s", expected, got) } } + +func TestUpdateViaDocAndUpsertAndFetchSource(t *testing.T) { + client := setupTestClient(t) + update := client.Update(). + Index("test").Type("type1").Id("1"). + Doc(map[string]interface{}{"name": "new_name"}). + DocAsUpsert(true). + Timeout("1s"). + Refresh("true"). + FetchSource(true) + path, params, err := update.url() + if err != nil { + t.Fatalf("expected to return URL, got: %v", err) + } + expectedPath := `/test/type1/1/_update` + if expectedPath != path { + t.Errorf("expected URL path\n%s\ngot:\n%s", expectedPath, path) + } + expectedParams := url.Values{ + "refresh": []string{"true"}, + "timeout": []string{"1s"}, + } + if expectedParams.Encode() != params.Encode() { + t.Errorf("expected URL parameters\n%s\ngot:\n%s", expectedParams.Encode(), params.Encode()) + } + body, err := update.body() + if err != nil { + t.Fatalf("expected to return body, got: %v", err) + } + data, err := json.Marshal(body) + if err != nil { + t.Fatalf("expected to marshal body as JSON, got: %v", err) + } + got := string(data) + expected := `{"_source":true,"doc":{"name":"new_name"},"doc_as_upsert":true}` + if got != expected { + t.Errorf("expected\n%s\ngot:\n%s", expected, got) + } +} + +func TestUpdateAndFetchSource(t *testing.T) { + client := setupTestClientAndCreateIndexAndAddDocs(t) // , SetTraceLog(log.New(os.Stdout, "", 0))) + res, err := client.Update(). + Index(testIndexName).Type("tweet").Id("1"). + Doc(map[string]interface{}{"user": "sandrae"}). + DetectNoop(true). + FetchSource(true). + Do(context.Background()) + if err != nil { + t.Fatal(err) + } + if res == nil { + t.Fatal("expected response != nil") + } + if res.GetResult == nil { + t.Fatal("expected GetResult != nil") + } + data, err := json.Marshal(res.GetResult.Source) + if err != nil { + t.Fatalf("expected to marshal body as JSON, got: %v", err) + } + got := string(data) + expected := `{"user":"sandrae","message":"Welcome to Golang and Elasticsearch.","retweets":0,"created":"0001-01-01T00:00:00Z"}` + if got != expected { + t.Errorf("expected\n%s\ngot:\n%s", expected, got) + } +} |