Skip to content

Commit

Permalink
fix(core): FlowWithSource also copies tenantId when created with meth…
Browse files Browse the repository at this point in the history
…od `of`

closes kestra-io/kestra-ee#696
  • Loading branch information
brian-mulier-p committed Dec 27, 2023
1 parent 53b0fbf commit e76cc70
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public boolean isUpdatable(Flow flow, String flowSource) {

public static FlowWithSource of(Flow flow, String source) {
return FlowWithSource.builder()
.tenantId(flow.tenantId)
.id(flow.id)
.namespace(flow.namespace)
.revision(flow.revision)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package io.kestra.core.models.flows;

import com.fasterxml.jackson.core.JsonProcessingException;
import io.kestra.core.models.Label;
import io.kestra.core.models.conditions.types.VariableCondition;
import io.kestra.core.models.flows.input.StringInput;
import io.kestra.core.models.listeners.Listener;
import io.kestra.core.models.triggers.types.Schedule;
import io.kestra.core.serializers.JacksonMapper;
import io.kestra.core.tasks.debugs.Return;
Expand All @@ -9,6 +13,7 @@
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Map;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
Expand Down Expand Up @@ -63,4 +68,66 @@ void scalar() throws JsonProcessingException {
assertThat(source, containsString("message: Hello World"));
assertThat(source, containsString(" cron: 0 1 9 * * *"));
}

@Test
void of() {
// test that all fields are transmitted to FlowWithSource
Flow flow = Flow.builder()
.tenantId("tenantId")
.id(IdUtils.create())
.namespace("io.kestra.unittest")
.description("description")
.labels(List.of(
new Label("key", "value")
))
.inputs(List.of(
StringInput.builder().name("strInput").build()
))
.variables(Map.of(
"varKey", "varValue"
))
.tasks(List.of(
Log.builder()
.id(IdUtils.create())
.type(Log.class.getName())
.message("Hello World")
.build()
))
.errors(List.of(
Log.builder()
.id(IdUtils.create())
.type(Log.class.getName())
.message("Error")
.build()
))
.listeners(List.of(
Listener.builder()
.conditions(List.of(VariableCondition.builder().expression("true").build()))
.build()
))
.triggers(List.of(
Schedule.builder().id("schedule").cron("0 1 9 * * *").build()
))
.taskDefaults(List.of(
TaskDefault.builder()
.type(Log.class.getName())
.forced(true)
.values(Map.of(
"message", "Default message"
))
.build()
))
.concurrency(
Concurrency.builder()
.behavior(Concurrency.Behavior.CANCEL)
.limit(2)
.build()
)
.build();
String expectedSource = flow.generateSource() + " # additional comment";
FlowWithSource of = FlowWithSource.of(flow, expectedSource);

assertThat(of.equalsWithoutRevision(flow), is(true));
assertThat(of.getSource(), is(expectedSource));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ protected List<FlowWithSource> updateCompleteNamespace(String namespace, List<Fl
if (existingFlow.isPresent()) {
return flowRepository.update(flow, existingFlow.get(), flowWithSource.getSource(), taskDefaultService.injectDefaults(flow));
} else {
return create(flow, flowWithSource.getSource());
return this.create(flow, flowWithSource.getSource());
}
})
.toList();
Expand Down

0 comments on commit e76cc70

Please sign in to comment.