Skip to content

Commit

Permalink
add more db-tests to check goal definition type constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
skovati committed Sep 9, 2024
1 parent 76bf92b commit 2199df4
Showing 1 changed file with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -612,5 +612,91 @@ void testCantPartiallyChangeEDSLGoalToProcedure() throws SQLException {
);
}
}

@Test
void testCantHaveEDSLGoalWithoutDefinition() throws SQLException {
try (final var statement = connection.createStatement()) {
final var exception = assertThrowsExactly(
PSQLException.class,
() -> statement.executeUpdate(
//language=sql
"""
update scheduler.scheduling_goal_definition
set definition = null
where goal_id = %d
""".formatted(goalIds[0])
)
);

assertTrue(exception.getMessage().contains(
"new row for relation \"scheduling_goal_definition\" violates check constraint \"check_goal_definition_type_consistency\"")
);
}
}

@Test
void testCantHaveEDSLGoalWithUploadedJarID() throws SQLException {
try (final var statement = connection.createStatement()) {
final var jarId = merlinHelper.insertFileUpload();

final var exception = assertThrowsExactly(
PSQLException.class,
() -> statement.executeUpdate(
//language=sql
"""
update scheduler.scheduling_goal_definition
set uploaded_jar_id = %d
where goal_id = %d
""".formatted(jarId, goalIds[0])
)
);

assertTrue(exception.getMessage().contains(
"new row for relation \"scheduling_goal_definition\" violates check constraint \"check_goal_definition_type_consistency\"")
);
}
}

@Test
void testCantHaveProcedureWithDefinition() throws SQLException {
try (final var statement = connection.createStatement()) {
final var exception = assertThrowsExactly(
PSQLException.class,
() -> statement.executeUpdate(
//language=sql
"""
update scheduler.scheduling_goal_definition
set definition = 'nope'
where goal_id = %d
""".formatted(goalIds[1])
)
);

assertTrue(exception.getMessage().contains(
"new row for relation \"scheduling_goal_definition\" violates check constraint \"check_goal_definition_type_consistency\"")
);
}
}

@Test
void testCantHaveProcedureWithoutUploadedJarId() throws SQLException {
try (final var statement = connection.createStatement()) {
final var exception = assertThrowsExactly(
PSQLException.class,
() -> statement.executeUpdate(
//language=sql
"""
update scheduler.scheduling_goal_definition
set uploaded_jar_id = null
where goal_id = %d
""".formatted(goalIds[1])
)
);

assertTrue(exception.getMessage().contains(
"new row for relation \"scheduling_goal_definition\" violates check constraint \"check_goal_definition_type_consistency\"")
);
}
}
}
}

0 comments on commit 2199df4

Please sign in to comment.