Skip to content

Commit 6719f71

Browse files
authored
fix: append task option at the end of script (#348)
1 parent 6d3d351 commit 6719f71

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## 4.5.0 [unreleased]
22

3+
### Bug Fixes
4+
1. [#348](https://github.com/influxdata/influxdb-client-csharp/pull/348): Append `task option` at the end of script
5+
36
### Dependencies
47
Update dependencies:
58

Client.Test/ItTasksApiTest.cs

+25-3
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public async Task CreateTaskCron()
171171
Assert.AreEqual(TaskStatusType.Active, task.Status);
172172
Assert.AreEqual("0 2 * * *", task.Cron);
173173
Assert.IsNull(task.Every);
174-
Assert.IsTrue(task.Flux.EndsWith(TaskFlux, StringComparison.OrdinalIgnoreCase));
174+
StringAssert.StartsWith(TaskFlux, task.Flux);
175175
}
176176

177177
[Test]
@@ -189,7 +189,7 @@ public async Task CreateTaskEvery()
189189
Assert.AreEqual(TaskStatusType.Active, task.Status);
190190
Assert.AreEqual("1h", task.Every);
191191
Assert.IsNull(task.Cron);
192-
Assert.IsTrue(task.Flux.EndsWith(TaskFlux, StringComparison.OrdinalIgnoreCase));
192+
StringAssert.StartsWith(TaskFlux, task.Flux);
193193
}
194194

195195
[Test]
@@ -586,7 +586,7 @@ public async Task UpdateTask()
586586
var cronTask =
587587
await _tasksApi.CreateTaskCronAsync(taskName, TaskFlux, "0 2 * * *", _organization);
588588

589-
var flux = $"option task = {{name: \"{taskName}\", every: 3m}}\n\n{TaskFlux}";
589+
var flux = $"{TaskFlux}\n\noption task = {{name: \"{taskName}\", every: 3m}}";
590590

591591
cronTask.Every = "3m";
592592
cronTask.Cron = null;
@@ -607,5 +607,27 @@ public async Task UpdateTask()
607607

608608
Assert.IsNotNull(updatedTask.UpdatedAt);
609609
}
610+
611+
[Test]
612+
public async Task CreateTaskWithMoreFrom()
613+
{
614+
var taskName = GenerateName("it task");
615+
616+
const string flux = "procTotal = from(bucket: \"example-bucket\")" +
617+
" |> range(start: -5m)" +
618+
" |> filter(fn: (r) => r._measurement == \"processes\" and r._field == \"total\")" +
619+
"" +
620+
"procTotal";
621+
622+
var task = await _tasksApi.CreateTaskCronAsync(taskName, flux, "0 2 * * *", _organization);
623+
624+
Assert.IsNotNull(task);
625+
Assert.IsNotEmpty(task.Id);
626+
Assert.AreEqual(taskName, task.Name);
627+
Assert.AreEqual(_organization.Id, task.OrgID);
628+
Assert.AreEqual(TaskStatusType.Active, task.Status);
629+
Assert.AreEqual("0 2 * * *", task.Cron);
630+
StringAssert.StartsWith(flux, task.Flux);
631+
}
610632
}
611633
}

Client/TasksApi.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,7 @@ private TaskType CreateTaskAsync(string name, string flux, string every, string
13241324
repetition += "\"" + cron + "\"";
13251325
}
13261326

1327-
task.Flux = $"option task = {{name: \"{name}\", {repetition}}} \n {flux}";
1327+
task.Flux = $"{flux}\n\noption task = {{name: \"{name}\", {repetition}}}";
13281328

13291329
return task;
13301330
}

0 commit comments

Comments
 (0)