Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
d848fc0b
Commit
d848fc0b
authored
6 years ago
by
Greg Messner
Browse files
Options
Download
Email Patches
Plain Diff
Added creation of a temporary .gitlab-ci.yml for testing if not present in repo.
parent
715f52f3
main
5.0.x
5.0.x.jdk17
6.x
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/org/gitlab4j/api/TestPipelineApi.java
+41
-9
src/test/java/org/gitlab4j/api/TestPipelineApi.java
with
41 additions
and
9 deletions
+41
-9
src/test/java/org/gitlab4j/api/TestPipelineApi.java
+
41
-
9
View file @
d848fc0b
...
...
@@ -10,6 +10,7 @@ import java.util.ArrayList;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.stream.Stream
;
import
org.gitlab4j.api.models.Pipeline
;
...
...
@@ -29,9 +30,14 @@ public class TestPipelineApi extends AbstractIntegrationTest {
private
static
final
String
SCHEDULE_DESCRIPTION
=
"Test pipeline schedule - DELETE AFTER TEST"
;
private
static
final
String
TRIGGER_DESCRIPTION
=
"Test pipeline trigger - DELETE AFTER TEST"
;
private
static
final
String
TEST_GITLAB_CI_YML_CONTENT
=
"build:\n"
+
" stage: build\n script:\n - echo 'Empty build for testing variables with GitLab4J-API'"
;
private
static
GitLabApi
gitLabApi
;
private
static
Project
testProject
;
private
static
RepositoryFile
createdGitlabCiYml
;
private
static
RepositoryFile
gitlabCiYml
;
public
TestPipelineApi
()
{
super
();
...
...
@@ -64,6 +70,13 @@ public class TestPipelineApi extends AbstractIntegrationTest {
}
}
catch
(
Exception
ignore
)
{}
if
(
createdGitlabCiYml
!=
null
)
{
try
{
gitLabApi
.
getRepositoryFileApi
().
deleteFile
(
testProject
,
".gitlab-ci.yml"
,
"master"
,
"No longer needed."
);
}
catch
(
Exception
ignore
)
{}
}
}
@BeforeClass
...
...
@@ -71,6 +84,23 @@ public class TestPipelineApi extends AbstractIntegrationTest {
// Must setup the connection to the GitLab test server and get the test Project instance
gitLabApi
=
baseTestSetup
();
testProject
=
getTestProject
();
Optional
<
RepositoryFile
>
fileInfo
=
gitLabApi
.
getRepositoryFileApi
().
getOptionalFileInfo
(
testProject
,
".gitlab-ci.yml"
,
"master"
);
if
(
fileInfo
.
isPresent
())
{
gitlabCiYml
=
fileInfo
.
get
();
}
else
{
try
{
RepositoryFile
file
=
new
RepositoryFile
();
file
.
setFilePath
(
".gitlab-ci.yml"
);
file
.
setContent
(
TEST_GITLAB_CI_YML_CONTENT
);
createdGitlabCiYml
=
gitLabApi
.
getRepositoryFileApi
().
createFile
(
testProject
,
file
,
"master"
,
"Need for testing pipelines."
);
gitlabCiYml
=
createdGitlabCiYml
;
System
.
out
.
println
(
"Created .gitlab-ci.yml file for testing purposes."
);
}
catch
(
Exception
ignore
)
{}
}
}
@AfterClass
...
...
@@ -187,12 +217,8 @@ public class TestPipelineApi extends AbstractIntegrationTest {
assertNotNull
(
testProject
);
// Skip this test if no .gitlab-ci.yml file is found in the test project
RepositoryFile
fileInfo
=
null
;
try
{
fileInfo
=
gitLabApi
.
getRepositoryFileApi
().
getFileInfo
(
testProject
,
".gitlab-ci.yml"
,
"master"
);
}
catch
(
GitLabApiException
ignore
)
{}
assumeNotNull
(
fileInfo
);
// Skip this test if no .gitlab-ci.yml file is in the test project
assumeNotNull
(
gitlabCiYml
);
String
triggerDescription
=
TRIGGER_DESCRIPTION
+
" - test triggerPipeline() - "
+
HelperUtils
.
getRandomInt
(
1000
);
Trigger
createdTrigger
=
gitLabApi
.
getPipelineApi
().
createPipelineTrigger
(
testProject
,
triggerDescription
);
...
...
@@ -212,7 +238,9 @@ public class TestPipelineApi extends AbstractIntegrationTest {
@Test
public
void
testCreatePipelineNoVariables
()
throws
GitLabApiException
{
assumeNotNull
(
testProject
);
// Skip this test if no .gitlab-ci.yml file is in the test project
assumeNotNull
(
gitlabCiYml
);
// Act
Pipeline
pipeline
=
gitLabApi
.
getPipelineApi
().
createPipeline
(
testProject
,
"master"
);
...
...
@@ -225,7 +253,9 @@ public class TestPipelineApi extends AbstractIntegrationTest {
@Test
public
void
testCreatePipelineWithVariables
()
throws
GitLabApiException
{
assumeNotNull
(
testProject
);
// Skip this test if no .gitlab-ci.yml file is in the test project
assumeNotNull
(
gitlabCiYml
);
// Arrange
List
<
Variable
>
variableList
=
new
ArrayList
<>();
...
...
@@ -243,7 +273,9 @@ public class TestPipelineApi extends AbstractIntegrationTest {
@Test
public
void
testCreatePipelineWithMapVariables
()
throws
GitLabApiException
{
assumeNotNull
(
testProject
);
// Skip this test if no .gitlab-ci.yml file is in the test project
assumeNotNull
(
gitlabCiYml
);
// Arrange
Map
<
String
,
String
>
variableMap
=
new
HashMap
<>();
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets