Skip to content

Commit

Permalink
Fix issues with paths in snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
lukfor committed Jun 12, 2024
1 parent 9e01e08 commit 77cad42
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.askimed.nf.test.lang.extensions.util;

import com.askimed.nf.test.lang.extensions.PathExtension;
import groovy.json.JsonGenerator.Converter;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.Vector;

public class PathConverterRaw implements Converter {

@Override
public boolean handles(Class<?> type) {
return true;
}

@Override
public Object convert(Object value, String key) {
Path path = null;
if (value instanceof Path) {
path = (Path) value;
if (!path.toFile().exists()) {
throw new RuntimeException("Path " + path.toString() + " not found.");
}
} else if (value instanceof File) {
path = ((File) value).toPath();
if (!path.toFile().exists()) {
throw new RuntimeException("Path " + path.toString() + " not found.");
}
} else {
path = new File(value.toString()).toPath();

}

if (path.toFile().exists()) {
return path.toFile().getAbsolutePath();
}
return value;
}

}
5 changes: 3 additions & 2 deletions src/main/java/com/askimed/nf/test/util/ObjectUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.askimed.nf.test.lang.extensions.SnapshotFile;
import com.askimed.nf.test.lang.extensions.util.PathConverter;
import com.askimed.nf.test.lang.extensions.util.PathConverterRaw;
import groovy.json.JsonGenerator;
import groovy.json.JsonOutput;
import groovy.json.JsonSlurper;
Expand Down Expand Up @@ -60,10 +61,10 @@ public static JsonGenerator createJsonGenerator() {
}

public static JsonGenerator createJsonGeneratorRaw() {
return new JsonGenerator.Options().excludeFieldsByName("mapping").build();
return new JsonGenerator.Options().excludeFieldsByName("mapping")
.addConverter(new PathConverterRaw()).build();
}


public static Object toMap(Object object) {
JsonGenerator jsonGenerator = createJsonGeneratorRaw();
String json = jsonGenerator.toJson(object);
Expand Down
4 changes: 2 additions & 2 deletions test-data/snapshots/snapshot_transformer.nf.test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
8,
9
],
"value": "1,36",
"value": "1.36",
"files": [
[
"ID,Name,Quantity,Price",
Expand Down Expand Up @@ -49,6 +49,6 @@
"nf-test": "0.9.0-rc2",
"nextflow": "23.04.3"
},
"timestamp": "2024-06-11T16:48:22.553889"
"timestamp": "2024-06-12T17:08:37.459381"
}
}

0 comments on commit 77cad42

Please sign in to comment.