Debian Codegraph @

snapshot_create_repository_test.go

raw
1 // Copyright 2012-present Oliver Eilhard. All rights reserved.
2 // Use of this source code is governed by a MIT-license.
3 // See http://olivere.mit-license.org/license.txt for details.
4
5 package elastic
6
7 import (
8 "encoding/json"
9 "testing"
10 )
11
12 func TestSnapshotPutRepositoryURL(t *testing.T) {
13 client := setupTestClient(t)
14
15 tests := []struct {
16 Repository string
17 Expected string
18 }{
19 {
20 "repo",
21 "/_snapshot/repo",
22 },
23 }
24
25 for _, test := range tests {
26 path, _, err := client.SnapshotCreateRepository(test.Repository).buildURL()
27 if err != nil {
28 t.Fatal(err)
29 }
30 if path != test.Expected {
31 t.Errorf("expected %q; got: %q", test.Expected, path)
32 }
33 }
34 }
35
36 func TestSnapshotPutRepositoryBodyWithSettings(t *testing.T) {
37 client := setupTestClient(t)
38
39 service := client.SnapshotCreateRepository("my_backup")
40 service = service.Type("fs").
41 Settings(map[string]interface{}{
42 "location": "my_backup_location",
43 "compress": false,
44 }).
45 Setting("compress", true).
46 Setting("chunk_size", 16*1024*1024)
47
48 if err := service.Validate(); err != nil {
49 t.Fatal(err)
50 }
51 src, err := service.buildBody()
52 if err != nil {
53 t.Fatal(err)
54 }
55 data, err := json.Marshal(src)
56 if err != nil {
57 t.Fatalf("marshaling to JSON failed: %v", err)
58 }
59 got := string(data)
60 expected := `{"settings":{"chunk_size":16777216,"compress":true,"location":"my_backup_location"},"type":"fs"}`
61 if got != expected {
62 t.Errorf("expected\n%s\n,got:\n%s", expected, got)
63 }
64 }