Skip to content

Commit

Permalink
Reimplement integration tests to be OS independent
Browse files Browse the repository at this point in the history
  • Loading branch information
baloo42 committed May 30, 2024
1 parent 06d27fd commit f216529
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@
* limitations under the License.
*/
import io.fabric8.crd.generator.maven.plugin.Verify
import java.nio.file.Path
Path basedirPath = basedir.toPath();


[
"multiples.sample.fabric8.io-v1"
].each {
Verify.verifyContentEquals(
new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml",it)),
new File(basedir, sprintf("/expected/%s.yml",it)))
basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml")),
basedirPath.resolve(Path.of("expected", it + ".yml")))
}

[
"mycustomresources.other.sample.fabric8.io-v1"
].each {
Verify.verifyAbsent(new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml", it)))
Verify.verifyAbsent(basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml")))
}

true
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@
* limitations under the License.
*/
import io.fabric8.crd.generator.maven.plugin.Verify
import java.nio.file.Path
Path basedirPath = basedir.toPath();


[
"multiples.sample.fabric8.io-v1",
"mycustomresources.other.sample.fabric8.io-v1"
].each {
Verify.verifyContentEquals(
new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml",it)),
new File(basedir, sprintf("/expected/%s.yml",it)))
basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml")),
basedirPath.resolve(Path.of("expected", it + ".yml")))
}

true
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@
* limitations under the License.
*/
import io.fabric8.crd.generator.maven.plugin.Verify
import java.nio.file.Path
Path basedirPath = basedir.toPath();


[
"multiples.sample.fabric8.io-v1"
].each {
Verify.verifyContentEquals(
new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml",it)),
new File(basedir, sprintf("/expected/%s.yml",it)))
basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml")),
basedirPath.resolve(Path.of("expected", it + ".yml")))
}

[
"mycustomresources.other.sample.fabric8.io-v1"
].each {
Verify.verifyAbsent(new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml", it)))
Verify.verifyAbsent(basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml")))
}

true
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@
* limitations under the License.
*/
import io.fabric8.crd.generator.maven.plugin.Verify
import java.nio.file.Path
Path basedirPath = basedir.toPath();


[
"mycustomresources.other.sample.fabric8.io-v1"
].each {
Verify.verifyContentEquals(
new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml",it)),
new File(basedir, sprintf("/expected/%s.yml",it)))
basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml")),
basedirPath.resolve(Path.of("expected", it + ".yml")))
}

[
"multiples.sample.fabric8.io-v1"
].each {
Verify.verifyAbsent(new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml", it)))
Verify.verifyAbsent(basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml")))
}

true
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
* limitations under the License.
*/
import io.fabric8.crd.generator.maven.plugin.Verify

import java.nio.file.Path
Path basedirPath = basedir.toPath();

[
"multiples.sample.fabric8.io-v1",
"mycustomresources.other.sample.fabric8.io-v1"
].each {
Verify.verifyContentEquals(
new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml",it)),
new File(basedir, sprintf("/expected/%s.yml",it)))
basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml")),
basedirPath.resolve(Path.of("expected", it + ".yml")))
}

true
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/
import io.fabric8.crd.generator.maven.plugin.Verify
import java.nio.file.Path
Path basedirPath = basedir.toPath();


[
Expand All @@ -22,8 +24,8 @@ import io.fabric8.crd.generator.maven.plugin.Verify
"myintermediatehasmetadatainterfaces.sample.fabric8.io-v1"
].each {
Verify.verifyContentEquals(
new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml",it)),
new File(basedir, sprintf("/expected/%s.yml",it)))
basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml")),
basedirPath.resolve(Path.of("expected", it + ".yml")))
}

true
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@
* limitations under the License.
*/
import io.fabric8.crd.generator.maven.plugin.Verify

import java.nio.file.Path
Path basedirPath = basedir.toPath();

[
"multiples.sample.fabric8.io-v1",
"mycustomresources.other.sample.fabric8.io-v1",
"projects.sample.fabric8.io-v1"
].each {
Verify.verifyContentEquals(
new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml",it)),
new File(basedir, sprintf("/expected/%s.yml",it)))
basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml")),
basedirPath.resolve(Path.of("expected", it + ".yml")))
}

true
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
* limitations under the License.
*/
import io.fabric8.crd.generator.maven.plugin.Verify

import java.nio.file.Path
Path basedirPath = basedir.toPath();

[
"multiples.sample.fabric8.io-v1"
].each {
Verify.verifyContentEquals(
new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml",it)),
new File(basedir, sprintf("/expected/%s.yml",it)))
basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml")),
basedirPath.resolve(Path.of("expected", it + ".yml")))
}

true
6 changes: 4 additions & 2 deletions crd-generator/maven-plugin/src/it/project-scan/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
* limitations under the License.
*/
import io.fabric8.crd.generator.maven.plugin.Verify
import java.nio.file.Path
Path basedirPath = basedir.toPath();


[
"multiples.sample.fabric8.io-v1"
].each {
Verify.verifyContentEquals(
new File(basedir, sprintf("/target/classes/META-INF/fabric8/%s.yml",it)),
new File(basedir, sprintf("/expected/%s.yml",it)))
basedirPath.resolve(Path.of("target", "classes", "META-INF", "fabric8", it + ".yml")),
basedirPath.resolve(Path.of("expected", it + ".yml")))
}

true
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,35 @@
*/
package io.fabric8.crd.generator.maven.plugin;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Objects;

class Verify {
static void verifyExist(File file) {
static void verifyExist(Path file) {
Objects.requireNonNull(file);
if (!file.exists())
throw new AssertionError("File " + file.getAbsoluteFile() + " does not exist");
if (!Files.exists(file))
throw new AssertionError("File " + file.normalize() + " does not exist");
}

static void verifyAbsent(File file) {
static void verifyAbsent(Path file) {
Objects.requireNonNull(file);
if (file.exists())
throw new AssertionError("File " + file.getAbsoluteFile() + " exists");
if (Files.exists(file))
throw new AssertionError("File " + file.normalize() + " exists");
}

static void verifyContentEquals(File file1, File file2) throws IOException {
static void verifyContentEquals(Path file1, Path file2) throws IOException {
verifyExist(file1);
verifyExist(file2);

if (!Objects.equals(readFile(file1), readFile(file2))) {
throw new AssertionError("File contents not equal: " + file1.getAbsoluteFile() + " " + file2.getAbsoluteFile());
throw new AssertionError("File contents not equal: " + file1.normalize() + " " + file2.normalize());
}
}

private static String readFile(File path) throws IOException {
return new String(Files.readAllBytes(path.toPath()), StandardCharsets.UTF_8);
private static String readFile(Path path) throws IOException {
return new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
}
}

0 comments on commit f216529

Please sign in to comment.