MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestBootstrapRESTAPISetup

Function TestBootstrapRESTAPISetup

rest/bootstrap_test.go:27–116  ·  view source on GitHub ↗

TestBootstrapRESTAPISetup will bootstrap against a cluster with no databases, and will use the SG REST API to create and persist a database in the cluster. Then Sync Gateway restarts to ensure that a subsequent bootstrap picks up the database created in the first step.

(t *testing.T)

Source from the content-addressed store, hash-verified

25// Then Sync Gateway restarts to ensure that a subsequent bootstrap picks up the
26// database created in the first step.
27func TestBootstrapRESTAPISetup(t *testing.T) {
28 base.SetUpTestLogging(t, base.LevelInfo, base.KeyHTTP)
29
30 config := BootstrapStartupConfigForTest(t) // share config between both servers in test to share a groupID
31 sc, closeFn := StartServerWithConfig(t, &config)
32
33 ctx := base.TestCtx(t)
34
35 // Get a test bucket, and use it to create the database.
36 tb := base.GetTestBucket(t)
37 defer tb.Close(ctx)
38
39 resp := BootstrapAdminRequest(t, sc, http.MethodPut, "/db1/",
40 fmt.Sprintf(
41 `{"bucket": "%s", "num_index_replicas": 0, "enable_shared_bucket_access": %t, "use_views": %t}`,
42 tb.GetName(), base.TestUseXattrs(), base.TestsDisableGSI(),
43 ),
44 )
45 resp.RequireStatus(http.StatusCreated)
46
47 // upsert 1 config field
48 resp = BootstrapAdminRequest(t, sc, http.MethodPost, "/db1/_config",
49 `{"cache": {"rev_cache":{"size":1234}}}`,
50 )
51 resp.RequireStatus(http.StatusCreated)
52
53 resp = BootstrapAdminRequest(t, sc, http.MethodGet, "/db1/", ``)
54 resp.RequireStatus(http.StatusOK)
55 var dbRootResp DatabaseRoot
56 require.NoError(t, base.JSONUnmarshal([]byte(resp.Body), &dbRootResp))
57 assert.Equal(t, "db1", dbRootResp.DBName)
58 assert.Equal(t, db.RunStateString[db.DBOnline], dbRootResp.State)
59
60 // Inspect the config
61 resp = BootstrapAdminRequest(t, sc, http.MethodGet, "/db1/_config", ``)
62 resp.RequireStatus(http.StatusOK)
63 var dbConfigResp DatabaseConfig
64 require.NoError(t, base.JSONUnmarshal([]byte(resp.Body), &dbConfigResp))
65 assert.Equal(t, "db1", dbConfigResp.Name)
66 require.NotNil(t, dbConfigResp.Bucket)
67 assert.Equal(t, tb.GetName(), *dbConfigResp.Bucket)
68 assert.Nil(t, dbConfigResp.Server)
69 assert.Empty(t, dbConfigResp.Username)
70 assert.Empty(t, dbConfigResp.Password)
71 require.Nil(t, dbConfigResp.Sync)
72 require.Equal(t, uint32(1234), *dbConfigResp.CacheConfig.RevCacheConfig.MaxItemCount)
73
74 // Sanity check to use the database
75 resp = BootstrapAdminRequest(t, sc, http.MethodGet, "/db1/doc1", ``)
76 resp.RequireStatus(http.StatusNotFound)
77 resp = BootstrapAdminRequest(t, sc, http.MethodPut, "/db1/doc1", `{"foo":"bar"}`)
78 resp.RequireStatus(http.StatusCreated)
79 require.Contains(t, resp.Body, `"id":"doc1","ok":true`)
80 resp = BootstrapAdminRequest(t, sc, http.MethodGet, "/db1/doc1", ``)
81 resp.RequireStatus(http.StatusOK)
82 assert.Contains(t, resp.Body, `"foo":"bar"`)
83
84 // Restart Sync Gateway

Callers

nothing calls this directly

Calls 14

SetUpTestLoggingFunction · 0.92
TestCtxFunction · 0.92
GetTestBucketFunction · 0.92
TestUseXattrsFunction · 0.92
TestsDisableGSIFunction · 0.92
JSONUnmarshalFunction · 0.92
StartServerWithConfigFunction · 0.85
BootstrapAdminRequestFunction · 0.85
RequireStatusMethod · 0.80
CloseMethod · 0.65
GetNameMethod · 0.65

Tested by

no test coverage detected