-
Notifications
You must be signed in to change notification settings - Fork 96
[JEP-206] Define API for gathering command output in a local encoding #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e703cc8
[JENKINS-31096] Define API for gathering command output in a local en…
jglick cc53b18
ByteBuffer.array is not what I wanted.
jglick 6df38ba
Merge branch 'master' into UTF-8-JENKINS-31096
jglick d04d08c
Introduce constant for SYSTEM_DEFAULT_CHARSET as suggested by @svanoort.
jglick 761202e
Merged with #66.
jglick 6e94552
Merge branch 'incrementals' into UTF-8-JENKINS-31096
jglick 6da5620
Suggestions from @oleg-nenashev.
jglick 7208013
Merge branch 'incrementals' into UTF-8-JENKINS-31096
jglick d096a91
Merge branch 'writeLog-JENKINS-37575' into UTF-8-JENKINS-31096
jglick 7b01461
Merge branch 'writeLog-JENKINS-37575' into UTF-8-JENKINS-31096
jglick b3b0e4e
Merge branch 'writeLog-JENKINS-37575' into UTF-8-JENKINS-31096
jglick 32de5bf
For purposes of lastLocation we must count bytes, not characters, so …
jglick f8c292c
Merge branch 'master' into UTF-8-JENKINS-31096
jglick 1aa8974
Updated parent and reincrementalified.
jglick 9dd828f
Merge branch 'parent' into UTF-8-JENKINS-31096
jglick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,8 +34,12 @@ | |
| import hudson.util.VersionNumber; | ||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.File; | ||
| import java.io.OutputStream; | ||
| import java.nio.charset.Charset; | ||
| import java.util.Collections; | ||
| import java.util.Locale; | ||
| import java.util.logging.Level; | ||
| import jenkins.security.MasterToSlaveCallable; | ||
| import org.apache.commons.io.output.TeeOutputStream; | ||
| import static org.hamcrest.Matchers.*; | ||
| import org.jenkinsci.test.acceptance.docker.Docker; | ||
|
|
@@ -67,7 +71,7 @@ public class BourneShellScriptTest { | |
| assumeThat("Docker must be at least 1.13.0 for this test (uses --init)", new VersionNumber(baos.toString().trim()), greaterThanOrEqualTo(new VersionNumber("1.13.0"))); | ||
| } | ||
|
|
||
| @Rule public LoggerRule logging = new LoggerRule().record(BourneShellScript.class, Level.FINE); | ||
| @Rule public LoggerRule logging = new LoggerRule().recordPackage(BourneShellScript.class, Level.FINE); | ||
|
|
||
| private StreamTaskListener listener; | ||
| private FilePath ws; | ||
|
|
@@ -236,4 +240,64 @@ private void runOnDocker(DumbSlave s) throws Exception { | |
| runOnDocker(new DumbSlave("docker", "/home/jenkins/agent", new SimpleCommandLauncher("docker run -i --rm --name agent --init jenkinsci/slave:3.7-1 java -jar /usr/share/jenkins/slave.jar"))); | ||
| } | ||
|
|
||
| @Issue("JENKINS-31096") | ||
| @Test public void encoding() throws Exception { | ||
| JavaContainer container = dockerUbuntu.get(); | ||
| DumbSlave s = new DumbSlave("docker", "/home/test", new SSHLauncher(container.ipBound(22), container.port(22), "test", "test", "", "-Dfile.encoding=ISO-8859-1")); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that this test can run without jenkinsci/docker-fixtures#19 since it is only concerned with file contents, not name. (Passing |
||
| j.jenkins.addNode(s); | ||
| j.waitOnline(s); | ||
| assertEquals("ISO-8859-1", s.getChannel().call(new DetectCharset())); | ||
| FilePath dockerWS = s.getWorkspaceRoot(); | ||
| dockerWS.child("latin").write("¡Ole!\n", "ISO-8859-1"); | ||
| dockerWS.child("eastern").write("Čau!\n", "ISO-8859-2"); | ||
| dockerWS.child("mixed").write("¡Čau → there!\n", "UTF-8"); | ||
| Launcher dockerLauncher = s.createLauncher(listener); | ||
| assertEncoding("control: no transcoding", "latin", null, "¡Ole!", "ISO-8859-1", dockerWS, dockerLauncher); | ||
| assertEncoding("test: specify particular charset (UTF-8)", "mixed", "UTF-8", "¡Čau → there!", "UTF-8", dockerWS, dockerLauncher); | ||
| assertEncoding("test: specify particular charset (unrelated)", "eastern", "ISO-8859-2", "Čau!", "UTF-8", dockerWS, dockerLauncher); | ||
| assertEncoding("test: specify agent default charset", "latin", "", "¡Ole!", "UTF-8", dockerWS, dockerLauncher); | ||
| assertEncoding("test: inappropriate charset, some replacement characters", "mixed", "US-ASCII", "����au ��� there!", "UTF-8", dockerWS, dockerLauncher); | ||
| s.toComputer().disconnect(new OfflineCause.UserCause(null, null)); | ||
| } | ||
| private static class DetectCharset extends MasterToSlaveCallable<String, RuntimeException> { | ||
| @Override public String call() throws RuntimeException { | ||
| return Charset.defaultCharset().name(); | ||
| } | ||
| } | ||
| private void assertEncoding(String description, String file, String charset, String expected, String expectedEncoding, FilePath dockerWS, Launcher dockerLauncher) throws Exception { | ||
| assertEncoding(description, file, charset, expected, expectedEncoding, false, dockerWS, dockerLauncher); | ||
| assertEncoding(description, file, charset, expected, expectedEncoding, true, dockerWS, dockerLauncher); | ||
| } | ||
| private void assertEncoding(String description, String file, String charset, String expected, String expectedEncoding, boolean output, FilePath dockerWS, Launcher dockerLauncher) throws Exception { | ||
| System.err.println(description + " (output=" + output + ")"); // TODO maybe this should just be moved into a new class and @RunWith(Parameterized.class) for clarity | ||
| BourneShellScript dt = new BourneShellScript("set +x; cat " + file + "; sleep 1; tr '[a-z]' '[A-Z]' < " + file); | ||
| if (charset != null) { | ||
| if (charset.isEmpty()) { | ||
| dt.defaultCharset(); | ||
| } else { | ||
| dt.charset(Charset.forName(charset)); | ||
| } | ||
| } | ||
| if (output) { | ||
| dt.captureOutput(); | ||
| } | ||
| Controller c = dt.launch(new EnvVars(), dockerWS, dockerLauncher, listener); | ||
| ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
| OutputStream tee = new TeeOutputStream(baos, System.err); | ||
| while (c.exitStatus(dockerWS, dockerLauncher, listener) == null) { | ||
| c.writeLog(dockerWS, tee); | ||
| Thread.sleep(100); | ||
| } | ||
| c.writeLog(dockerWS, tee); | ||
| assertEquals(description, 0, c.exitStatus(dockerWS, dockerLauncher, listener).intValue()); | ||
| String fullExpected = expected + "\n" + expected.toUpperCase(Locale.ENGLISH) + "\n"; | ||
| if (output) { | ||
| assertEquals(description, fullExpected, new String(c.getOutput(dockerWS, launcher), expectedEncoding)); | ||
| } else { | ||
| assertThat(description, baos.toString(expectedEncoding), containsString(fullExpected)); | ||
| } | ||
| c.cleanup(dockerWS); | ||
|
|
||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is unreadable IMHO. Would it be possible to split it to several tests or at least explicitly indicate test stages? Assert logic could be also refactored to a separate method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it could be refactored to use a helper assertion method with parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(resolved)