Skip to content

Commit 28396ba

Browse files
committed
start laying foundations for dealing with asymmetric C# examples
1 parent aa97dc3 commit 28396ba

File tree

15 files changed

+97
-55
lines changed

15 files changed

+97
-55
lines changed

src/main/java/com/dtsx/docs/core/planner/meta/snapshot/SnapshotSourcesParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static List<SnapshotSource> parseSources(SnapshotsConfig config) {
6666
sources.add(parser.apply(source, params));
6767
}
6868

69-
return sources.stream().sorted().toList();
69+
return sources;
7070
}
7171

7272
private static <M> BiFunction<String, Map<String, Object>, SnapshotSource> mk(BiFunction<String, M, SnapshotSource> constructor, TypeReference<M> typeRef) {

src/main/java/com/dtsx/docs/core/runner/drivers/ClientDriver.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.dtsx.docs.core.runner.ExecutionEnvironment.TestFileModifierFlags;
88
import com.dtsx.docs.core.runner.RunException;
99
import com.dtsx.docs.core.runner.drivers.impls.*;
10+
import com.dtsx.docs.core.runner.tests.snapshots.verifier.Snapshot;
1011
import com.dtsx.docs.lib.ExternalPrograms.ExternalProgram;
1112
import com.dtsx.docs.lib.ExternalPrograms.RunResult;
1213
import lombok.AllArgsConstructor;
@@ -15,10 +16,7 @@
1516

1617
import java.nio.file.Files;
1718
import java.nio.file.Path;
18-
import java.util.ArrayList;
19-
import java.util.Iterator;
20-
import java.util.List;
21-
import java.util.Map;
19+
import java.util.*;
2220
import java.util.function.Function;
2321

2422
/// A pluggable driver for setting up and running clients of different languages.
@@ -110,7 +108,11 @@ public abstract class ClientDriver {
110108
/// @return the execution result with exit code and output
111109
public abstract RunResult executeScript(BaseScriptRunnerCtx ctx, ExecutionEnvironment execEnv, Map<String, String> envVars);
112110

113-
protected void replaceArtifactPlaceholder(ExecutionEnvironment execEnv, String file) {
111+
public HashMap<Snapshot, Set<Path>> reduceSnapshots(HashMap<Snapshot, Set<Path>> snapshots) {
112+
return snapshots;
113+
}
114+
115+
protected final void replaceArtifactPlaceholder(ExecutionEnvironment execEnv, String file) {
114116
val path = execEnv.envDir().resolve(file);
115117

116118
try {
@@ -122,7 +124,7 @@ protected void replaceArtifactPlaceholder(ExecutionEnvironment execEnv, String f
122124
}
123125
}
124126

125-
protected String artifact() {
127+
protected final String artifact() {
126128
if (artifact == null) {
127129
throw new RunException("Attempted to access artifact for driver that does not use one: " + language() + ". Did *someone* forget to set a default artifact in ClientLanguage?");
128130
}

src/main/java/com/dtsx/docs/core/runner/tests/results/TestOutcome.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.dtsx.docs.core.runner.tests.results;
22

3+
import com.dtsx.docs.core.runner.tests.snapshots.verifier.Snapshot;
34
import com.dtsx.docs.lib.CliLogger;
45
import com.dtsx.docs.core.planner.TestRoot;
56
import com.dtsx.docs.core.runner.drivers.ClientLanguage;
@@ -32,24 +33,24 @@ enum DryPassed implements TestOutcome {
3233
enum Mismatch implements TestOutcome {
3334
INSTANCE;
3435

35-
public Mismatch alsoLog(TestRoot testRoot, ClientLanguage language, Map<String, Set<Path>> differingSnapshots) {
36+
public Mismatch alsoLog(TestRoot testRoot, ClientLanguage language, Map<Snapshot, Set<Path>> differingSnapshots) {
3637
val extra = new StringBuilder("Differing snapshots found for the following files:\n");
3738

38-
for (val entry : differingSnapshots.entrySet()) {
39-
extra.append("Snapshot:\n").append(entry.getKey()).append("\nFiles:\n");
39+
differingSnapshots.forEach((snapshot, paths) -> {
40+
extra.append("Snapshot:\n").append(snapshot).append("\nFiles:\n");
4041

41-
for (val path : entry.getValue()) {
42+
for (val path : paths) {
4243
extra.append(" - ").append(path).append("\n");
4344
}
44-
}
45+
});
4546

4647
logResult(testRoot, language, this, extra.toString());
4748
return this;
4849
}
4950
}
5051

5152
record FailedToVerify(Optional<Path> expected) implements TestOutcome {
52-
public FailedToVerify alsoLog(TestRoot testRoot, ClientLanguage language, String actualSnapshot) {
53+
public FailedToVerify alsoLog(TestRoot testRoot, ClientLanguage language, Snapshot actualSnapshot) {
5354
val prefix = expected
5455
.map((path) -> "Expected snapshot file: " + path)
5556
.orElse("No approved snapshot file found.");

src/main/java/com/dtsx/docs/core/runner/tests/snapshots/sources/SnapshotSource.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,25 @@
55
import com.dtsx.docs.core.planner.fixtures.FixtureMetadata;
66
import com.dtsx.docs.core.runner.PlaceholderVars;
77
import com.dtsx.docs.core.runner.drivers.ClientDriver;
8+
import com.dtsx.docs.core.runner.tests.snapshots.verifier.Snapshot.SnapshotPart;
89
import com.dtsx.docs.core.runner.tests.snapshots.sources.output.OutputCaptureSource;
910
import com.dtsx.docs.core.runner.tests.snapshots.sources.records.RecordSource;
10-
import com.dtsx.docs.core.runner.tests.snapshots.verifier.SnapshotVerifier;
1111
import com.dtsx.docs.lib.ExternalPrograms.RunResult;
12-
import lombok.Getter;
12+
import lombok.EqualsAndHashCode;
1313
import lombok.RequiredArgsConstructor;
1414

1515
import java.util.Optional;
1616
import java.util.function.Supplier;
1717

18-
/// Represents a pluggable source of snapshots based on the run output, or the database state.
19-
///
20-
/// @see RecordSource
21-
/// @see OutputCaptureSource
2218
@RequiredArgsConstructor
2319
public abstract class SnapshotSource implements Comparable<SnapshotSource> {
24-
@Getter
2520
protected final String name;
2621

27-
/// Returns just a string containing the snapshot for this source.
28-
/// Any header/footer or delimiting information is added by the caller.
29-
///
30-
/// @see SnapshotVerifier
31-
public abstract String mkSnapshot(TestCtx ctx, ClientDriver driver, RunResult res, FixtureMetadata md);
22+
public SnapshotPart mkSnapshot(TestCtx ctx, ClientDriver driver, RunResult res, FixtureMetadata md) {
23+
return new SnapshotPart(name, mkSnapshotImpl(ctx, driver, res, md));
24+
}
25+
26+
protected abstract String mkSnapshotImpl(TestCtx ctx, ClientDriver driver, RunResult res, FixtureMetadata md);
3227

3328
@Override
3429
public int compareTo(SnapshotSource other) {

src/main/java/com/dtsx/docs/core/runner/tests/snapshots/sources/output/OutputCaptureSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public OutputCaptureSource(String name, Void ignored) {
1313
}
1414

1515
@Override
16-
public String mkSnapshot(TestCtx ctx, ClientDriver driver, RunResult res, FixtureMetadata md) {
16+
public String mkSnapshotImpl(TestCtx ctx, ClientDriver driver, RunResult res, FixtureMetadata md) {
1717
return SnapshotSourceUtils.extractOutput(name, res);
1818
}
1919
}

src/main/java/com/dtsx/docs/core/runner/tests/snapshots/sources/output/OutputJsonifySource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public OutputJsonifySource(String name, OutputJsonifySourceMeta meta) {
2424
}
2525

2626
@Override
27-
public String mkSnapshot(TestCtx ctx, ClientDriver driver, RunResult res, FixtureMetadata md) {
27+
public String mkSnapshotImpl(TestCtx ctx, ClientDriver driver, RunResult res, FixtureMetadata md) {
2828
val output = SnapshotSourceUtils.extractOutput(name, res);
2929
val rawJsonLines = driver.preprocessToJson(ctx, meta, output);
3030

src/main/java/com/dtsx/docs/core/runner/tests/snapshots/sources/output/OutputMatchesSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public OutputMatchesSource(String name, OutputMatchesSourceMeta meta) {
2020
}
2121

2222
@Override
23-
public String mkSnapshot(TestCtx ctx, ClientDriver driver, RunResult res, FixtureMetadata md) {
23+
public String mkSnapshotImpl(TestCtx ctx, ClientDriver driver, RunResult res, FixtureMetadata md) {
2424
val output = SnapshotSourceUtils.extractOutput(name, res);
2525

2626
if (regex.matcher(output).matches()) {

src/main/java/com/dtsx/docs/core/runner/tests/snapshots/sources/records/RecordSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private Projection[] buildProjection(Map<String, Object> projectionMap) {
106106
protected abstract Stream<Map<String, Object>> streamRecords(TestCtx ctx, String name, String keyspace);
107107

108108
@Override
109-
public String mkSnapshot(TestCtx ctx, ClientDriver driver, RunResult res, FixtureMetadata md) {
109+
public String mkSnapshotImpl(TestCtx ctx, ClientDriver driver, RunResult res, FixtureMetadata md) {
110110
val schemaObjName = resolveName("schema object name", md, driver, overrideName, () -> extractSchemaObjectName(md));
111111
val schemaObjKeyspace = resolveName("keyspace", md, driver, overrideKeyspace, () -> Optional.of(md.keyspaceName()));
112112

src/main/java/com/dtsx/docs/core/runner/tests/snapshots/sources/schema/definitions/SchemaObjectDefinitionSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public SchemaObjectDefinitionSource(String name, WithNameAndKeyspace nameAndKeys
2828
protected abstract Object getDefinition(TestCtx ctx, String name, String keyspace);
2929

3030
@Override
31-
public String mkSnapshot(TestCtx ctx, ClientDriver driver, RunResult res, FixtureMetadata md) {
31+
public String mkSnapshotImpl(TestCtx ctx, ClientDriver driver, RunResult res, FixtureMetadata md) {
3232
val schemaObjName = resolveName("schema object name", md, driver, overrideName, () -> extractSchemaObjectName(md));
3333
val schemaObjKeyspace = resolveName("keyspace", md, driver, overrideKeyspace, () -> Optional.of(md.keyspaceName()));
3434

src/main/java/com/dtsx/docs/core/runner/tests/snapshots/sources/schema/definitions/TableIndexDefinitionsSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public TableIndexDefinitionsSource(String name, TableIndexDefinitionSourceMeta m
3333
}
3434

3535
@Override
36-
public String mkSnapshot(TestCtx ctx, ClientDriver driver, RunResult res, FixtureMetadata md) {
36+
public String mkSnapshotImpl(TestCtx ctx, ClientDriver driver, RunResult res, FixtureMetadata md) {
3737
val tableName = resolveName("table name", md, driver, overrideName, md::tableName);
3838

3939
val table = DataAPIUtils.getTable(

0 commit comments

Comments
 (0)