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

Function TestServerlessPollBuckets

rest/serverless_test.go:23–88  ·  view source on GitHub ↗

Tests behaviour of CBG-2257 to poll only buckets in BucketCredentials that don't currently have a database

(t *testing.T)

Source from the content-addressed store, hash-verified

21
22// Tests behaviour of CBG-2257 to poll only buckets in BucketCredentials that don't currently have a database
23func TestServerlessPollBuckets(t *testing.T) {
24 RequireBucketSpecificCredentials(t)
25
26 ctx := base.TestCtx(t)
27 // Get test bucket
28 tb1 := base.GetTestBucket(t)
29 defer tb1.Close(ctx)
30
31 rt := NewRestTester(t, &RestTesterConfig{
32 CustomTestBucket: tb1.NoCloseClone(),
33 serverless: true,
34 PersistentConfig: true,
35 MutateStartupConfig: func(config *StartupConfig) {
36 config.Bootstrap.ConfigUpdateFrequency = base.NewConfigDuration(0)
37 },
38 })
39 defer rt.Close()
40 sc := rt.ServerContext()
41 ctx = rt.Context()
42
43 // Blank out all per-bucket creds
44 perBucketCreds := sc.Config.BucketCredentials
45 rt.ReplacePerBucketCredentials(map[string]*base.CredentialsConfig{})
46
47 // Confirm fetch does not return any configs due to no databases existing
48 configs, err := sc.FetchConfigs(ctx, false)
49 require.NoError(t, err)
50 assert.Empty(t, configs)
51
52 // Create a database
53 rt2 := NewRestTester(t, &RestTesterConfig{CustomTestBucket: tb1.NoCloseClone(), PersistentConfig: true, GroupID: &sc.Config.Bootstrap.ConfigGroupID})
54 defer rt2.Close()
55 // Create a new db on the RT to confirm fetch won't retrieve it (due to bucket not being in BucketCredentials)
56 resp := rt2.SendAdminRequest(http.MethodPut, "/db/", fmt.Sprintf(`{
57 "bucket": "%s",
58 "use_views": %t,
59 "num_index_replicas": 0
60 }`, tb1.GetName(), base.TestsDisableGSI()))
61 RequireStatus(t, resp, http.StatusCreated)
62
63 // Confirm fetch does not return any configs due to no databases in the bucket credentials config
64 configs, err = sc.FetchConfigs(ctx, false)
65 require.NoError(t, err)
66 assert.Empty(t, configs)
67
68 // Add the test bucket to bucket credentials config
69 rt.ReplacePerBucketCredentials(perBucketCreds)
70
71 // Confirm fetch does return config for db in tb1
72 configs, err = sc.FetchConfigs(ctx, false)
73 require.NoError(t, err)
74 require.Len(t, configs, 1)
75 assert.NotNil(t, configs["db"])
76 count, err := sc.fetchAndLoadConfigs(ctx, false)
77 require.NoError(t, err)
78 assert.Equal(t, 1, count)
79
80 // Confirm fetch does not return any configs due to db being known about already (so existing db does not get polled)

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
ServerContextMethod · 0.95
ContextMethod · 0.95
SendAdminRequestMethod · 0.95
TestCtxFunction · 0.92
GetTestBucketFunction · 0.92
NewConfigDurationFunction · 0.92
TestsDisableGSIFunction · 0.92
NewRestTesterFunction · 0.85
RequireStatusFunction · 0.85

Tested by

no test coverage detected