Skip to content

Commit

Permalink
Added new test to check job, actions and params
Browse files Browse the repository at this point in the history
Signed-off-by: cmoulliard <[email protected]>
  • Loading branch information
cmoulliard committed Aug 9, 2024
1 parent 2b5d0d7 commit 3b650bf
Showing 1 changed file with 41 additions and 6 deletions.
47 changes: 41 additions & 6 deletions src/test/java/dev/snowdrop/SnakeYamlTests.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package dev.snowdrop;

import dev.snowdrop.model.Action;
import org.junit.jupiter.api.BeforeAll;
import dev.snowdrop.model.Job;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.TypeDescription;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;

Expand All @@ -15,8 +14,7 @@
import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.*;

public class SnakeYamlTests {

Expand Down Expand Up @@ -57,7 +55,7 @@ public void paramsWithDifferentObjects() {

@Test
public void fromActionParamsYamlToAction_Object() {
String actionParams = """
String yamlStr = """
name: git-clone
ref: "bundle://pack-builder:quay.io/ch007m/tekton-bundle:latest"
params:
Expand All @@ -69,7 +67,8 @@ public void fromActionParamsYamlToAction_Object() {

Constructor constructor = new Constructor(Action.class, new LoaderOptions());
Yaml yaml = new Yaml(constructor);
Action a = yaml.load(actionParams);
Action a = yaml.load(yamlStr);

assertNotNull(a);
assertEquals("bundle://pack-builder:quay.io/ch007m/tekton-bundle:latest",a.getRef());
assertEquals("git-clone",a.getName());
Expand All @@ -78,4 +77,40 @@ public void fromActionParamsYamlToAction_Object() {
assertEquals(List.of("$(params.packCmdBuilderFlags)"),a.getParams().get(2).get("PACK_CMD_FLAGS"));
}

@Test
public void fromJobYamlToJobObject() {
String yamlStr = """
resourceType: PipelineRun
name: pack-builder-push
description: "This Pipeline builds a builder image using the pack CLI."
params:
- debug: true
- git-url: "https://github.com/redhat-buildpacks/ubi-image-builder.git"
- cmdArgs:
- -v
- --publish
actions:
- name: git-clone
ref: bundle://quay.io/konflux-ci/tekton-catalog/task-git-clone:0.1@sha256:de0ca8872c791944c479231e21d68379b54877aaf42e5f766ef4a8728970f8b3
params:
- url: "$(params.git-url)"
- subdirectory: "."
- name: tool
ref: bundle://quay.io/ch007m/tekton-bundle:latest@sha256:af13b94347457df001742f8449de9edb381e90b0d174da598ddd15cf493e340f
params:
- CMD_ARGS:
- "$(params.cmdArgs)"
""";

Constructor constructor = new Constructor(Job.class, new LoaderOptions());
Yaml yaml = new Yaml(constructor);
Job j = yaml.load(yamlStr);

assertNotNull(j);

assertEquals(List.of("-v", "--publish"),j.getParams().get(2).get("cmdArgs"));
assertEquals(2,j.getActions().size());
assertEquals(List.of("$(params.cmdArgs)"),j.getActions().get(1).getParams().get(0).get("CMD_ARGS"));
}

}

0 comments on commit 3b650bf

Please sign in to comment.