Skip to content

Commit 45d81b8

Browse files
committed
Test for config fingerprint mismatch
1 parent e988a2f commit 45d81b8

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

core/src/test/java/dev/mhh/cloner/RecloneTest.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dev.mhh.cloner;
22

3+
import dev.mhh.cloner.api.CloneConfiguration;
4+
import dev.mhh.cloner.api.CloneError;
35
import dev.mhh.cloner.api.CloneException;
46
import dev.mhh.cloner.api.Cloner;
57
import dev.mhh.cloner.impl.ClonerImpl;
@@ -13,8 +15,7 @@
1315
import java.util.List;
1416

1517
import static dev.mhh.cloner.TestDatabase.*;
16-
import static org.junit.jupiter.api.Assertions.assertEquals;
17-
import static org.junit.jupiter.api.Assertions.assertTrue;
18+
import static org.junit.jupiter.api.Assertions.*;
1819

1920
class RecloneTest {
2021
Cloner<Long> cloner = new ClonerImpl<>();
@@ -125,4 +126,28 @@ int count(final Connection conn, final String sql) throws SQLException {
125126
return rs.getInt(1);
126127
}
127128
}
129+
130+
@Test
131+
void recloneWithADifferentConfigurationFails() throws SQLException, IOException, CloneException {
132+
runTestWithScripts(
133+
List.of("V1__schema.sql", "V2__data.sql"),
134+
List.of("V1__schema.sql"),
135+
this::recloneWithADifferentConfigurationFails
136+
);
137+
}
138+
139+
void recloneWithADifferentConfigurationFails(final Connection exportConn, final Connection importConn) throws IOException, CloneException, SQLException {
140+
final byte[] zipBytes;
141+
try (final var out = new ByteArrayOutputStream()) {
142+
cloner.exportClone(out, exportConn, CLONE_CONFIGURATION, List.of(1L));
143+
zipBytes = out.toByteArray();
144+
}
145+
146+
// First import
147+
try (final var in = new ByteArrayInputStream(zipBytes)) {
148+
final var differentConfiguration = CloneConfiguration.builder("wrong", "wrong", Long.class).build();
149+
final var cloneException = assertThrows(CloneException.class, () -> cloner.importClone(in, importConn, differentConfiguration));
150+
assertEquals(CloneError.CONFIG_FINGERPRINT_MISMATCH, cloneException.error());
151+
}
152+
}
128153
}

0 commit comments

Comments
 (0)