Skip to content

Commit

Permalink
#1 docker test
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Nov 5, 2019
1 parent 64b43f8 commit df680f7
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 12 deletions.
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM centos
MAINTAINER Yegor Bugayenko <[email protected]>
LABEL Description="Yum utils" Vendor="Yegor Bugayenko" Version="1.0"

RUN yum install -y yum-utils
RUN yum install -y createrepo
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
Turns your files into an NPM repository.

Similar solutions:

* [Artifactory](https://www.jfrog.com/confluence/display/RTF/RPM+Repositories)
* [Pulp](https://pulp-rpm.readthedocs.io/en/latest/)

11 changes: 8 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,17 @@ SOFTWARE.
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<scope>test</scope>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-log</artifactId>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<directory>${basedir}/src/test/resources-binary</directory>
<filtering>false</filtering>
</testResource>
</testResources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/com/yegor256/rpm/Rpm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2019 Yegor Bugayenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.yegor256.rpm;

import java.io.IOException;
import java.nio.file.Path;

/**
* The RPM front.
*
* @author Yegor Bugayenko ([email protected])
* @version $Id$
* @since 0.1
*/
public final class Rpm {

/**
* The storage.
*/
private final Storage storage;

/**
* Ctor.
* @param stg The storage
*/
public Rpm(final Storage stg) {
this.storage = stg;
}

/**
* Publish a single DEB artifact.
*
* @param path The file
* @throws IOException If fails
*/
public void publish(final Path path) throws IOException {
this.storage.save("x.rpm", path);
}

}
24 changes: 16 additions & 8 deletions src/main/java/com/yegor256/rpm/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package com.yegor256.rpm;

import com.jcabi.log.Logger;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -57,11 +58,11 @@ public interface Storage {
void load(String key, Path content) throws IOException;

/**
* Fake storage.
* Simple storage.
*
* @since 0.1
*/
final class Fake implements Storage {
final class Simple implements Storage {
/**
* Where we keep the data.
*/
Expand All @@ -70,28 +71,35 @@ final class Fake implements Storage {
* Ctor.
* @throws IOException If fails
*/
public Fake() throws IOException {
public Simple() throws IOException {
this(Files.createTempDirectory("rpm-files"));
}
/**
* Ctor.
* @param path The path to the dir
*/
public Fake(final Path path) {
public Simple(final Path path) {
this.dir = path;
}
@Override
public void save(final String key, final Path path) throws IOException {
final Path target = Paths.get(this.dir.toString(), key);
target.getParent().toFile().mkdirs();
Files.copy(path, target, StandardCopyOption.REPLACE_EXISTING);
Logger.info(
this,
"Saved %d bytes to %s: %s",
Files.size(target), key, target
);
}
@Override
public void load(final String key, final Path path) throws IOException {
Files.copy(
Paths.get(this.dir.toString(), key),
path,
StandardCopyOption.REPLACE_EXISTING
final Path source = Paths.get(this.dir.toString(), key);
Files.copy(source, path, StandardCopyOption.REPLACE_EXISTING);
Logger.info(
this,
"Loaded %d bytes of %s: %s",
Files.size(source), key, source
);
}
}
Expand Down
99 changes: 99 additions & 0 deletions src/test/java/com/yegor256/rpm/RpmITCase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2019 Yegor Bugayenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.yegor256.rpm;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

/**
* Integration case for {@link Rpm}.
*
* @author Yegor Bugayenko ([email protected])
* @version $Id$
* @since 0.1
*/
public final class RpmITCase {

/**
* Temp folder for all tests.
*/
@Rule
@SuppressWarnings("PMD.BeanMembersShouldSerialize")
public TemporaryFolder folder = new TemporaryFolder();

/**
* RPM works.
* @throws Exception If some problem inside
*/
@Test
public void savesAndLoads() throws Exception {
final Path repo = this.folder.newFolder("repo").toPath();
final Rpm rpm = new Rpm(new Storage.Simple(repo));
final Path bin = this.folder.newFile("x.rpm").toPath();
Files.copy(
RpmITCase.class.getResourceAsStream(
"/nginx-module-xslt-1.16.1-1.el7.ngx.x86_64.rpm"
),
bin,
StandardCopyOption.REPLACE_EXISTING
);
rpm.publish(bin);
final Path stdout = this.folder.newFile("stdout.txt").toPath();
new ProcessBuilder()
.command(
"docker",
"run",
"--rm",
"--volume",
String.format("%s:/repo", repo),
"af27e27cbf9d",
"/bin/bash",
"-c",
String.join(
";",
"createrepo /repo",
"yum-config-manager --add-repo file:///repo",
"yum --disablerepo='*' --enablerepo='repo' list available"
)
)
.redirectOutput(stdout.toFile())
.redirectError(stdout.toFile())
.start()
.waitFor();
MatcherAssert.assertThat(
new String(Files.readAllBytes(stdout)),
Matchers.allOf(
Matchers.containsString("nginx-module-xslt.x86_64"),
Matchers.containsString("1:1.16.1-1.el7.ngx")
)
);
}

}
2 changes: 1 addition & 1 deletion src/test/java/com/yegor256/rpm/StorageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public final class StorageTest {
*/
@Test
public void savesAndLoads() throws Exception {
final Storage storage = new Storage.Fake();
final Storage storage = new Storage.Simple();
final Path input = this.folder.newFile("a.deb").toPath();
final String content = "Hello, друг!";
Files.write(input, content.getBytes());
Expand Down
Binary file not shown.
7 changes: 7 additions & 0 deletions src/test/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
log4j.rootLogger=WARN, CONSOLE

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=com.jcabi.log.MulticolorLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[%color{%p}] %t %c: %m%n

log4j.logger.com.yegor256.rpm=DEBUG

0 comments on commit df680f7

Please sign in to comment.