Skip to content

Commit

Permalink
Add YAML assertions (#52)
Browse files Browse the repository at this point in the history
Co-authored-by: i.pieniak <[email protected]>
  • Loading branch information
ivopieniak and i.pieniak authored Nov 4, 2022
1 parent c1365f2 commit 05a89cd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
19 changes: 17 additions & 2 deletions docs/assertions/files.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,27 @@ assert path(process.out.out_ch.get(0)).md5 == "64debea5017a035ddc67c0b51fa84b16"
```

## JSON Files
nf-test supports comparison of JSON files and keys within JSON files.
To assert that two JSON files contain the same keys and values:
```Groovy
assert path(process.out.out_ch.get(0)).json == path('./some.json').json
```
Individual keys can also be asserted:

nf-test extends `path` by a `json` property that can be used to read json files:
```Groovy
assert path(process.out.out_ch.get(0)).json.key == "value"
```

## YAML Files
nf-test supports comparison of YAML files and keys within YAML files.
To assert that two YAML files contain the same keys and values:
```Groovy
assert path(process.out.out_ch.get(0)).yaml == path('./some.yaml').yaml
```
Individual keys can also be asserted:

```Groovy
assert path(process.out.out_ch.get(0)).json.key == "value"
assert path(process.out.out_ch.get(0)).yaml.key == "value"
```

## GZip Files
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
<version>3.0.9</version>
</dependency>

<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-yaml</artifactId>
<version>3.0.9</version>
</dependency>

<dependency>
<groupId>org.apache.ivy</groupId>
<artifactId>ivy</artifactId>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/askimed/nf/test/core/AbstractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public abstract class AbstractTest implements ITest {
public static String[] SHARED_DIRECTORIES = { "bin", "lib" };

protected File config = null;

private boolean updateSnapshot = false;

public AbstractTest() {

}

public void config(String config) {
this.config = new File(config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.askimed.nf.test.util.FileUtil;

import groovy.json.JsonSlurper;
import groovy.yaml.YamlSlurper;


public class PathExtension {

Expand Down Expand Up @@ -45,6 +47,13 @@ public static Object getJson(Path self) throws FileNotFoundException, IOExceptio
return readJSON(self);
}

/* YAML */

public static Object getYaml(Path self) throws FileNotFoundException, IOException {
YamlSlurper YamlSlurper = new YamlSlurper();
return YamlSlurper.parse(self);
}

/* File methods */

public static Path[] list(Path self) {
Expand Down

0 comments on commit 05a89cd

Please sign in to comment.