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

Function TestDbConfigUpdatedAtField

rest/config_database_test.go:32–86  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

30}
31
32func TestDbConfigUpdatedAtField(t *testing.T) {
33 b := base.GetTestBucket(t)
34 rt := NewRestTester(t, &RestTesterConfig{
35 CustomTestBucket: b,
36 PersistentConfig: true,
37 })
38 defer rt.Close()
39 ctx := base.TestCtx(t)
40
41 dbConfig := rt.NewDbConfig()
42 RequireStatus(t, rt.CreateDatabase("db1", dbConfig), http.StatusCreated)
43
44 sc := rt.ServerContext()
45
46 resp := rt.SendAdminRequest(http.MethodGet, "/db1/_config", "")
47 RequireStatus(t, resp, http.StatusOK)
48 var unmarshaledConfig DbConfig
49 require.NoError(t, json.Unmarshal(resp.BodyBytes(), &unmarshaledConfig))
50
51 registry := &GatewayRegistry{}
52 bName := b.GetName()
53 _, err := sc.BootstrapContext.Connection.GetMetadataDocument(ctx, bName, base.SGRegistryKey, registry)
54 require.NoError(t, err)
55
56 // Check that the config has an updatedAt field
57 require.NotNil(t, unmarshaledConfig.UpdatedAt)
58 require.NotNil(t, unmarshaledConfig.CreatedAt)
59 currUpdatedTime := unmarshaledConfig.UpdatedAt
60 currCreatedTime := unmarshaledConfig.CreatedAt
61 registryUpdated := registry.UpdatedAt
62 registryCreated := registry.CreatedAt
63
64 // avoid flake where update at seems to be the same (possibly running to fast)
65 time.Sleep(500 * time.Nanosecond)
66
67 // Update the config
68 dbConfig = rt.NewDbConfig()
69 RequireStatus(t, rt.UpsertDbConfig("db1", dbConfig), http.StatusCreated)
70
71 resp = rt.SendAdminRequest(http.MethodGet, "/db1/_config", "")
72 RequireStatus(t, resp, http.StatusOK)
73 unmarshaledConfig = DbConfig{}
74 require.NoError(t, json.Unmarshal(resp.BodyBytes(), &unmarshaledConfig))
75
76 registry = &GatewayRegistry{}
77 _, err = sc.BootstrapContext.Connection.GetMetadataDocument(ctx, b.GetName(), base.SGRegistryKey, registry)
78 require.NoError(t, err)
79
80 // asser that the db config timestamps are as expected
81 assert.Greater(t, unmarshaledConfig.UpdatedAt.UnixNano(), currUpdatedTime.UnixNano())
82 assert.Equal(t, unmarshaledConfig.CreatedAt.UnixNano(), currCreatedTime.UnixNano())
83 // assert that registry timestamps are as expected
84 assert.Equal(t, registry.CreatedAt.UnixNano(), registryCreated.UnixNano())
85 assert.Greater(t, registry.UpdatedAt.UnixNano(), registryUpdated.UnixNano())
86}
87
88func TestConfigToBucketPointName(t *testing.T) {
89 if base.UnitTestUrlIsWalrus() {

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
NewDbConfigMethod · 0.95
CreateDatabaseMethod · 0.95
ServerContextMethod · 0.95
SendAdminRequestMethod · 0.95
UpsertDbConfigMethod · 0.95
GetTestBucketFunction · 0.92
TestCtxFunction · 0.92
NewRestTesterFunction · 0.85
RequireStatusFunction · 0.85
GetNameMethod · 0.65
GetMetadataDocumentMethod · 0.65

Tested by

no test coverage detected