Skip to content

Commit

Permalink
Add failing test to show #1469
Browse files Browse the repository at this point in the history
  • Loading branch information
tatu-at-datastax committed Sep 27, 2024
1 parent 3d4cf3e commit 260d568
Showing 1 changed file with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,32 @@ public String getFeatureFlagTables() {
@Test
public void failCreateWithoutFeatureEnabled() {
DataApiCommandSenders.assertNamespaceCommand(keyspaceName)
.postCreateTable(simpleTableDef(TABLE_TO_CREATE))
.postCreateTable(simpleValidTableDef(TABLE_TO_CREATE))
.hasSingleApiError(ErrorCodeV1.TABLE_FEATURE_NOT_ENABLED);
}

// But with header override, should succeed
// And should also fail with invalid definition
@Order(2)
@Test
public void failInvalidCreateWithoutFeatureEnabled() {
DataApiCommandSenders.assertNamespaceCommand(keyspaceName)
.postCreateTable(invalidTableDef(TABLE_TO_CREATE))
.hasSingleApiError(ErrorCodeV1.TABLE_FEATURE_NOT_ENABLED);
}

// But with header override, should succeed
@Order(3)
@Test
public void okCreateWithFeatureEnabledViaHeader() {
DataApiCommandSenders.assertNamespaceCommand(keyspaceName)
.header(ApiFeature.TABLES.httpHeaderName(), "true")
.postCreateTable(simpleTableDef(TABLE_TO_CREATE))
.postCreateTable(simpleValidTableDef(TABLE_TO_CREATE))
.hasNoErrors()
.body("status.ok", is(1));
}

// But even with table, find() should fail without Feature enabled
@Order(3)
@Order(4)
@Test
public void failFindWithoutFeature() {
DataApiCommandSenders.assertTableCommand(keyspaceName, TABLE_TO_CREATE)
Expand All @@ -67,7 +76,7 @@ public void failFindWithoutFeature() {
}

// And finally, with header override, should succeed in findOne()
@Order(4)
@Order(5)
@Test
public void okFindWithFeatureEnabledViaHeader() {
DataApiCommandSenders.assertTableCommand(keyspaceName, TABLE_TO_CREATE)
Expand All @@ -76,20 +85,28 @@ public void okFindWithFeatureEnabledViaHeader() {
.hasNoErrors();
}

private static String simpleTableDef(String tableName) {
private static String simpleValidTableDef(String tableName) {
return tableDef(tableName, "text");
}

private static String invalidTableDef(String tableName) {
return tableDef(tableName, "not_a_valid_cql_type");
}

private static String tableDef(String tableName, String nameType) {
return
"""
{
"name": "%s",
"definition": {
"columns": {
"id": { "type": "text" },
"name": { "type": "text" }
"name": { "type": "%s" }
},
"primaryKey": "id"
}
}
"""
.formatted(tableName);
.formatted(tableName, nameType);
}
}

0 comments on commit 260d568

Please sign in to comment.