Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
jenkins
提交
335fb4bc
J
jenkins
项目概览
LinuxSuRen
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
335fb4bc
编写于
2月 26, 2017
作者:
D
Daniel Beck
提交者:
GitHub
2月 26, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2763 from slide/windows-ci
Fix tests on Windows
上级
a348b0d3
513d7e03
变更
29
展开全部
隐藏空白更改
内联
并排
Showing
29 changed file
with
382 addition
and
202 deletion
+382
-202
Jenkinsfile
Jenkinsfile
+1
-1
core/src/test/groovy/hudson/util/SecretRewriterTest.groovy
core/src/test/groovy/hudson/util/SecretRewriterTest.groovy
+4
-0
core/src/test/java/jenkins/model/RunIdMigratorTest.java
core/src/test/java/jenkins/model/RunIdMigratorTest.java
+9
-0
core/src/test/java/jenkins/util/VirtualFileTest.java
core/src/test/java/jenkins/util/VirtualFileTest.java
+4
-0
test/src/test/groovy/hudson/cli/SetBuildParameterCommandTest.groovy
...est/groovy/hudson/cli/SetBuildParameterCommandTest.groovy
+21
-4
test/src/test/groovy/hudson/model/AbstractProjectTest.groovy
test/src/test/groovy/hudson/model/AbstractProjectTest.groovy
+108
-76
test/src/test/groovy/hudson/util/TextFileTest.groovy
test/src/test/groovy/hudson/util/TextFileTest.groovy
+3
-3
test/src/test/java/hudson/PluginManagerTest.java
test/src/test/java/hudson/PluginManagerTest.java
+3
-0
test/src/test/java/hudson/ProcStarterTest.java
test/src/test/java/hudson/ProcStarterTest.java
+5
-2
test/src/test/java/hudson/ProcTest.java
test/src/test/java/hudson/ProcTest.java
+4
-0
test/src/test/java/hudson/cli/AbstractBuildRangeCommand2Test.java
.../test/java/hudson/cli/AbstractBuildRangeCommand2Test.java
+5
-3
test/src/test/java/hudson/cli/AbstractBuildRangeCommandTest.java
...c/test/java/hudson/cli/AbstractBuildRangeCommandTest.java
+40
-40
test/src/test/java/hudson/cli/ConsoleCommandTest.java
test/src/test/java/hudson/cli/ConsoleCommandTest.java
+37
-11
test/src/test/java/hudson/cli/DeleteBuildsCommandTest.java
test/src/test/java/hudson/cli/DeleteBuildsCommandTest.java
+3
-0
test/src/test/java/hudson/cli/ReloadJobCommandTest.java
test/src/test/java/hudson/cli/ReloadJobCommandTest.java
+28
-18
test/src/test/java/hudson/cli/SetBuildDescriptionCommandTest.java
.../test/java/hudson/cli/SetBuildDescriptionCommandTest.java
+17
-4
test/src/test/java/hudson/model/ParametersAction2Test.java
test/src/test/java/hudson/model/ParametersAction2Test.java
+4
-1
test/src/test/java/hudson/model/ProjectTest.java
test/src/test/java/hudson/model/ProjectTest.java
+14
-14
test/src/test/java/hudson/model/QueueTest.java
test/src/test/java/hudson/model/QueueTest.java
+8
-1
test/src/test/java/hudson/model/labels/LabelExpressionTest.java
...rc/test/java/hudson/model/labels/LabelExpressionTest.java
+3
-0
test/src/test/java/hudson/tasks/ArtifactArchiverTest.java
test/src/test/java/hudson/tasks/ArtifactArchiverTest.java
+2
-1
test/src/test/java/hudson/tasks/FingerprinterTest.java
test/src/test/java/hudson/tasks/FingerprinterTest.java
+22
-6
test/src/test/java/hudson/tools/InstallerTranslatorTest.java
test/src/test/java/hudson/tools/InstallerTranslatorTest.java
+21
-13
test/src/test/java/hudson/util/ArgumentListBuilder2Test.java
test/src/test/java/hudson/util/ArgumentListBuilder2Test.java
+14
-3
test/src/test/java/jenkins/security/Security232Test.java
test/src/test/java/jenkins/security/Security232Test.java
+1
-0
test/src/test/java/jenkins/security/security218/ysoserial/payloads/JRMPClient.java
...s/security/security218/ysoserial/payloads/JRMPClient.java
+1
-1
test/src/test/resources/hudson/model/ParametersAction2Test/backwardCompatibility.zip
...son/model/ParametersAction2Test/backwardCompatibility.zip
+0
-0
test/src/test/resources/hudson/tasks/ArtifactArchiverTest/fingerprintMigration.zip
...udson/tasks/ArtifactArchiverTest/fingerprintMigration.zip
+0
-0
test/src/test/resources/hudson/tasks/FingerprinterTest/actionSerialization.zip
...es/hudson/tasks/FingerprinterTest/actionSerialization.zip
+0
-0
未找到文件。
Jenkinsfile
浏览文件 @
335fb4bc
...
...
@@ -19,7 +19,7 @@ properties([[$class: 'jenkins.model.BuildDiscarderProperty', strategy: [$class:
artifactNumToKeepStr:
'20'
]]])
// see https://github.com/jenkins-infra/documentation/blob/master/ci.adoc for information on what node types are available
def
buildTypes
=
[
'Linux'
]
// TODO add 'Windows'
def
buildTypes
=
[
'Linux'
,
'Windows'
]
def
builds
=
[:]
for
(
i
=
0
;
i
<
buildTypes
.
size
();
i
++)
{
...
...
core/src/test/groovy/hudson/util/SecretRewriterTest.groovy
浏览文件 @
335fb4bc
...
...
@@ -2,6 +2,7 @@ package hudson.util
import
com.trilead.ssh2.crypto.Base64
import
hudson.FilePath
import
hudson.Functions
import
jenkins.security.ConfidentialStoreRule
import
org.junit.Rule
import
org.junit.Test
...
...
@@ -9,6 +10,8 @@ import org.junit.rules.TemporaryFolder
import
javax.crypto.Cipher
import
static
org
.
junit
.
Assume
.
assumeFalse
/**
*
*
...
...
@@ -77,6 +80,7 @@ class SecretRewriterTest {
*/
@Test
void
recursionDetection
()
{
assumeFalse
(
"Symlinks don't work on Windows very well"
,
Functions
.
isWindows
())
def
sw
=
new
SecretRewriter
();
def
st
=
StreamTaskListener
.
fromStdout
()
...
...
core/src/test/java/jenkins/model/RunIdMigratorTest.java
浏览文件 @
335fb4bc
...
...
@@ -24,6 +24,7 @@
package
jenkins.model
;
import
hudson.Functions
;
import
hudson.Util
;
import
hudson.util.StreamTaskListener
;
import
java.io.File
;
...
...
@@ -38,6 +39,8 @@ import java.util.logging.Level;
import
org.apache.commons.io.FileUtils
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
junit
.
Assume
.
assumeFalse
;
import
org.junit.Before
;
import
org.junit.BeforeClass
;
import
org.junit.Rule
;
...
...
@@ -79,6 +82,7 @@ public class RunIdMigratorTest {
}
@Test
public
void
legacy
()
throws
Exception
{
assumeFalse
(
"Symlinks don't work well on Windows"
,
Functions
.
isWindows
());
write
(
"2014-01-02_03-04-05/build.xml"
,
"<?xml version='1.0' encoding='UTF-8'?>\n<run>\n <stuff>ok</stuff>\n <number>99</number>\n <otherstuff>ok</otherstuff>\n</run>"
);
link
(
"99"
,
"2014-01-02_03-04-05"
);
link
(
"lastFailedBuild"
,
"-1"
);
...
...
@@ -97,6 +101,7 @@ public class RunIdMigratorTest {
}
@Test
public
void
reRunMigration
()
throws
Exception
{
assumeFalse
(
"Symlinks don't work well on Windows"
,
Functions
.
isWindows
());
write
(
"2014-01-02_03-04-04/build.xml"
,
"<run>\n <number>98</number>\n</run>"
);
link
(
"98"
,
"2014-01-02_03-04-04"
);
write
(
"99/build.xml"
,
"<?xml version='1.0' encoding='UTF-8'?>\n<run>\n <stuff>ok</stuff>\n <timestamp>1388649845000</timestamp>\n <otherstuff>ok</otherstuff>\n</run>"
);
...
...
@@ -108,6 +113,7 @@ public class RunIdMigratorTest {
}
@Test
public
void
reverseImmediately
()
throws
Exception
{
assumeFalse
(
"Symlinks don't work well on Windows"
,
Functions
.
isWindows
());
File
root
=
dir
;
dir
=
new
File
(
dir
,
"jobs/somefolder/jobs/someproject/promotions/OK/builds"
);
write
(
"99/build.xml"
,
"<?xml version='1.0' encoding='UTF-8'?>\n<run>\n <stuff>ok</stuff>\n <id>2014-01-02_03-04-05</id>\n <timestamp>1388649845000</timestamp>\n <otherstuff>ok</otherstuff>\n</run>"
);
...
...
@@ -120,6 +126,7 @@ public class RunIdMigratorTest {
}
@Test
public
void
reverseAfterNewBuilds
()
throws
Exception
{
assumeFalse
(
"Symlinks don't work well on Windows"
,
Functions
.
isWindows
());
File
root
=
dir
;
dir
=
new
File
(
dir
,
"jobs/someproject/modules/test$test/builds"
);
write
(
"1/build.xml"
,
"<?xml version='1.0' encoding='UTF-8'?>\n<run>\n <stuff>ok</stuff>\n <timestamp>1388649845000</timestamp>\n <otherstuff>ok</otherstuff>\n</run>"
);
...
...
@@ -130,6 +137,7 @@ public class RunIdMigratorTest {
}
@Test
public
void
reverseMatrixAfterNewBuilds
()
throws
Exception
{
assumeFalse
(
"Symlinks don't work well on Windows"
,
Functions
.
isWindows
());
File
root
=
dir
;
dir
=
new
File
(
dir
,
"jobs/someproject/Environment=prod/builds"
);
write
(
"1/build.xml"
,
"<?xml version='1.0' encoding='UTF-8'?>\n<run>\n <stuff>ok</stuff>\n <timestamp>1388649845000</timestamp>\n <otherstuff>ok</otherstuff>\n</run>"
);
...
...
@@ -140,6 +148,7 @@ public class RunIdMigratorTest {
}
@Test
public
void
reverseMavenAfterNewBuilds
()
throws
Exception
{
assumeFalse
(
"Symlinks don't work well on Windows"
,
Functions
.
isWindows
());
File
root
=
dir
;
dir
=
new
File
(
dir
,
"jobs/someproject/test$test/builds"
);
write
(
"1/build.xml"
,
"<?xml version='1.0' encoding='UTF-8'?>\n<run>\n <stuff>ok</stuff>\n <timestamp>1388649845000</timestamp>\n <otherstuff>ok</otherstuff>\n</run>"
);
...
...
core/src/test/java/jenkins/util/VirtualFileTest.java
浏览文件 @
335fb4bc
...
...
@@ -24,6 +24,7 @@
package
jenkins.util
;
import
hudson.Functions
;
import
hudson.Util
;
import
hudson.model.TaskListener
;
import
java.io.File
;
...
...
@@ -32,6 +33,8 @@ import org.apache.commons.io.FileUtils;
import
org.apache.commons.io.IOUtils
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
junit
.
Assume
.
assumeFalse
;
import
org.junit.Rule
;
import
org.junit.rules.TemporaryFolder
;
import
org.jvnet.hudson.test.Issue
;
...
...
@@ -42,6 +45,7 @@ public class VirtualFileTest {
@Issue
(
"SECURITY-162"
)
@Test
public
void
outsideSymlinks
()
throws
Exception
{
assumeFalse
(
"Symlinks don't work well on Windows"
,
Functions
.
isWindows
());
File
ws
=
tmp
.
newFolder
(
"ws"
);
FileUtils
.
write
(
new
File
(
ws
,
"safe"
),
"safe"
);
Util
.
createSymlink
(
ws
,
"safe"
,
"supported"
,
TaskListener
.
NULL
);
...
...
test/src/test/groovy/hudson/cli/SetBuildParameterCommandTest.groovy
浏览文件 @
335fb4bc
package
hudson.cli
import
hudson.Functions
import
hudson.Launcher
import
hudson.model.AbstractBuild
import
hudson.model.BuildListener
...
...
@@ -8,6 +9,8 @@ import hudson.model.ParametersDefinitionProperty
import
hudson.model.ParameterDefinition
import
hudson.model.Result
import
hudson.model.StringParameterDefinition
import
hudson.tasks.BatchFile
import
hudson.tasks.Builder
import
hudson.tasks.Shell
import
jenkins.model.JenkinsLocationConfiguration
import
org.junit.Assert
...
...
@@ -39,9 +42,9 @@ public class SetBuildParameterCommandTest {
});
List
<
ParameterDefinition
>
pd
=
[
new
StringParameterDefinition
(
"a"
,
""
),
new
StringParameterDefinition
(
"b"
,
""
)];
p
.
addProperty
(
new
ParametersDefinitionProperty
(
pd
))
p
.
buildersList
.
add
(
new
Shell
(
"java -jar cli.jar set-build-parameter a b"
))
p
.
buildersList
.
add
(
new
Shell
(
"java -jar cli.jar set-build-parameter a x"
))
p
.
buildersList
.
add
(
new
Shell
(
"java -jar cli.jar set-build-parameter b y"
))
p
.
buildersList
.
add
(
createScriptBuilder
(
"java -jar cli.jar set-build-parameter a b"
))
p
.
buildersList
.
add
(
createScriptBuilder
(
"java -jar cli.jar set-build-parameter a x"
))
p
.
buildersList
.
add
(
createScriptBuilder
(
"java -jar cli.jar set-build-parameter b y"
))
def
r
=
[:];
...
...
@@ -50,10 +53,24 @@ public class SetBuildParameterCommandTest {
assert
r
.
equals
([
"a"
:
"x"
,
"b"
:
"y"
]);
p
.
buildersList
.
add
(
new
Shell
(
"BUILD_NUMBER=1 java -jar cli.jar set-build-parameter a b"
));
if
(
Functions
.
isWindows
())
{
p
.
buildersList
.
add
(
new
BatchFile
(
"set BUILD_NUMBER=1\r\njava -jar cli.jar set-build-parameter a b"
))
}
else
{
p
.
buildersList
.
add
(
new
Shell
(
"BUILD_NUMBER=1 java -jar cli.jar set-build-parameter a b"
))
}
def
b2
=
j
.
assertBuildStatus
(
Result
.
FAILURE
,
p
.
scheduleBuild2
(
0
).
get
());
r
=
[:];
b
.
getAction
(
ParametersAction
.
class
).
parameters
.
each
{
v
->
r
[
v
.
name
]=
v
.
value
}
assert
r
.
equals
([
"a"
:
"x"
,
"b"
:
"y"
]);
}
//TODO: determine if this should be pulled out into JenkinsRule or something
/**
* Create a script based builder (either Shell or BatchFile) depending on platform
* @param script the contents of the script to run
* @return A Builder instance of either Shell or BatchFile
*/
private
Builder
createScriptBuilder
(
String
script
)
{
return
Functions
.
isWindows
()
?
new
BatchFile
(
script
)
:
new
Shell
(
script
);
}
}
test/src/test/groovy/hudson/model/AbstractProjectTest.groovy
浏览文件 @
335fb4bc
此差异已折叠。
点击以展开。
test/src/test/groovy/hudson/util/TextFileTest.groovy
浏览文件 @
335fb4bc
...
...
@@ -44,9 +44,9 @@ class TextFileTest {
f
.
text
=
getClass
().
getResource
(
"ascii.txt"
).
text
def
t
=
new
TextFile
(
f
)
def
tail
35
=
"la, vitae interdum quam rutrum id.\n"
assert
t
.
fastTail
(
35
).
equals
(
tail35
)
assert
tail
35
.
length
()==
35
def
tail
Str
=
"la, vitae interdum quam rutrum id."
+
System
.
lineSeparator
()
assert
t
.
fastTail
(
tailStr
.
length
()).
equals
(
tailStr
)
assert
tail
Str
.
length
()==(
34
+
System
.
lineSeparator
().
length
())
}
@Test
...
...
test/src/test/java/hudson/PluginManagerTest.java
浏览文件 @
335fb4bc
...
...
@@ -50,6 +50,7 @@ import net.sf.json.JSONObject;
import
org.apache.commons.io.FileUtils
;
import
org.apache.tools.ant.filters.StringInputStream
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
junit
.
Assume
.
assumeFalse
;
import
org.junit.Rule
;
import
org.junit.Test
;
...
...
@@ -213,6 +214,7 @@ public class PluginManagerTest {
}
@Test
public
void
prevalidateConfig
()
throws
Exception
{
assumeFalse
(
"TODO: Implement this test on Windows"
,
Functions
.
isWindows
());
PersistedList
<
UpdateSite
>
sites
=
r
.
jenkins
.
getUpdateCenter
().
getSites
();
sites
.
clear
();
URL
url
=
PluginManagerTest
.
class
.
getResource
(
"/plugins/tasks-update-center.json"
);
...
...
@@ -467,6 +469,7 @@ public class PluginManagerTest {
}
@Test
public
void
uploadDependencyResolution
()
throws
Exception
{
assumeFalse
(
"TODO: Implement this test for Windows"
,
Functions
.
isWindows
());
PersistedList
<
UpdateSite
>
sites
=
r
.
jenkins
.
getUpdateCenter
().
getSites
();
sites
.
clear
();
URL
url
=
PluginManagerTest
.
class
.
getResource
(
"/plugins/upload-test-update-center.json"
);
...
...
test/src/test/java/hudson/ProcStarterTest.java
浏览文件 @
335fb4bc
...
...
@@ -103,7 +103,8 @@ public class ProcStarterTest {
@Override
public
Environment
setUp
(
AbstractBuild
build
,
Launcher
launcher
,
BuildListener
listener
)
throws
IOException
,
InterruptedException
{
Launcher
.
ProcStarter
starter
=
launcher
.
launch
().
cmds
(
"echo"
,
"Hello"
);
String
[]
cmds
=
Functions
.
isWindows
()
?
new
String
[]
{
"cmd.exe"
,
"/C"
,
"echo"
,
"Hello"
}
:
new
String
[]
{
"echo"
,
"Hello"
};
Launcher
.
ProcStarter
starter
=
launcher
.
launch
().
cmds
(
cmds
);
starter
.
start
();
starter
.
join
();
return
new
Environment
()
{
...
...
@@ -148,7 +149,9 @@ public class ProcStarterTest {
@Override
public
boolean
perform
(
AbstractBuild
<?,
?>
build
,
Launcher
launcher
,
BuildListener
listener
)
throws
InterruptedException
,
IOException
{
Launcher
.
ProcStarter
starter
=
launcher
.
launch
().
cmds
(
"echo"
,
"Hello"
).
pwd
(
new
File
(
"/this/path/doesnt/exist"
));
String
[]
cmds
=
Functions
.
isWindows
()
?
new
String
[]
{
"cmd.exe"
,
"/C"
,
"echo"
,
"Hello"
}
:
new
String
[]
{
"echo"
,
"Hello"
};
String
path
=
Functions
.
isWindows
()
?
"C:\\this\\path\\doesn't\\exist"
:
"/this/path/doesnt/exist"
;
Launcher
.
ProcStarter
starter
=
launcher
.
launch
().
cmds
(
cmds
).
pwd
(
new
File
(
path
));
starter
.
start
();
starter
.
join
();
return
true
;
...
...
test/src/test/java/hudson/ProcTest.java
浏览文件 @
335fb4bc
...
...
@@ -2,6 +2,7 @@ package hudson;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assume
.
assumeFalse
;
import
hudson.Launcher.LocalLauncher
;
import
hudson.Launcher.RemoteLauncher
;
...
...
@@ -37,6 +38,7 @@ public class ProcTest {
*/
@Test
public
void
remoteProcOutputSync
()
throws
Exception
{
assumeFalse
(
"TODO: Implement this test for Windows"
,
Functions
.
isWindows
());
VirtualChannel
ch
=
createSlaveChannel
();
// keep the pipe fairly busy
...
...
@@ -96,11 +98,13 @@ public class ProcTest {
@Test
public
void
ioPumpingWithLocalLaunch
()
throws
Exception
{
assumeFalse
(
"TODO: Implement this test for Windows"
,
Functions
.
isWindows
());
doIoPumpingTest
(
new
LocalLauncher
(
new
StreamTaskListener
(
System
.
out
,
Charset
.
defaultCharset
())));
}
@Test
public
void
ioPumpingWithRemoteLaunch
()
throws
Exception
{
assumeFalse
(
"TODO: Implement this test for Windows"
,
Functions
.
isWindows
());
doIoPumpingTest
(
new
RemoteLauncher
(
new
StreamTaskListener
(
System
.
out
,
Charset
.
defaultCharset
()),
createSlaveChannel
(),
true
));
...
...
test/src/test/java/hudson/cli/AbstractBuildRangeCommand2Test.java
浏览文件 @
335fb4bc
...
...
@@ -25,10 +25,12 @@
package
hudson.cli
;
import
hudson.Extension
;
import
hudson.Functions
;
import
hudson.model.AbstractBuild
;
import
hudson.model.FreeStyleProject
;
import
hudson.model.Job
;
import
hudson.model.labels.LabelAtom
;
import
hudson.tasks.BatchFile
;
import
hudson.tasks.Shell
;
import
jenkins.model.Jenkins
;
import
org.junit.Before
;
...
...
@@ -88,7 +90,7 @@ public class AbstractBuildRangeCommand2Test {
@Test
public
void
dummyRangeShouldSuccessEvenTheBuildIsRunning
()
throws
Exception
{
FreeStyleProject
project
=
j
.
createFreeStyleProject
(
"aProject"
);
project
.
getBuildersList
().
add
(
new
Shell
(
"echo 1\nsleep 10s"
));
project
.
getBuildersList
().
add
(
Functions
.
isWindows
()
?
new
BatchFile
(
"echo 1\r\nping -n 10 127.0.0.1 >nul"
)
:
new
Shell
(
"echo 1\nsleep 10s"
));
assertThat
(
"Job wasn't scheduled properly"
,
project
.
scheduleBuild
(
0
),
equalTo
(
true
));
// Wait until classProject is started (at least 1s)
...
...
@@ -106,7 +108,7 @@ public class AbstractBuildRangeCommand2Test {
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
"aProject"
,
"1"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1
"
+
System
.
lineSeparator
()
));
}
@Test
public
void
dummyRangeShouldSuccessEvenTheBuildIsStuckInTheQueue
()
throws
Exception
{
...
...
@@ -124,7 +126,7 @@ public class AbstractBuildRangeCommand2Test {
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
"aProject"
,
"1"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds:
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds:
"
+
System
.
lineSeparator
()
));
}
}
test/src/test/java/hudson/cli/AbstractBuildRangeCommandTest.java
浏览文件 @
335fb4bc
...
...
@@ -119,13 +119,13 @@ public class AbstractBuildRangeCommandTest {
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
String
.
valueOf
(
BUILDS
+
1
));
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds:
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds:
"
+
System
.
lineSeparator
()
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
String
.
valueOf
(
deleted
[
0
]));
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds:
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds:
"
+
System
.
lineSeparator
()
));
}
@Test
public
void
dummyRangeNumberSingleShouldSuccess
()
throws
Exception
{
...
...
@@ -134,28 +134,28 @@ public class AbstractBuildRangeCommandTest {
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"1"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1
"
+
System
.
lineSeparator
()
));
// First with plus symbol '+'
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"+1"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1
"
+
System
.
lineSeparator
()
));
// In the middle
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"10"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 10
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 10
"
+
System
.
lineSeparator
()
));
// In the middle with plus symbol '+'
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"+10"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 10
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 10
"
+
System
.
lineSeparator
()
));
// Last
result
=
command
...
...
@@ -163,7 +163,7 @@ public class AbstractBuildRangeCommandTest {
.
invokeWithArgs
(
PROJECT_NAME
,
String
.
valueOf
(
BUILDS
));
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
String
.
format
(
"Builds: %s
\n"
,
String
.
valueOf
(
BUILDS
))));
containsString
(
String
.
format
(
"Builds: %s
"
+
System
.
lineSeparator
()
,
String
.
valueOf
(
BUILDS
))));
// Last with the plus symbol '+'
result
=
command
...
...
@@ -171,7 +171,7 @@ public class AbstractBuildRangeCommandTest {
.
invokeWithArgs
(
PROJECT_NAME
,
'+'
+
String
.
valueOf
(
BUILDS
));
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
String
.
format
(
"Builds: %s
\n"
,
String
.
valueOf
(
BUILDS
))));
containsString
(
String
.
format
(
"Builds: %s
"
+
System
.
lineSeparator
()
,
String
.
valueOf
(
BUILDS
))));
}
@Test
public
void
dummyRangeNumberSingleShouldSuccessIfBuildNumberIsZero
()
throws
Exception
{
...
...
@@ -179,13 +179,13 @@ public class AbstractBuildRangeCommandTest {
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"0"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds:
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds:
"
+
System
.
lineSeparator
()
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"+0"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds:
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds:
"
+
System
.
lineSeparator
()
));
}
@Test
public
void
dummyRangeNumberSingleShouldFailIfBuildNumberIsNegative
()
throws
Exception
{
...
...
@@ -227,7 +227,7 @@ public class AbstractBuildRangeCommandTest {
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
""
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds:
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds:
"
+
System
.
lineSeparator
()
));
}
@Test
public
void
dummyRangeNumberSingleShouldFailIfBuildNumberIsSpace
()
throws
Exception
{
...
...
@@ -244,7 +244,7 @@ public class AbstractBuildRangeCommandTest {
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
","
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds:
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds:
"
+
System
.
lineSeparator
()
));
}
@Test
public
void
dummyRangeNumberSingleShouldFailIfBuildNumberIsHyphen
()
throws
Exception
{
...
...
@@ -261,40 +261,40 @@ public class AbstractBuildRangeCommandTest {
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"1,2"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2
"
+
System
.
lineSeparator
()
));
// With plus symbol '+'
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"1,+2,4"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2,4
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2,4
"
+
System
.
lineSeparator
()
));
// Build specified twice
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"1,1"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,1
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,1
"
+
System
.
lineSeparator
()
));
// Build with zero build number
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"0,1,2"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2
"
+
System
.
lineSeparator
()
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"1,0,2"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2
"
+
System
.
lineSeparator
()
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"1,2,0"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2
"
+
System
.
lineSeparator
()
));
}
@Test
public
void
dummyRangeNumberMultiShouldSuccessIfSomeBuildDoesNotExist
()
throws
Exception
{
...
...
@@ -302,19 +302,19 @@ public class AbstractBuildRangeCommandTest {
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"1,2,"
+
deleted
[
0
]);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2
"
+
System
.
lineSeparator
()
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
String
.
format
(
"1,%d,%d"
,
deleted
[
0
],
deleted
[
0
]+
1
));
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
String
.
format
(
"Builds: 1,%d
\n"
,
deleted
[
0
]+
1
)));
assertThat
(
result
.
stdout
(),
containsString
(
String
.
format
(
"Builds: 1,%d
"
+
System
.
lineSeparator
()
,
deleted
[
0
]+
1
)));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
String
.
format
(
"%d,%d,%d"
,
deleted
[
0
]-
1
,
deleted
[
0
],
deleted
[
0
]+
1
));
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
String
.
format
(
"Builds: %d,%d
\n"
,
deleted
[
0
]-
1
,
deleted
[
0
]+
1
)));
assertThat
(
result
.
stdout
(),
containsString
(
String
.
format
(
"Builds: %d,%d
"
+
System
.
lineSeparator
()
,
deleted
[
0
]-
1
,
deleted
[
0
]+
1
)));
}
@Test
public
void
dummyRangeNumberMultiShouldFailIfBuildNumberIsNegative
()
throws
Exception
{
...
...
@@ -504,25 +504,25 @@ public class AbstractBuildRangeCommandTest {
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"1-2"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2
"
+
System
.
lineSeparator
()
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"+1-+2"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2
"
+
System
.
lineSeparator
()
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"1-1"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1
"
+
System
.
lineSeparator
()
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"+1-+1"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1
"
+
System
.
lineSeparator
()
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
...
...
@@ -536,49 +536,49 @@ public class AbstractBuildRangeCommandTest {
builds
+=
i
;
next
=
true
;
}
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: "
+
builds
+
"\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: "
+
builds
+
System
.
lineSeparator
()
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"+1-+"
+
deleted
[
0
]);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: "
+
builds
+
"\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: "
+
builds
+
System
.
lineSeparator
()
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"0-1"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1
"
+
System
.
lineSeparator
()
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"+0-+1"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1
"
+
System
.
lineSeparator
()
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"0-2"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2
"
+
System
.
lineSeparator
()
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"+0-+2"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2
"
+
System
.
lineSeparator
()
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"0-0"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds:
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds:
"
+
System
.
lineSeparator
()
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"+0-+0"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds:
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds:
"
+
System
.
lineSeparator
()
));
}
@Test
public
void
dummyRangeRangeSingleShouldSuccessIfSomeBuildDoesNotExist
()
throws
Exception
{
...
...
@@ -586,19 +586,19 @@ public class AbstractBuildRangeCommandTest {
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
String
.
format
(
"%d-%d"
,
deleted
[
0
],
deleted
[
0
]+
1
));
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
String
.
format
(
"Builds: %d
\n"
,
deleted
[
0
]
+
1
)));
assertThat
(
result
.
stdout
(),
containsString
(
String
.
format
(
"Builds: %d
"
+
System
.
lineSeparator
()
,
deleted
[
0
]
+
1
)));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
String
.
format
(
"%d-%d"
,
deleted
[
0
]-
1
,
deleted
[
0
]+
1
));
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
String
.
format
(
"Builds: %d,%d
\n"
,
deleted
[
0
]-
1
,
deleted
[
0
]+
1
)));
assertThat
(
result
.
stdout
(),
containsString
(
String
.
format
(
"Builds: %d,%d
"
+
System
.
lineSeparator
()
,
deleted
[
0
]-
1
,
deleted
[
0
]+
1
)));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
String
.
format
(
"%d-%d"
,
deleted
[
0
]-
1
,
deleted
[
0
]));
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
String
.
format
(
"Builds: %d
\n"
,
deleted
[
0
]-
1
)));
assertThat
(
result
.
stdout
(),
containsString
(
String
.
format
(
"Builds: %d
"
+
System
.
lineSeparator
()
,
deleted
[
0
]-
1
)));
}
@Test
public
void
dummyRangeRangeSingleShouldFailIfBuildRangeContainsZeroAndNegative
()
throws
Exception
{
...
...
@@ -955,25 +955,25 @@ public class AbstractBuildRangeCommandTest {
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"1-2,3-4"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2,3,4
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2,3,4
"
+
System
.
lineSeparator
()
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"1-3,3-4"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2,3,3,4
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2,3,3,4
"
+
System
.
lineSeparator
()
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"1-4,2-3"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2,3,4,2,3
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2,3,4,2,3
"
+
System
.
lineSeparator
()
));
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
)
.
invokeWithArgs
(
PROJECT_NAME
,
"1-2,4-5"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2,4
\n"
));
assertThat
(
result
.
stdout
(),
containsString
(
"Builds: 1,2,4
"
+
System
.
lineSeparator
()
));
}
@Extension
...
...
test/src/test/java/hudson/cli/ConsoleCommandTest.java
浏览文件 @
335fb4bc
...
...
@@ -24,12 +24,14 @@
package
hudson.cli
;
import
hudson.Functions
;
import
hudson.model.FreeStyleProject
;
import
hudson.model.Item
;
import
hudson.model.Job
;
import
hudson.model.Result
;
import
hudson.model.Run
;
import
hudson.model.labels.LabelAtom
;
import
hudson.tasks.BatchFile
;
import
hudson.tasks.Shell
;
import
jenkins.model.Jenkins
;
import
org.junit.Before
;
...
...
@@ -156,7 +158,11 @@ public class ConsoleCommandTest {
@Test
public
void
consoleShouldSuccessWithLastBuild
()
throws
Exception
{
FreeStyleProject
project
=
j
.
createFreeStyleProject
(
"aProject"
);
project
.
getBuildersList
().
add
(
new
Shell
(
"echo 1"
));
if
(
Functions
.
isWindows
())
{
project
.
getBuildersList
().
add
(
new
BatchFile
(
"echo 1"
));
}
else
{
project
.
getBuildersList
().
add
(
new
Shell
(
"echo 1"
));
}
assertThat
(
project
.
scheduleBuild2
(
0
).
get
().
getLog
(),
containsString
(
"echo 1"
));
final
CLICommandInvoker
.
Result
result
=
command
...
...
@@ -170,7 +176,11 @@ public class ConsoleCommandTest {
@Test
public
void
consoleShouldSuccessWithSpecifiedBuildNumber
()
throws
Exception
{
FreeStyleProject
project
=
j
.
createFreeStyleProject
(
"aProject"
);
project
.
getBuildersList
().
add
(
new
Shell
(
"echo ${BUILD_NUMBER}"
));
if
(
Functions
.
isWindows
())
{
project
.
getBuildersList
().
add
(
new
BatchFile
(
"echo %BUILD_NUMBER%"
));
}
else
{
project
.
getBuildersList
().
add
(
new
Shell
(
"echo ${BUILD_NUMBER}"
));
}
assertThat
(
project
.
scheduleBuild2
(
0
).
get
().
getLog
(),
containsString
(
"echo 1"
));
assertThat
(
project
.
scheduleBuild2
(
0
).
get
().
getLog
(),
containsString
(
"echo 2"
));
assertThat
(
project
.
scheduleBuild2
(
0
).
get
().
getLog
(),
containsString
(
"echo 3"
));
...
...
@@ -184,10 +194,15 @@ public class ConsoleCommandTest {
}
@Test
public
void
consoleShouldSuccessWithFollow
()
throws
Exception
{
FreeStyleProject
project
=
j
.
createFreeStyleProject
(
"aProject"
);
project
.
getBuildersList
().
add
(
new
Shell
(
"echo start - ${BUILD_NUMBER}\nsleep 10s\n"
+
"echo after sleep - ${BUILD_NUMBER}"
));
//TODO: do we really want to sleep for 10 seconds?
if
(
Functions
.
isWindows
())
{
project
.
getBuildersList
().
add
(
new
BatchFile
(
"echo start - %BUILD_NUMBER%\r\n"
+
"ping -n 10 127.0.0.1 >nul\r\necho after sleep - %BUILD_NUMBER%"
));
}
else
{
project
.
getBuildersList
().
add
(
new
Shell
(
"echo start - ${BUILD_NUMBER}\nsleep 10s\n"
+
"echo after sleep - ${BUILD_NUMBER}"
));
}
if
(!
project
.
scheduleBuild
(
0
))
{
fail
(
"Job wasn't scheduled properly"
);
}
...
...
@@ -229,14 +244,18 @@ public class ConsoleCommandTest {
@Test
public
void
consoleShouldSuccessWithLastNLines
()
throws
Exception
{
FreeStyleProject
project
=
j
.
createFreeStyleProject
(
"aProject"
);
project
.
getBuildersList
().
add
(
new
Shell
(
"echo 1\necho 2\necho 3\necho 4\necho 5"
));
if
(
Functions
.
isWindows
())
{
project
.
getBuildersList
().
add
(
new
BatchFile
(
"echo 1\r\necho 2\r\necho 3\r\necho 4\r\necho 5"
));
}
else
{
project
.
getBuildersList
().
add
(
new
Shell
(
"echo 1\necho 2\necho 3\necho 4\necho 5"
));
}
project
.
scheduleBuild2
(
0
).
get
();
assertThat
(
project
.
getBuildByNumber
(
1
).
getLog
(),
containsString
(
"echo 1"
));
assertThat
(
project
.
getBuildByNumber
(
1
).
getLog
(),
containsString
(
"echo 5"
));
final
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
,
Item
.
BUILD
)
.
invokeWithArgs
(
"aProject"
,
"1"
,
"-n"
,
"4"
);
.
invokeWithArgs
(
"aProject"
,
"1"
,
"-n"
,
Functions
.
isWindows
()
?
"5"
:
"4"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
not
(
containsString
(
"echo 1"
)));
...
...
@@ -246,9 +265,16 @@ public class ConsoleCommandTest {
@Test
public
void
consoleShouldSuccessWithLastNLinesAndFollow
()
throws
Exception
{
FreeStyleProject
project
=
j
.
createFreeStyleProject
(
"aProject"
);
project
.
getBuildersList
().
add
(
new
Shell
(
"echo 1\necho 2\necho 3\necho 4\necho 5\n"
+
"sleep 10s\n"
+
"echo 6\necho 7\necho 8\necho 9"
));
//TODO: do we really want to sleep for 10 seconds?
if
(
Functions
.
isWindows
())
{
// the ver >NUL is to reset ERRORLEVEL so we don't fail (ping causes the error)
project
.
getBuildersList
().
add
(
new
BatchFile
(
"echo 1\r\necho 2\r\necho 3\r\necho 4\r\necho 5\r\n"
+
"ping -n 10 127.0.0.1 >nul\r\necho 6\r\necho 7\r\necho 8\r\necho 9"
));
}
else
{
project
.
getBuildersList
().
add
(
new
Shell
(
"echo 1\necho 2\necho 3\necho 4\necho 5\n"
+
"sleep 10s\n"
+
"echo 6\necho 7\necho 8\necho 9"
));
}
if
(!
project
.
scheduleBuild
(
0
))
{
fail
(
"Job wasn't scheduled properly"
);
...
...
@@ -270,7 +296,7 @@ public class ConsoleCommandTest {
CLICommandInvoker
.
Result
result
=
command
.
authorizedTo
(
Jenkins
.
READ
,
Job
.
READ
,
Item
.
BUILD
)
.
invokeWithArgs
(
"aProject"
,
"1"
,
"-f"
,
"-n"
,
"4"
);
.
invokeWithArgs
(
"aProject"
,
"1"
,
"-f"
,
"-n"
,
Functions
.
isWindows
()
?
"5"
:
"4"
);
assertThat
(
result
,
succeeded
());
assertThat
(
result
.
stdout
(),
not
(
containsString
(
"echo 1"
)));
...
...
test/src/test/java/hudson/cli/DeleteBuildsCommandTest.java
浏览文件 @
335fb4bc
...
...
@@ -24,6 +24,7 @@
package
hudson.cli
;
import
hudson.Functions
;
import
hudson.model.ExecutorTest
;
import
hudson.model.FreeStyleProject
;
import
hudson.model.Job
;
...
...
@@ -43,6 +44,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
hasSize
;
import
static
org
.
junit
.
Assume
.
assumeFalse
;
/**
* @author pjanouse
...
...
@@ -135,6 +137,7 @@ public class DeleteBuildsCommandTest {
}
@Test
public
void
deleteBuildsShouldSuccessEvenTheBuildIsRunning
()
throws
Exception
{
assumeFalse
(
"You can't delete files that are in use on Windows"
,
Functions
.
isWindows
());
FreeStyleProject
project
=
j
.
createFreeStyleProject
(
"aProject"
);
ExecutorTest
.
startBlockingBuild
(
project
);
assertThat
(((
FreeStyleProject
)
j
.
jenkins
.
getItem
(
"aProject"
)).
getBuilds
(),
hasSize
(
1
));
...
...
test/src/test/java/hudson/cli/ReloadJobCommandTest.java
浏览文件 @
335fb4bc
...
...
@@ -25,8 +25,11 @@
package
hudson.cli
;
import
hudson.FilePath
;
import
hudson.Functions
;
import
hudson.model.FreeStyleProject
;
import
hudson.model.Job
;
import
hudson.tasks.BatchFile
;
import
hudson.tasks.Builder
;
import
hudson.tasks.Shell
;
import
jenkins.model.Jenkins
;
import
org.junit.Before
;
...
...
@@ -58,7 +61,7 @@ public class ReloadJobCommandTest {
@Test
public
void
reloadJobShouldFailWithoutJobConfigurePermission
()
throws
Exception
{
FreeStyleProject
project
=
j
.
createFreeStyleProject
(
"aProject"
);
project
.
getBuildersList
().
add
(
new
Shell
(
"echo 1"
));
project
.
getBuildersList
().
add
(
createScriptBuilder
(
"echo 1"
));
assertThat
(
project
.
scheduleBuild2
(
0
).
get
().
getLog
(),
containsString
(
"echo 1"
));
changeProjectOnTheDisc
(
project
,
"echo 1"
,
"echo 2"
);
...
...
@@ -77,7 +80,7 @@ public class ReloadJobCommandTest {
@Test
public
void
reloadJobShouldFailWithoutJobReadPermission
()
throws
Exception
{
FreeStyleProject
project
=
j
.
createFreeStyleProject
(
"aProject"
);
project
.
getBuildersList
().
add
(
new
Shell
(
"echo 1"
));
project
.
getBuildersList
().
add
(
createScriptBuilder
(
"echo 1"
));
assertThat
(
project
.
scheduleBuild2
(
0
).
get
().
getLog
(),
containsString
(
"echo 1"
));
changeProjectOnTheDisc
(
project
,
"echo 1"
,
"echo 2"
);
...
...
@@ -96,7 +99,7 @@ public class ReloadJobCommandTest {
@Test
public
void
reloadJobShouldSucceed
()
throws
Exception
{
FreeStyleProject
project
=
j
.
createFreeStyleProject
(
"aProject"
);
project
.
getBuildersList
().
add
(
new
Shell
(
"echo 1"
));
project
.
getBuildersList
().
add
(
createScriptBuilder
(
"echo 1"
));
assertThat
(
project
.
scheduleBuild2
(
0
).
get
().
getLog
(),
containsString
(
"echo 1"
));
...
...
@@ -134,13 +137,12 @@ public class ReloadJobCommandTest {
}
@Test
public
void
reloadJobManyShouldSucceed
()
throws
Exception
{
FreeStyleProject
project1
=
j
.
createFreeStyleProject
(
"aProject1"
);
project1
.
getBuildersList
().
add
(
new
Shell
(
"echo 1"
));
project1
.
getBuildersList
().
add
(
createScriptBuilder
(
"echo 1"
));
FreeStyleProject
project2
=
j
.
createFreeStyleProject
(
"aProject2"
);
project2
.
getBuildersList
().
add
(
new
Shell
(
"echo 1"
));
project2
.
getBuildersList
().
add
(
createScriptBuilder
(
"echo 1"
));
FreeStyleProject
project3
=
j
.
createFreeStyleProject
(
"aProject3"
);
project3
.
getBuildersList
().
add
(
new
Shell
(
"echo 1"
));
project3
.
getBuildersList
().
add
(
createScriptBuilder
(
"echo 1"
));
assertThat
(
project1
.
scheduleBuild2
(
0
).
get
().
getLog
(),
containsString
(
"echo 1"
));
assertThat
(
project2
.
scheduleBuild2
(
0
).
get
().
getLog
(),
containsString
(
"echo 1"
));
...
...
@@ -164,9 +166,9 @@ public class ReloadJobCommandTest {
@Test
public
void
reloadJobManyShouldFailIfFirstJobDoesNotExist
()
throws
Exception
{
FreeStyleProject
project1
=
j
.
createFreeStyleProject
(
"aProject1"
);
project1
.
getBuildersList
().
add
(
new
Shell
(
"echo 1"
));
project1
.
getBuildersList
().
add
(
createScriptBuilder
(
"echo 1"
));
FreeStyleProject
project2
=
j
.
createFreeStyleProject
(
"aProject2"
);
project2
.
getBuildersList
().
add
(
new
Shell
(
"echo 1"
));
project2
.
getBuildersList
().
add
(
createScriptBuilder
(
"echo 1"
));
assertThat
(
project1
.
scheduleBuild2
(
0
).
get
().
getLog
(),
containsString
(
"echo 1"
));
assertThat
(
project2
.
scheduleBuild2
(
0
).
get
().
getLog
(),
containsString
(
"echo 1"
));
...
...
@@ -190,9 +192,9 @@ public class ReloadJobCommandTest {
@Test
public
void
reloadJobManyShouldFailIfMiddleJobDoesNotExist
()
throws
Exception
{
FreeStyleProject
project1
=
j
.
createFreeStyleProject
(
"aProject1"
);
project1
.
getBuildersList
().
add
(
new
Shell
(
"echo 1"
));
project1
.
getBuildersList
().
add
(
createScriptBuilder
(
"echo 1"
));
FreeStyleProject
project2
=
j
.
createFreeStyleProject
(
"aProject2"
);
project2
.
getBuildersList
().
add
(
new
Shell
(
"echo 1"
));
project2
.
getBuildersList
().
add
(
createScriptBuilder
(
"echo 1"
));
assertThat
(
project1
.
scheduleBuild2
(
0
).
get
().
getLog
(),
containsString
(
"echo 1"
));
assertThat
(
project2
.
scheduleBuild2
(
0
).
get
().
getLog
(),
containsString
(
"echo 1"
));
...
...
@@ -216,9 +218,9 @@ public class ReloadJobCommandTest {
@Test
public
void
reloadJobManyShouldFailIfLastJobDoesNotExist
()
throws
Exception
{
FreeStyleProject
project1
=
j
.
createFreeStyleProject
(
"aProject1"
);
project1
.
getBuildersList
().
add
(
new
Shell
(
"echo 1"
));
project1
.
getBuildersList
().
add
(
createScriptBuilder
(
"echo 1"
));
FreeStyleProject
project2
=
j
.
createFreeStyleProject
(
"aProject2"
);
project2
.
getBuildersList
().
add
(
new
Shell
(
"echo 1"
));
project2
.
getBuildersList
().
add
(
createScriptBuilder
(
"echo 1"
));
assertThat
(
project1
.
scheduleBuild2
(
0
).
get
().
getLog
(),
containsString
(
"echo 1"
));
assertThat
(
project2
.
scheduleBuild2
(
0
).
get
().
getLog
(),
containsString
(
"echo 1"
));
...
...
@@ -242,9 +244,9 @@ public class ReloadJobCommandTest {
@Test
public
void
reloadJobManyShouldFailIfMoreJobsDoNotExist
()
throws
Exception
{
FreeStyleProject
project1
=
j
.
createFreeStyleProject
(
"aProject1"
);
project1
.
getBuildersList
().
add
(
new
Shell
(
"echo 1"
));
project1
.
getBuildersList
().
add
(
createScriptBuilder
(
"echo 1"
));
FreeStyleProject
project2
=
j
.
createFreeStyleProject
(
"aProject2"
);
project2
.
getBuildersList
().
add
(
new
Shell
(
"echo 1"
));
project2
.
getBuildersList
().
add
(
createScriptBuilder
(
"echo 1"
));
assertThat
(
project1
.
scheduleBuild2
(
0
).
get
().
getLog
(),
containsString
(
"echo 1"
));
assertThat
(
project2
.
scheduleBuild2
(
0
).
get
().
getLog
(),
containsString
(
"echo 1"
));
...
...
@@ -267,11 +269,10 @@ public class ReloadJobCommandTest {
}
@Test
public
void
reloadJobManyShouldSucceedEvenAJobIsSpecifiedTwice
()
throws
Exception
{
FreeStyleProject
project1
=
j
.
createFreeStyleProject
(
"aProject1"
);
project1
.
getBuildersList
().
add
(
new
Shell
(
"echo 1"
));
project1
.
getBuildersList
().
add
(
createScriptBuilder
(
"echo 1"
));
FreeStyleProject
project2
=
j
.
createFreeStyleProject
(
"aProject2"
);
project2
.
getBuildersList
().
add
(
new
Shell
(
"echo 1"
));
project2
.
getBuildersList
().
add
(
createScriptBuilder
(
"echo 1"
));
assertThat
(
project1
.
scheduleBuild2
(
0
).
get
().
getLog
(),
containsString
(
"echo 1"
));
assertThat
(
project2
.
scheduleBuild2
(
0
).
get
().
getLog
(),
containsString
(
"echo 1"
));
...
...
@@ -303,4 +304,13 @@ public class ReloadJobCommandTest {
FilePath
fp
=
new
FilePath
(
new
File
(
project
.
getRootDir
()+
"/config.xml"
));
fp
.
write
(
fp
.
readToString
().
replace
(
oldstr
,
newstr
),
null
);
}
/**
* Create a script based builder (either Shell or BatchFile) depending on platform
* @param script the contents of the script to run
* @return A Builder instance of either Shell or BatchFile
*/
private
Builder
createScriptBuilder
(
String
script
)
{
return
Functions
.
isWindows
()
?
new
BatchFile
(
script
)
:
new
Shell
(
script
);
}
}
test/src/test/java/hudson/cli/SetBuildDescriptionCommandTest.java
浏览文件 @
335fb4bc
...
...
@@ -25,10 +25,13 @@
package
hudson.cli
;
import
hudson.FilePath
;
import
hudson.Functions
;
import
hudson.model.FreeStyleBuild
;
import
hudson.model.FreeStyleProject
;
import
hudson.model.Job
;
import
hudson.model.Run
;
import
hudson.tasks.BatchFile
;
import
hudson.tasks.Builder
;
import
hudson.tasks.Shell
;
import
jenkins.model.Jenkins
;
import
org.junit.Before
;
...
...
@@ -61,7 +64,7 @@ public class SetBuildDescriptionCommandTest {
@Test
public
void
setBuildDescriptionShouldFailWithoutJobReadPermission
()
throws
Exception
{
FreeStyleProject
project
=
j
.
createFreeStyleProject
(
"aProject"
);
project
.
getBuildersList
().
add
(
new
Shell
(
"echo 1"
));
project
.
getBuildersList
().
add
(
createScriptBuilder
(
"echo 1"
));
assertThat
(
project
.
scheduleBuild2
(
0
).
get
().
getLog
(),
containsString
(
"echo 1"
));
final
CLICommandInvoker
.
Result
result
=
command
...
...
@@ -74,7 +77,7 @@ public class SetBuildDescriptionCommandTest {
@Test
public
void
setBuildDescriptionShouldFailWithoutRunUpdatePermission1
()
throws
Exception
{
FreeStyleProject
project
=
j
.
createFreeStyleProject
(
"aProject"
);
project
.
getBuildersList
().
add
(
new
Shell
(
"echo 1"
));
project
.
getBuildersList
().
add
(
createScriptBuilder
(
"echo 1"
));
assertThat
(
project
.
scheduleBuild2
(
0
).
get
().
getLog
(),
containsString
(
"echo 1"
));
final
CLICommandInvoker
.
Result
result
=
command
...
...
@@ -87,7 +90,7 @@ public class SetBuildDescriptionCommandTest {
@Test
public
void
setBuildDescriptionShouldSucceed
()
throws
Exception
{
FreeStyleProject
project
=
j
.
createFreeStyleProject
(
"aProject"
);
project
.
getBuildersList
().
add
(
new
Shell
(
"echo 1"
));
project
.
getBuildersList
().
add
(
createScriptBuilder
(
"echo 1"
));
FreeStyleBuild
build
=
project
.
scheduleBuild2
(
0
).
get
();
assertThat
(
build
.
getLog
(),
containsString
(
"echo 1"
));
assertThat
(
build
.
getDescription
(),
equalTo
(
null
));
...
...
@@ -133,7 +136,7 @@ public class SetBuildDescriptionCommandTest {
@Test
public
void
setBuildDescriptionShouldFailIfBuildDoesNotExist
()
throws
Exception
{
FreeStyleProject
project
=
j
.
createFreeStyleProject
(
"aProject"
);
project
.
getBuildersList
().
add
(
new
Shell
(
"echo 1"
));
project
.
getBuildersList
().
add
(
createScriptBuilder
(
"echo 1"
));
assertThat
(
project
.
scheduleBuild2
(
0
).
get
().
getLog
(),
containsString
(
"echo 1"
));
final
CLICommandInvoker
.
Result
result
=
command
...
...
@@ -145,4 +148,14 @@ public class SetBuildDescriptionCommandTest {
assertThat
(
result
.
stderr
(),
containsString
(
"ERROR: No such build #2"
));
}
//TODO: determine if this should be pulled out into JenkinsRule or something
/**
* Create a script based builder (either Shell or BatchFile) depending on platform
* @param script the contents of the script to run
* @return A Builder instance of either Shell or BatchFile
*/
private
Builder
createScriptBuilder
(
String
script
)
{
return
Functions
.
isWindows
()
?
new
BatchFile
(
script
)
:
new
Shell
(
script
);
}
}
test/src/test/java/hudson/model/ParametersAction2Test.java
浏览文件 @
335fb4bc
package
hudson.model
;
import
hudson.Functions
;
import
hudson.Launcher
;
import
hudson.tasks.BatchFile
;
import
hudson.tasks.Builder
;
import
org.junit.Rule
;
import
org.junit.Test
;
...
...
@@ -67,7 +69,8 @@ public class ParametersAction2Test {
public
void
backwardCompatibility
()
throws
Exception
{
// Local data contains a parameterized job with two parameters (FOO and BAR) and one build
// with pre-fix format (generated with 1.609.3) with FOO, BAR and UNDEF.
FreeStyleProject
p
=
j
.
jenkins
.
getItemByFullName
(
"parameterized"
,
FreeStyleProject
.
class
);
FreeStyleProject
p
=
j
.
jenkins
.
getItemByFullName
(
Functions
.
isWindows
()
?
"parameterized-windows"
:
"parameterized"
,
FreeStyleProject
.
class
);
FreeStyleBuild
b1
=
p
.
getBuildByNumber
(
1
);
ParametersAction
pa
=
b1
.
getAction
(
ParametersAction
.
class
);
hasParameterWithName
(
pa
,
"FOO"
);
...
...
test/src/test/java/hudson/model/ProjectTest.java
浏览文件 @
335fb4bc
...
...
@@ -25,8 +25,10 @@ package hudson.model;
import
com.gargoylesoftware.htmlunit.HttpMethod
;
import
com.gargoylesoftware.htmlunit.WebRequest
;
import
hudson.*
;
import
hudson.model.queue.QueueTaskFuture
;
import
hudson.security.AccessDeniedException2
;
import
hudson.tasks.*
;
import
org.acegisecurity.context.SecurityContextHolder
;
import
hudson.security.HudsonPrivateSecurityRealm
;
import
hudson.security.GlobalMatrixAuthorizationStrategy
;
...
...
@@ -38,9 +40,7 @@ import org.jvnet.hudson.reactor.ReactorException;
import
org.jvnet.hudson.test.FakeChangeLogSCM
;
import
hudson.scm.SCMRevisionState
;
import
hudson.scm.PollingResult
;
import
hudson.Launcher
;
import
hudson.Launcher.RemoteLauncher
;
import
hudson.Util
;
import
hudson.scm.NullSCM
;
import
hudson.scm.SCM
;
import
hudson.model.queue.SubTaskContributor
;
...
...
@@ -62,15 +62,13 @@ import java.io.Serializable;
import
jenkins.scm.DefaultSCMCheckoutStrategyImpl
;
import
jenkins.scm.SCMCheckoutStrategy
;
import
java.io.File
;
import
hudson.FilePath
;
import
hudson.slaves.EnvironmentVariablesNodeProperty
;
import
hudson.EnvVars
;
import
hudson.model.labels.LabelAtom
;
import
hudson.scm.SCMDescriptor
;
import
hudson.slaves.Cloud
;
import
hudson.slaves.DumbSlave
;
import
hudson.slaves.NodeProvisioner
;
import
hudson.tasks.Shell
;
import
org.jvnet.hudson.test.TestExtension
;
import
java.util.List
;
import
java.util.ArrayList
;
...
...
@@ -81,9 +79,7 @@ import org.junit.Rule;
import
org.junit.Test
;
import
org.jvnet.hudson.test.JenkinsRule
;
import
static
org
.
junit
.
Assert
.*;
import
hudson.tasks.Fingerprinter
;
import
hudson.tasks.ArtifactArchiver
;
import
hudson.tasks.BuildTrigger
;
import
java.util.Map
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.ExecutionException
;
...
...
@@ -194,7 +190,8 @@ public class ProjectTest {
getFilePath
=
true
;
assertNotNull
(
"Project should have any workspace because WorkspaceBrowser find some."
,
p
.
getSomeWorkspace
());
getFilePath
=
false
;
p
.
getBuildersList
().
add
(
new
Shell
(
"echo ahoj > some.log"
));
String
cmd
=
"echo ahoj > some.log"
;
p
.
getBuildersList
().
add
(
Functions
.
isWindows
()
?
new
BatchFile
(
cmd
)
:
new
Shell
(
cmd
));
j
.
buildAndAssertSuccess
(
p
);
assertNotNull
(
"Project should has any workspace."
,
p
.
getSomeWorkspace
());
}
...
...
@@ -202,7 +199,8 @@ public class ProjectTest {
@Test
public
void
testGetSomeBuildWithWorkspace
()
throws
Exception
{
FreeStyleProject
p
=
j
.
createFreeStyleProject
(
"project"
);
p
.
getBuildersList
().
add
(
new
Shell
(
"echo ahoj > some.log"
));
String
cmd
=
"echo ahoj > some.log"
;
p
.
getBuildersList
().
add
(
Functions
.
isWindows
()
?
new
BatchFile
(
cmd
)
:
new
Shell
(
cmd
));
assertNull
(
"Project which has never run should not have any build with workspace."
,
p
.
getSomeBuildWithWorkspace
());
j
.
buildAndAssertSuccess
(
p
);
assertEquals
(
"Last build should have workspace."
,
p
.
getLastBuild
(),
p
.
getSomeBuildWithWorkspace
());
...
...
@@ -213,7 +211,8 @@ public class ProjectTest {
@Issue
(
"JENKINS-10450"
)
@Test
public
void
workspaceBrowsing
()
throws
Exception
{
FreeStyleProject
p
=
j
.
createFreeStyleProject
(
"project"
);
p
.
getBuildersList
().
add
(
new
Shell
(
"echo ahoj > some.log"
));
String
cmd
=
"echo ahoj > some.log"
;
p
.
getBuildersList
().
add
(
Functions
.
isWindows
()
?
new
BatchFile
(
cmd
)
:
new
Shell
(
cmd
));
j
.
buildAndAssertSuccess
(
p
);
JenkinsRule
.
WebClient
wc
=
j
.
createWebClient
();
wc
.
goTo
(
"job/project/ws/some.log"
,
"text/plain"
);
...
...
@@ -360,14 +359,14 @@ public class ProjectTest {
@Test
public
void
testGetCauseOfBlockage
()
throws
Exception
{
FreeStyleProject
p
=
j
.
createFreeStyleProject
(
"project"
);
p
.
getBuildersList
().
add
(
new
Shell
(
"sleep 10"
));
p
.
getBuildersList
().
add
(
Functions
.
isWindows
()
?
new
BatchFile
(
"ping -n 10 127.0.0.1 >nul"
)
:
new
Shell
(
"sleep 10"
));
QueueTaskFuture
<
FreeStyleBuild
>
b1
=
waitForStart
(
p
);
assertInstanceOf
(
"Build can not start because previous build has not finished: "
+
p
.
getCauseOfBlockage
(),
p
.
getCauseOfBlockage
(),
BlockedBecauseOfBuildInProgress
.
class
);
p
.
getLastBuild
().
getExecutor
().
interrupt
();
b1
.
get
();
// wait for it to finish
FreeStyleProject
downstream
=
j
.
createFreeStyleProject
(
"project-downstream"
);
downstream
.
getBuildersList
().
add
(
new
Shell
(
"sleep 10"
));
downstream
.
getBuildersList
().
add
(
Functions
.
isWindows
()
?
new
BatchFile
(
"ping -n 10 127.0.0.1 >nul"
)
:
new
Shell
(
"sleep 10"
));
p
.
getPublishersList
().
add
(
new
BuildTrigger
(
Collections
.
singleton
(
downstream
),
Result
.
SUCCESS
));
Jenkins
.
getInstance
().
rebuildDependencyGraph
();
p
.
setBlockBuildWhenDownstreamBuilding
(
true
);
...
...
@@ -606,7 +605,8 @@ public class ProjectTest {
auth
.
add
(
Jenkins
.
READ
,
user
.
getId
());
Slave
slave
=
j
.
createOnlineSlave
();
project
.
setAssignedLabel
(
slave
.
getSelfLabel
());
project
.
getBuildersList
().
add
(
new
Shell
(
"echo hello > change.log"
));
String
cmd
=
"echo hello > change.log"
;
project
.
getBuildersList
().
add
(
Functions
.
isWindows
()?
new
BatchFile
(
cmd
)
:
new
Shell
(
cmd
));
j
.
buildAndAssertSuccess
(
project
);
JenkinsRule
.
WebClient
wc
=
j
.
createWebClient
().
login
(
user
.
getId
(),
"password"
);
WebRequest
request
=
new
WebRequest
(
new
URL
(
wc
.
getContextPath
()
+
project
.
getUrl
()
+
"doWipeOutWorkspace"
),
HttpMethod
.
POST
);
...
...
test/src/test/java/hudson/model/QueueTest.java
浏览文件 @
335fb4bc
...
...
@@ -30,6 +30,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlForm;
import
com.gargoylesoftware.htmlunit.html.HtmlFormUtil
;
import
com.gargoylesoftware.htmlunit.html.HtmlPage
;
import
com.gargoylesoftware.htmlunit.xml.XmlPage
;
import
hudson.Functions
;
import
hudson.Launcher
;
import
hudson.XmlFile
;
import
hudson.matrix.Axis
;
...
...
@@ -62,6 +63,7 @@ import hudson.slaves.DummyCloudImpl;
import
hudson.slaves.NodeProperty
;
import
hudson.slaves.NodePropertyDescriptor
;
import
hudson.slaves.NodeProvisionerRule
;
import
hudson.tasks.BatchFile
;
import
hudson.tasks.BuildTrigger
;
import
hudson.tasks.Shell
;
import
hudson.triggers.SCMTrigger.SCMTriggerCause
;
...
...
@@ -118,6 +120,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
junit
.
Assume
.
assumeFalse
;
/**
* @author Kohsuke Kawaguchi
...
...
@@ -378,7 +381,11 @@ public class QueueTest {
m
.
addProperty
(
new
ParametersDefinitionProperty
(
new
StringParameterDefinition
(
"FOO"
,
"value"
)
));
m
.
getBuildersList
().
add
(
new
Shell
(
"sleep 3"
));
if
(
Functions
.
isWindows
())
{
m
.
getBuildersList
().
add
(
new
BatchFile
(
"ping -n 3 127.0.0.1 >nul"
));
}
else
{
m
.
getBuildersList
().
add
(
new
Shell
(
"sleep 3"
));
}
m
.
setAxes
(
new
AxisList
(
new
TextAxis
(
"DoesntMatter"
,
"aaa"
,
"bbb"
)));
List
<
Future
<
MatrixBuild
>>
futures
=
new
ArrayList
<
Future
<
MatrixBuild
>>();
...
...
test/src/test/java/hudson/model/labels/LabelExpressionTest.java
浏览文件 @
335fb4bc
...
...
@@ -24,8 +24,10 @@
package
hudson.model.labels
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
junit
.
Assume
.
assumeFalse
;
import
antlr.ANTLRException
;
import
hudson.Functions
;
import
hudson.Launcher
;
import
hudson.model.AbstractBuild
;
import
hudson.model.AbstractProject
;
...
...
@@ -189,6 +191,7 @@ public class LabelExpressionTest {
@Test
public
void
dataCompatibilityWithHostNameWithWhitespace
()
throws
Exception
{
assumeFalse
(
"Windows can't have paths with colons, skipping"
,
Functions
.
isWindows
());
DumbSlave
slave
=
new
DumbSlave
(
"abc def (xyz) : test"
,
"dummy"
,
j
.
createTmpDir
().
getPath
(),
"1"
,
Mode
.
NORMAL
,
""
,
j
.
createComputerLauncher
(
null
),
RetentionStrategy
.
NOOP
,
Collections
.
EMPTY_LIST
);
j
.
jenkins
.
addNode
(
slave
);
...
...
test/src/test/java/hudson/tasks/ArtifactArchiverTest.java
浏览文件 @
335fb4bc
...
...
@@ -26,6 +26,7 @@ package hudson.tasks;
import
hudson.AbortException
;
import
hudson.FilePath
;
import
hudson.Functions
;
import
hudson.Launcher
;
import
hudson.Util
;
import
hudson.model.AbstractBuild
;
...
...
@@ -266,7 +267,7 @@ public class ArtifactArchiverTest {
@LocalData
@Test
public
void
fingerprintMigration
()
throws
Exception
{
FreeStyleProject
p
=
j
.
jenkins
.
getItemByFullName
(
"sample"
,
FreeStyleProject
.
class
);
FreeStyleProject
p
=
j
.
jenkins
.
getItemByFullName
(
Functions
.
isWindows
()
?
"sample-windows"
:
"sample"
,
FreeStyleProject
.
class
);
assertNotNull
(
p
);
String
xml
=
p
.
getConfigFile
().
asString
();
assertFalse
(
xml
,
xml
.
contains
(
"<recordBuildArtifacts>"
));
...
...
test/src/test/java/hudson/tasks/FingerprinterTest.java
浏览文件 @
335fb4bc
...
...
@@ -26,6 +26,7 @@ package hudson.tasks;
import
com.google.common.collect.ImmutableMap
;
import
com.google.common.collect.ImmutableSet
;
import
hudson.Functions
;
import
hudson.Launcher
;
import
hudson.Util
;
import
hudson.XmlFile
;
...
...
@@ -293,14 +294,18 @@ public class FingerprinterTest {
@Issue
(
"JENKINS-17125"
)
@LocalData
@Test
public
void
actionSerialization
()
throws
Exception
{
FreeStyleProject
job
=
j
.
jenkins
.
getItemByFullName
(
"j"
,
FreeStyleProject
.
class
);
FreeStyleProject
job
=
j
.
jenkins
.
getItemByFullName
(
Functions
.
isWindows
()
?
"j-windows"
:
"j"
,
FreeStyleProject
.
class
);
assertNotNull
(
job
);
FreeStyleBuild
build
=
job
.
getBuildByNumber
(
2
);
assertNotNull
(
build
);
Fingerprinter
.
FingerprintAction
action
=
build
.
getAction
(
Fingerprinter
.
FingerprintAction
.
class
);
assertNotNull
(
action
);
assertEquals
(
build
,
action
.
getBuild
());
assertEquals
(
"{a=2d5fac981a2e865baf0e15db655c7d63}"
,
action
.
getRecords
().
toString
());
if
(
Functions
.
isWindows
())
{
assertEquals
(
"{a=603bc9e16cc05bdbc5e595969f42e3b8}"
,
action
.
getRecords
().
toString
());
}
else
{
assertEquals
(
"{a=2d5fac981a2e865baf0e15db655c7d63}"
,
action
.
getRecords
().
toString
());
}
j
.
assertBuildStatusSuccess
(
job
.
scheduleBuild2
(
0
));
job
.
_getRuns
().
purgeCache
();
// force build records to be reloaded
build
=
job
.
getBuildByNumber
(
3
);
...
...
@@ -309,7 +314,11 @@ public class FingerprinterTest {
action
=
build
.
getAction
(
Fingerprinter
.
FingerprintAction
.
class
);
assertNotNull
(
action
);
assertEquals
(
build
,
action
.
getBuild
());
assertEquals
(
"{a=f31efcf9afe30617d6c46b919e702822}"
,
action
.
getRecords
().
toString
());
if
(
Functions
.
isWindows
())
{
assertEquals
(
"{a=a97a39fb51de0eee9fd908174dccc304}"
,
action
.
getRecords
().
toString
());
}
else
{
assertEquals
(
"{a=f31efcf9afe30617d6c46b919e702822}"
,
action
.
getRecords
().
toString
());
}
}
@SuppressWarnings
(
"unchecked"
)
...
...
@@ -326,7 +335,8 @@ public class FingerprinterTest {
j
.
assertBuildStatusSuccess
(
p2
.
scheduleBuild2
(
0
));
j
.
assertBuildStatusSuccess
(
p3
.
scheduleBuild2
(
0
));
Fingerprint
f
=
j
.
jenkins
.
_getFingerprint
(
Util
.
getDigestOf
(
singleContents
[
0
]+
"\n"
));
Fingerprint
f
=
j
.
jenkins
.
_getFingerprint
(
Util
.
getDigestOf
(
singleContents
[
0
]+
System
.
lineSeparator
()));
assertNotNull
(
f
);
assertEquals
(
3
,
f
.
getUsages
().
size
());
j
.
jenkins
.
rebuildDependencyGraph
();
...
...
@@ -373,9 +383,15 @@ public class FingerprinterTest {
StringBuilder
targets
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
contents
.
length
;
i
++)
{
if
(
project
instanceof
MatrixProject
)
{
((
MatrixProject
)
project
).
getBuildersList
().
add
(
new
Shell
(
"echo "
+
contents
[
i
]
+
" > "
+
files
[
i
]));
((
MatrixProject
)
project
).
getBuildersList
().
add
(
Functions
.
isWindows
()
?
new
BatchFile
(
"echo "
+
contents
[
i
]
+
"> "
+
files
[
i
])
:
new
Shell
(
"echo "
+
contents
[
i
]
+
" > "
+
files
[
i
]));
}
else
{
((
FreeStyleProject
)
project
).
getBuildersList
().
add
(
new
Shell
(
"echo "
+
contents
[
i
]
+
" > "
+
files
[
i
]));
((
FreeStyleProject
)
project
).
getBuildersList
().
add
(
Functions
.
isWindows
()
?
new
BatchFile
(
"echo "
+
contents
[
i
]
+
"> "
+
files
[
i
])
:
new
Shell
(
"echo "
+
contents
[
i
]
+
" > "
+
files
[
i
]));
}
targets
.
append
(
files
[
i
]).
append
(
','
);
...
...
test/src/test/java/hudson/tools/InstallerTranslatorTest.java
浏览文件 @
335fb4bc
...
...
@@ -24,6 +24,7 @@
package
hudson.tools
;
import
hudson.Functions
;
import
hudson.model.FreeStyleBuild
;
import
hudson.model.FreeStyleProject
;
import
hudson.model.JDK
;
...
...
@@ -32,6 +33,7 @@ import hudson.slaves.DumbSlave;
import
hudson.slaves.JNLPLauncher
;
import
hudson.slaves.NodeProperty
;
import
hudson.slaves.RetentionStrategy
;
import
hudson.tasks.BatchFile
;
import
hudson.tasks.Shell
;
import
hudson.util.StreamTaskListener
;
import
java.nio.charset.Charset
;
...
...
@@ -66,38 +68,40 @@ public class InstallerTranslatorTest {
@Issue
(
"JENKINS-17667"
)
@Test
public
void
multipleSlavesAndTools
()
throws
Exception
{
String
jdk1Path
=
Functions
.
isWindows
()
?
"C:\\jdk1"
:
"/opt/jdk1"
;
String
jdk2Path
=
Functions
.
isWindows
()
?
"C:\\jdk2"
:
"/opt/jdk2"
;
Node
slave1
=
r
.
createSlave
();
Node
slave2
=
r
.
createSlave
();
JDK
jdk1
=
new
JDK
(
"jdk1"
,
null
,
Collections
.
singletonList
(
new
InstallSourceProperty
(
Collections
.
singletonList
(
new
CommandInstaller
(
null
,
"echo installed jdk1"
,
"/opt/jdk1"
)))));
JDK
jdk2
=
new
JDK
(
"jdk2"
,
null
,
Collections
.
singletonList
(
new
InstallSourceProperty
(
Collections
.
singletonList
(
new
CommandInstaller
(
null
,
"echo installed jdk2"
,
"/opt/jdk2"
)))));
JDK
jdk1
=
new
JDK
(
"jdk1"
,
null
,
Collections
.
singletonList
(
new
InstallSourceProperty
(
Collections
.
singletonList
(
Functions
.
isWindows
()
?
new
BatchCommandInstaller
(
null
,
"echo installed jdk1"
,
jdk1Path
)
:
new
CommandInstaller
(
null
,
"echo installed jdk1"
,
jdk1Path
)))));
JDK
jdk2
=
new
JDK
(
"jdk2"
,
null
,
Collections
.
singletonList
(
new
InstallSourceProperty
(
Collections
.
singletonList
(
Functions
.
isWindows
()
?
new
BatchCommandInstaller
(
null
,
"echo installed jdk2"
,
jdk2Path
)
:
new
CommandInstaller
(
null
,
"echo installed jdk2"
,
jdk2Path
)))));
r
.
jenkins
.
getJDKs
().
add
(
jdk1
);
r
.
jenkins
.
getJDKs
().
add
(
jdk2
);
FreeStyleProject
p
=
r
.
createFreeStyleProject
();
p
.
setJDK
(
jdk1
);
p
.
getBuildersList
().
add
(
new
Shell
(
"echo $JAVA_HOME"
));
p
.
getBuildersList
().
add
(
Functions
.
isWindows
()
?
new
BatchFile
(
"echo %JAVA_HOME%"
)
:
new
Shell
(
"echo $JAVA_HOME"
));
p
.
setAssignedNode
(
slave1
);
FreeStyleBuild
b1
=
r
.
buildAndAssertSuccess
(
p
);
r
.
assertLogContains
(
"installed jdk1"
,
b1
);
r
.
assertLogContains
(
"/opt/jdk1"
,
b1
);
r
.
assertLogContains
(
jdk1Path
,
b1
);
p
.
setJDK
(
jdk2
);
FreeStyleBuild
b2
=
r
.
buildAndAssertSuccess
(
p
);
r
.
assertLogContains
(
"installed jdk2"
,
b2
);
r
.
assertLogContains
(
"/opt/jdk2"
,
b2
);
r
.
assertLogContains
(
jdk2Path
,
b2
);
FreeStyleBuild
b3
=
r
.
buildAndAssertSuccess
(
p
);
// An installer is run for every build, and it is up to a CommandInstaller configuration to do any up-to-date check.
r
.
assertLogContains
(
"installed jdk2"
,
b3
);
r
.
assertLogContains
(
"/opt/jdk2"
,
b3
);
r
.
assertLogContains
(
jdk2Path
,
b3
);
p
.
setAssignedNode
(
slave2
);
FreeStyleBuild
b4
=
r
.
buildAndAssertSuccess
(
p
);
r
.
assertLogContains
(
"installed jdk2"
,
b4
);
r
.
assertLogContains
(
"/opt/jdk2"
,
b4
);
r
.
assertLogContains
(
jdk2Path
,
b4
);
p
.
setJDK
(
jdk1
);
FreeStyleBuild
b5
=
r
.
buildAndAssertSuccess
(
p
);
r
.
assertLogContains
(
"installed jdk1"
,
b5
);
r
.
assertLogContains
(
"/opt/jdk1"
,
b5
);
r
.
assertLogContains
(
jdk1Path
,
b5
);
FreeStyleBuild
b6
=
r
.
buildAndAssertSuccess
(
p
);
r
.
assertLogContains
(
"installed jdk1"
,
b6
);
r
.
assertLogContains
(
"/opt/jdk1"
,
b6
);
r
.
assertLogContains
(
jdk1Path
,
b6
);
}
@Issue
(
"JENKINS-26940"
)
...
...
@@ -113,7 +117,7 @@ public class InstallerTranslatorTest {
FreeStyleProject
p
=
r
.
createFreeStyleProject
();
p
.
setJDK
(
jdk
);
p
.
getBuildersList
().
add
(
new
Shell
(
"echo $JAVA_HOME"
));
p
.
getBuildersList
().
add
(
Functions
.
isWindows
()
?
new
BatchFile
(
"echo %JAVA_HOME%"
)
:
new
Shell
(
"echo $JAVA_HOME"
));
FreeStyleBuild
b1
=
r
.
buildAndAssertSuccess
(
p
);
r
.
assertLogContains
(
hudson
.
tools
.
Messages
.
CannotBeInstalled
(
ci
.
getDescriptor
().
getDisplayName
(),
jdk
.
getName
(),
r
.
jenkins
.
getDisplayName
()),
b1
);
r
.
assertLogContains
(
hudson
.
tools
.
Messages
.
CannotBeInstalled
(
bci
.
getDescriptor
().
getDisplayName
(),
jdk
.
getName
(),
r
.
jenkins
.
getDisplayName
()),
b1
);
...
...
@@ -122,8 +126,12 @@ public class InstallerTranslatorTest {
@Issue
(
"JENKINS-26940"
)
@Test
public
void
testNoMessageLoggedWhenAnyInstallerFound
()
throws
Exception
{
final
CommandInstaller
ci
=
new
CommandInstaller
(
"wrong1"
,
"echo hello"
,
"/opt/jdk"
);
final
CommandInstaller
ci2
=
new
CommandInstaller
(
"master"
,
"echo hello"
,
"/opt/jdk2"
);
final
AbstractCommandInstaller
ci
=
Functions
.
isWindows
()
?
new
BatchCommandInstaller
(
"wrong1"
,
"echo hello"
,
"C:\\jdk"
)
:
new
CommandInstaller
(
"wrong1"
,
"echo hello"
,
"/opt/jdk"
);
final
AbstractCommandInstaller
ci2
=
Functions
.
isWindows
()
?
new
BatchCommandInstaller
(
"master"
,
"echo hello"
,
"C:\\jdk2"
)
:
new
CommandInstaller
(
"master"
,
"echo hello"
,
"/opt/jdk2"
);
InstallSourceProperty
isp
=
new
InstallSourceProperty
(
Arrays
.
asList
(
ci
,
ci2
));
JDK
jdk
=
new
JDK
(
"jdk"
,
null
,
Collections
.
singletonList
(
isp
));
...
...
@@ -132,7 +140,7 @@ public class InstallerTranslatorTest {
FreeStyleProject
p
=
r
.
createFreeStyleProject
();
p
.
setJDK
(
jdk
);
p
.
getBuildersList
().
add
(
new
Shell
(
"echo $JAVA_HOME"
));
p
.
getBuildersList
().
add
(
Functions
.
isWindows
()
?
new
BatchFile
(
"echo %JAVA_HOME%"
)
:
new
Shell
(
"echo $JAVA_HOME"
));
FreeStyleBuild
b1
=
r
.
buildAndAssertSuccess
(
p
);
r
.
assertLogNotContains
(
ci
.
getDescriptor
().
getDisplayName
(),
b1
);
}
...
...
test/src/test/java/hudson/util/ArgumentListBuilder2Test.java
浏览文件 @
335fb4bc
...
...
@@ -28,6 +28,7 @@ import static org.hamcrest.Matchers.containsString;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
junit
.
Assume
.
assumeTrue
;
import
hudson.Functions
;
import
hudson.Launcher.LocalLauncher
;
...
...
@@ -45,6 +46,7 @@ import com.google.common.base.Joiner;
import
java.io.ByteArrayOutputStream
;
import
java.io.StringWriter
;
import
java.net.URL
;
/**
* @author Kohsuke Kawaguchi
...
...
@@ -90,9 +92,18 @@ public class ArgumentListBuilder2Test {
}
public
String
echoArgs
(
String
...
arguments
)
throws
Exception
{
ArgumentListBuilder
args
=
new
ArgumentListBuilder
(
JavaEnvUtils
.
getJreExecutable
(
"java"
),
"-cp"
,
"target/test-classes/"
,
"hudson.util.EchoCommand"
);
args
.
add
(
arguments
);
args
=
args
.
toWindowsCommand
();
String
testHarnessJar
=
Class
.
forName
(
"hudson.util.EchoCommand"
)
.
getProtectionDomain
()
.
getCodeSource
()
.
getLocation
()
.
getFile
()
.
replaceAll
(
"^/"
,
""
);
ArgumentListBuilder
args
=
new
ArgumentListBuilder
(
JavaEnvUtils
.
getJreExecutable
(
"java"
).
replaceAll
(
"^\"|\"$"
,
""
),
"-cp"
,
testHarnessJar
,
"hudson.util.EchoCommand"
)
.
add
(
arguments
)
.
toWindowsCommand
();
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
final
StreamTaskListener
listener
=
new
StreamTaskListener
(
out
);
...
...
test/src/test/java/jenkins/security/Security232Test.java
浏览文件 @
335fb4bc
...
...
@@ -170,6 +170,7 @@ public class Security232Test {
long
o2
=
Long
.
parseLong
(
parts
[
1
],
16
);
short
o3
=
Short
.
parseShort
(
parts
[
2
],
16
);
// Need to find Windows equivalent.
exploit
(
new
InetSocketAddress
(
isa
.
getAddress
(),
jrmpPort
),
obj
,
o1
,
o2
,
o3
,
new
CommonsCollections1
(),
"touch "
+
pwned
);
}
...
...
test/src/test/java/jenkins/security/security218/ysoserial/payloads/JRMPClient.java
浏览文件 @
335fb4bc
...
...
@@ -79,7 +79,7 @@ public class JRMPClient extends PayloadRunner implements ObjectPayload<Registry>
String
host
;
int
port
;
int
sep
=
command
.
indexOf
(
':'
);
if
(
sep
<
0
)
{
if
(
sep
<
0
||
((
sep
+
1
)
<
command
.
length
()
&&
!
Character
.
isDigit
(
command
.
charAt
(
sep
+
1
)))
)
{
port
=
new
Random
().
nextInt
(
65535
);
host
=
command
;
}
...
...
test/src/test/resources/hudson/model/ParametersAction2Test/backwardCompatibility.zip
浏览文件 @
335fb4bc
此差异由.gitattributes 抑制。
test/src/test/resources/hudson/tasks/ArtifactArchiverTest/fingerprintMigration.zip
浏览文件 @
335fb4bc
此差异由.gitattributes 抑制。
test/src/test/resources/hudson/tasks/FingerprinterTest/actionSerialization.zip
浏览文件 @
335fb4bc
此差异由.gitattributes 抑制。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录