(t *testing.T)
| 30 | } |
| 31 | |
| 32 | func 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 | |
| 88 | func TestConfigToBucketPointName(t *testing.T) { |
| 89 | if base.UnitTestUrlIsWalrus() { |
nothing calls this directly
no test coverage detected