(t *testing.T)
| 49 | } |
| 50 | |
| 51 | func TestComputeMetadataID(t *testing.T) { |
| 52 | |
| 53 | if base.UnitTestUrlIsWalrus() { |
| 54 | t.Skip("This test only works against Couchbase Server - requires bootstrap support") |
| 55 | } |
| 56 | |
| 57 | base.TestRequiresCollections(t) |
| 58 | // Start SG with no databases |
| 59 | config := BootstrapStartupConfigForTest(t) |
| 60 | ctx := base.TestCtx(t) |
| 61 | sc, err := SetupServerContext(ctx, &config, true) |
| 62 | require.NoError(t, err) |
| 63 | defer func() { |
| 64 | sc.Close(ctx) |
| 65 | }() |
| 66 | |
| 67 | bootstrapContext := sc.BootstrapContext |
| 68 | |
| 69 | // Get a test bucket for bootstrap testing |
| 70 | tb := base.GetTestBucket(t) |
| 71 | defer func() { |
| 72 | fmt.Println("closing test bucket") |
| 73 | tb.Close(ctx) |
| 74 | }() |
| 75 | bucketName := tb.GetName() |
| 76 | |
| 77 | registry, err := bootstrapContext.getGatewayRegistry(ctx, bucketName) |
| 78 | require.NoError(t, err) |
| 79 | |
| 80 | dbName := "dbName" |
| 81 | standardMetadataID := dbName |
| 82 | |
| 83 | defaultVersion := "1-abc" |
| 84 | defaultDbConfig := makeDbConfig(tb.GetName(), dbName, nil) |
| 85 | |
| 86 | // Use defaultMetadataID if database targets the default collection |
| 87 | metadataID := bootstrapContext.computeMetadataID(ctx, registry, &defaultDbConfig) |
| 88 | assert.Equal(t, defaultMetadataID, metadataID) |
| 89 | |
| 90 | // Set _sync:seq in default collection, verify computeMetadataID still returns default ID |
| 91 | defaultStore := tb.Bucket.DefaultDataStore() |
| 92 | syncSeqKey := base.DefaultMetadataKeys.SyncSeqKey() |
| 93 | _, err = defaultStore.Incr(syncSeqKey, 1, 0, 0) |
| 94 | require.NoError(t, err) |
| 95 | |
| 96 | metadataID = bootstrapContext.computeMetadataID(ctx, registry, &defaultDbConfig) |
| 97 | assert.Equal(t, defaultMetadataID, metadataID) |
| 98 | |
| 99 | // Add another database to the registry already using defaultMetadataID |
| 100 | existingDbName := "existingDb" |
| 101 | existingDbConfig := makeDbConfig(tb.GetName(), existingDbName, nil) |
| 102 | existingDatabaseConfig := &DatabaseConfig{ |
| 103 | DbConfig: existingDbConfig, |
| 104 | Version: defaultVersion, |
| 105 | MetadataID: defaultMetadataID, |
| 106 | } |
| 107 | _, err = registry.upsertDatabaseConfig(ctx, t.Name(), existingDatabaseConfig) |
| 108 | require.NoError(t, err) |
nothing calls this directly
no test coverage detected