Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Mar 18, 2024
2 parents 53ae06b + 7ccf5b1 commit 3f824cb
Show file tree
Hide file tree
Showing 79 changed files with 292 additions and 112 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
<plugin>
<groupId>com.qulice</groupId>
<artifactId>qulice-maven-plugin</artifactId>
<version>0.22.1</version>
<version>0.22.2</version>
<configuration>
<excludes combine.children="append">
<exclude>checkstyle:/src/main/js/.*</exclude>
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/rultor/agents/daemons/ArchivesDaemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import java.nio.file.Files;
import java.util.Date;
import java.util.logging.Level;
import javax.ws.rs.core.MediaType;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -132,7 +131,7 @@ public Iterable<Directive> process(final XML xml) throws IOException {
*/
private URI upload(final File file, final String hash) throws IOException {
final ObjectMetadata meta = new ObjectMetadata();
meta.setContentType(MediaType.TEXT_PLAIN);
meta.setContentType("text/plain");
meta.setContentEncoding(StandardCharsets.UTF_8.name());
meta.setContentLength(file.length());
final String key = String.format("%tY/%1$tm/%s.txt", new Date(), hash);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/rultor/agents/github/CommitsLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ final class CommitsLog {
* @return Release body text.
* @throws IOException In case of problem communicating with git.
*/
@SuppressWarnings("PMD.UseConcurrentHashMap")
@SuppressWarnings({"PMD.UseConcurrentHashMap", "PMD.UseDiamondOperator"})
public String build(final Date prev, final Date current)
throws IOException {
final DateFormat format = new SimpleDateFormat(
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/rultor/agents/shells/PfShell.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import com.jcabi.ssh.Ssh;
import com.rultor.spi.Profile;
import java.io.IOException;
import java.io.InputStream;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -151,8 +150,7 @@ public String key() throws IOException {
if (path.isEmpty()) {
key = this.pvt;
} else {
final InputStream asset = this.profile.assets().get(path);
if (asset == null) {
if (this.profile.assets().get(path) == null) {
throw new Profile.ConfigException(
String.format("Private SSH key not found at %s", path)
);
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/rultor/web/TkSiblings.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ private Iterable<Directive> dirs(final Talk talk) throws IOException {
dirs.append(TkSiblings.log(xml, log));
}
return dirs.up().add("name").set(talk.name()).up()
// @checkstyle MultipleStringLiteralsCheck (1 line)
.add("href").set(xml.xpath("/talk/wire/href/text()").get(0)).up()
.add("updated").set(Long.toString(talk.updated().getTime())).up()
.add("timeago").set(new PrettyTime().format(talk.updated())).up()
Expand Down
13 changes: 9 additions & 4 deletions src/test/java/com/rultor/TimeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
package com.rultor;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
Expand All @@ -54,7 +53,8 @@ final class TimeTest {
void canParseValidTime() {
final String date = "2005-10-08T15:48:39";
Assertions.assertDoesNotThrow(
() -> new Time(date)
() -> new Time(date),
"Time should be able to create from date-time string"
);
}

Expand All @@ -71,7 +71,8 @@ void canParseValidTime() {
void exceptionParseInvalidTime(final String date) {
Assertions.assertThrows(
IllegalStateException.class,
() -> new Time(date)
() -> new Time(date),
"Exception is expected for invalid date time string"
);
}

Expand All @@ -80,12 +81,13 @@ void exceptionParseInvalidTime(final String date) {
*/
@Test
void isoValidFormat() {
final Date date = Calendar.getInstance().getTime();
final Date date = new Date();
final SimpleDateFormat format =
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
format.setTimeZone(TimeZone.getTimeZone("GMT"));
final Time time = new Time(date);
MatcherAssert.assertThat(
"ISO value should be for the GMT timezone",
time.iso(),
Matchers.equalTo(format.format(date))
);
Expand All @@ -99,6 +101,7 @@ void defaultNowTime() {
final Date date = new Date();
final Time time = new Time();
MatcherAssert.assertThat(
"Time without parameters should get current time",
time.msec(),
Matchers.allOf(
Matchers.greaterThanOrEqualTo(date.getTime()),
Expand All @@ -115,6 +118,7 @@ void fromDateValidTime() {
final Date date = new Date();
final Time time = new Time(date);
MatcherAssert.assertThat(
"Time should get date from the parameter",
time.msec(),
Matchers.equalTo(date.getTime())
);
Expand All @@ -128,6 +132,7 @@ void fromMsValidTime() {
final Date date = new Date();
final Time time = new Time(date.getTime());
MatcherAssert.assertThat(
"Time should get msec value from parameter",
time.msec(),
Matchers.equalTo(date.getTime())
);
Expand Down
7 changes: 5 additions & 2 deletions src/test/java/com/rultor/agents/IndexesRequestsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void storesIndexIfNone() throws Exception {
);
new IndexesRequests().execute(talks);
MatcherAssert.assertThat(
"Talk should be reindexed (1 based)",
talks.get(name).read(),
XhtmlMatchers.hasXPaths("/talk/request[@index='1']")
);
Expand Down Expand Up @@ -94,14 +95,14 @@ void retrievesIndexFromLog() throws Exception {
);
new IndexesRequests().execute(talks);
MatcherAssert.assertThat(
"Index value should be started from log records max",
talks.get(name).read(),
XhtmlMatchers.hasXPaths("/talk/request[@index='3']")
);
}

/**
* IndexesRequests should retrieve index from sibling
* (the test is skipped, more information in #733).
* IndexesRequests should retrieve index from sibling.
* @throws Exception In case of error.
*/
@Test
Expand Down Expand Up @@ -141,6 +142,7 @@ void retrievesIndexFromSibling() throws Exception {
);
new IndexesRequests().execute(talks);
MatcherAssert.assertThat(
"Index value should be started from log records max",
talks.get(third).read(),
XhtmlMatchers.hasXPaths("/talk/request[@index='5']")
);
Expand All @@ -163,6 +165,7 @@ void notStoreIndexWithoutRequest() throws Exception {
);
new IndexesRequests().execute(talks);
MatcherAssert.assertThat(
"Request tag should not be created if does not exist",
talks.get(name).read(),
Matchers.not(
XhtmlMatchers.hasXPaths("/talk/request")
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/rultor/agents/MailsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ void sendsMail() throws Exception {
Mockito.verify(postman).send(captor.capture());
final Envelope envelope = captor.getValue();
MatcherAssert.assertThat(
"Mail text should contain some data",
envelope.unwrap().getContent().toString(),
Matchers.allOf(
Matchers.containsString("See #456, release log:"),
Expand All @@ -83,6 +84,7 @@ void sendsMail() throws Exception {
)
);
MatcherAssert.assertThat(
"Mail subject should be about release",
envelope.unwrap().getSubject(),
Matchers.equalTo("user/repo v2.0 released!")
);
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/rultor/agents/PublishesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void addsPublicAttribute() throws Exception {
);
agent.execute(talk);
MatcherAssert.assertThat(
"public attribute should be added",
talk.read(),
XhtmlMatchers.hasXPath("/talk[@public='true']")
);
Expand All @@ -84,6 +85,7 @@ void ignoresIfPublicAttributeSet() throws Exception {
);
agent.execute(talk);
MatcherAssert.assertThat(
"public attribute should be kept false",
talk.read(),
XhtmlMatchers.hasXPath("/talk[@public='false']")
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void archivesDaemon(@TempDir final Path temp) throws Exception {
);
agent.execute(talk);
MatcherAssert.assertThat(
"archive tag should be created with bucket name",
talk.read(),
XhtmlMatchers.hasXPaths(
"/talk[not(daemon)]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void endsIfHostNotFound() throws IOException {
final Agent agent = new DismountDaemon();
agent.execute(talk);
MatcherAssert.assertThat(
"Daemon should be stopped for not found host",
talk.read(),
XhtmlMatchers.hasXPaths(
"/talk/daemon/ended",
Expand Down Expand Up @@ -104,6 +105,7 @@ void ignoresFreshDaemons() throws IOException {
final Agent agent = new DismountDaemon();
agent.execute(talk);
MatcherAssert.assertThat(
"Daemon should not be ended if younger then 10 days",
talk.read(),
XhtmlMatchers.hasXPaths("/talk/daemon[not(ended)]")
);
Expand Down
17 changes: 10 additions & 7 deletions src/test/java/com/rultor/agents/daemons/EndsDaemonITCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.rultor.spi.Talk;
import java.io.IOException;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.core.StringContains;
import org.hamcrest.core.StringEndsWith;
import org.junit.jupiter.api.Assumptions;
Expand Down Expand Up @@ -78,6 +79,7 @@ void parsesHighlightedStdout() throws IOException {
final Agent agent = new EndsDaemon();
agent.execute(talk);
MatcherAssert.assertThat(
"Rultor prefix should be moved to highlights",
talk.read(),
XhtmlMatchers.hasXPaths(
"/talk/daemon/highlights",
Expand Down Expand Up @@ -105,6 +107,7 @@ void readsExitCodeCorrectly() throws IOException {
final Agent agent = new EndsDaemon();
agent.execute(talk);
MatcherAssert.assertThat(
"Status code should be placed to daemon/code",
talk.read(),
XhtmlMatchers.hasXPath("/talk/daemon[code='123']")
);
Expand Down Expand Up @@ -133,6 +136,7 @@ void exitsWhenProfileBroken() throws Exception {
final Agent agent = new EndsDaemon();
agent.execute(talk);
MatcherAssert.assertThat(
"Exception message should be placed in tail text",
talk.read(),
XhtmlMatchers.hasXPaths(
"/talk/daemon[code='154']",
Expand Down Expand Up @@ -165,15 +169,15 @@ void deprecatesDefaultImage() throws IOException {
final String dir = talk.read()
.xpath("/talk/daemon/dir/text()").get(0);
MatcherAssert.assertThat(
"Deprecation message should be printed",
dir,
StringContains.containsString(
"#### Deprecation Notice ####"
Matchers.allOf(
StringContains.containsString(
"#### Deprecation Notice ####"
),
StringEndsWith.endsWith("##############")
)
);
MatcherAssert.assertThat(
dir,
StringEndsWith.endsWith("##############")
);
}
}
}
Expand All @@ -200,7 +204,6 @@ private PfShell start(final StartsDockerDaemon start, final Talk talk,
talk.modify(
new Directives().xpath("/talk")
.add("daemon")
// @checkstyle MultipleStringLiterals (1 line)
.attr("id", "abcd")
.add("title").set("merge").up()
.add("script").set("ls").up()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void ignoresFreshDaemon() throws Exception {
final Agent agent = new KillsDaemon();
agent.execute(talk);
MatcherAssert.assertThat(
"KillsDaemon stops daemon older then 1h by default",
talk.read(),
XhtmlMatchers.hasXPath("/talk/daemon")
);
Expand Down
12 changes: 10 additions & 2 deletions src/test/java/com/rultor/agents/daemons/StartsDaemonITCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ void startsDaemon() throws Exception {
) {
final Talk talk = StartsDaemonITCase.talk(start);
MatcherAssert.assertThat(
"started tag should be added with start time",
talk.read(),
XhtmlMatchers.hasXPaths(
"/talk/daemon[started and dir]",
Expand All @@ -95,6 +96,7 @@ void startsDaemon() throws Exception {
baos, baos
);
MatcherAssert.assertThat(
"Start script should be send to daemon",
baos.toString(StandardCharsets.UTF_8.name()),
Matchers.allOf(
Matchers.containsString("+ set -o pipefail"),
Expand All @@ -104,7 +106,9 @@ void startsDaemon() throws Exception {
)
);
MatcherAssert.assertThat(
new File(dir, "status").exists(), Matchers.is(false)
"status file should not be created",
new File(dir, "status").exists(),
Matchers.is(false)
);
}
}
Expand Down Expand Up @@ -136,7 +140,11 @@ void deprecatesDefaultImage() throws IOException {
} else {
matcher = Matchers.not(StringStartsWith.startsWith(notice));
}
MatcherAssert.assertThat(dir, matcher);
MatcherAssert.assertThat(
"Deprecation message in case of default image should be printed",
dir,
matcher
);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/test/java/com/rultor/agents/daemons/TailITCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import com.rultor.agents.shells.PfShell;
import com.rultor.spi.Profile;
import com.rultor.spi.Talk;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
Expand Down Expand Up @@ -89,9 +89,10 @@ void tailsNonUtf() throws Exception {
.add("key").set(sshd.key()).up().up()
);
MatcherAssert.assertThat(
"SSH output should be in the Tail",
IOUtils.toString(
new Tail(talk.read(), hash).read(),
Charset.forName("UTF-8")
StandardCharsets.UTF_8
),
Matchers.is(String.format("%sê\n", clean))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,24 @@ void providesPfShell() throws Exception {
) {
final PfShell shell = start.shell();
MatcherAssert.assertThat(
"Should login as root",
shell.login(),
Matchers.is("root")
);
final String key = shell.key();
MatcherAssert.assertThat(
"Should be RSA key",
key,
Matchers.startsWith("-----BEGIN RSA PRIVATE KEY-----")
);
MatcherAssert.assertThat(
key,
Matchers.endsWith("-----END RSA PRIVATE KEY-----")
Matchers.allOf(
Matchers.startsWith("-----BEGIN RSA PRIVATE KEY-----"),
Matchers.endsWith("-----END RSA PRIVATE KEY-----")
)
);
final Shell.Plain ssh = new Shell.Plain(
new Ssh(shell.host(), shell.port(), shell.login(), shell.key())
);
MatcherAssert.assertThat(
"Key should be placed in /root/.ssh/id_rsa",
ssh.exec("cat /root/.ssh/id_rsa"),
Matchers.containsString(key)
);
Expand Down
Loading

0 comments on commit 3f824cb

Please sign in to comment.