Skip to content

Commit 3515ca5

Browse files
authored
Migrate cron eval bats test to java (#50940)
This commit migrates the simple test of the cron eval tool from bats to java packaging tests. relates #46005
1 parent ae2ec85 commit 3515ca5

File tree

6 files changed

+53
-50
lines changed

6 files changed

+53
-50
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/DistroTestPlugin.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ public void apply(Project project) {
117117
}
118118
Map<String, TaskProvider<?>> batsTests = new HashMap<>();
119119
batsTests.put("bats oss", configureBatsTest(project, "oss", distributionsDir, copyDistributionsTask));
120-
batsTests.put("bats default", configureBatsTest(project, "default", distributionsDir, copyDistributionsTask));
121120
configureBatsTest(project, "plugins",distributionsDir, copyDistributionsTask, copyPluginsTask).configure(t ->
122121
t.setPluginsDir(pluginsDir)
123122
);

qa/os/bats/default/10_basic.bats

Lines changed: 0 additions & 47 deletions
This file was deleted.

qa/os/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ tasks.dependenciesInfo.enabled = false
5858
tasks.thirdPartyAudit.ignoreMissingClasses()
5959

6060
tasks.register('destructivePackagingTest') {
61-
dependsOn 'destructiveDistroTest', 'destructiveBatsTest.oss', 'destructiveBatsTest.default'
61+
dependsOn 'destructiveDistroTest', 'destructiveBatsTest.oss'
6262
}
6363

6464
processTestResources {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.packaging.test;
21+
22+
import org.elasticsearch.packaging.util.Distribution;
23+
import org.elasticsearch.packaging.util.Shell;
24+
import org.junit.Before;
25+
26+
import static org.hamcrest.CoreMatchers.containsString;
27+
import static org.junit.Assume.assumeTrue;
28+
29+
public class CronEvalCliTests extends PackagingTestCase {
30+
31+
@Before
32+
public void filterDistros() {
33+
assumeTrue("only default distro", distribution.flavor == Distribution.Flavor.DEFAULT);
34+
assumeTrue("no docker", distribution.packaging != Distribution.Packaging.DOCKER);
35+
}
36+
37+
public void test10Install() throws Exception {
38+
install();
39+
}
40+
41+
public void test20Help() throws Exception {
42+
Shell.Result result = installation.executables().cronevalTool.run("--help");
43+
assertThat(result.stdout, containsString("Validates and evaluates a cron expression"));
44+
}
45+
46+
public void test30Run() throws Exception {
47+
Shell.Result result = installation.executables().cronevalTool.run("'0 0 20 ? * MON-THU' -c 2");
48+
assertThat(result.stdout, containsString("Valid!"));
49+
}
50+
}

qa/os/src/test/java/org/elasticsearch/packaging/util/Installation.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ public class Executables {
177177
public final Executable keystoreTool = new Executable("elasticsearch-keystore");
178178
public final Executable certutilTool = new Executable("elasticsearch-certutil");
179179
public final Executable certgenTool = new Executable("elasticsearch-certgen");
180+
public final Executable cronevalTool = new Executable("elasticsearch-croneval");
180181
public final Executable shardTool = new Executable("elasticsearch-shard");
181182
public final Executable nodeTool = new Executable("elasticsearch-node");
182183
public final Executable setupPasswordsTool = new Executable("elasticsearch-setup-passwords");

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/trigger/schedule/tool/CronEvalTool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected void execute(Terminal terminal, OptionSet options) throws Exception {
5656
int count = countOption.value(options);
5757
List<String> args = arguments.values(options);
5858
if (args.size() != 1) {
59-
throw new UserException(ExitCodes.USAGE, "expecting a single argument that is the cron expression to evaluate");
59+
throw new UserException(ExitCodes.USAGE, "expecting a single argument that is the cron expression to evaluate, got " + args);
6060
}
6161
boolean printDetail = options.has(detailOption);
6262
execute(terminal, args.get(0), count, printDetail);

0 commit comments

Comments
 (0)