Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
go-gitlab
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
go-gitlab
Commits
198acc90
Unverified
Commit
198acc90
authored
Dec 29, 2018
by
Sander van Harmelen
Committed by
GitHub
Dec 29, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #540 from Snehal1112/master
Added unit test
parents
7bc4155e
d52dbbbe
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
125 additions
and
2 deletions
+125
-2
environments.go
environments.go
+22
-2
environments_test.go
environments_test.go
+101
-0
issues_test.go
issues_test.go
+2
-0
No files found.
environments.go
View file @
198acc90
...
@@ -84,7 +84,7 @@ type CreateEnvironmentOptions struct {
...
@@ -84,7 +84,7 @@ type CreateEnvironmentOptions struct {
ExternalURL
*
string
`url:"external_url,omitempty" json:"external_url,omitempty"`
ExternalURL
*
string
`url:"external_url,omitempty" json:"external_url,omitempty"`
}
}
// CreateEnvironment adds a environment to a project. This is an idempotent
// CreateEnvironment adds a
n
environment to a project. This is an idempotent
// method and can be called multiple times with the same parameters. Createing
// method and can be called multiple times with the same parameters. Createing
// an environment that is already a environment does not affect the
// an environment that is already a environment does not affect the
// existing environmentship.
// existing environmentship.
...
@@ -146,7 +146,7 @@ func (s *EnvironmentsService) EditEnvironment(pid interface{}, environment int,
...
@@ -146,7 +146,7 @@ func (s *EnvironmentsService) EditEnvironment(pid interface{}, environment int,
return
env
,
resp
,
err
return
env
,
resp
,
err
}
}
// DeleteEnvironment removes a environment from a project team.
// DeleteEnvironment removes a
n
environment from a project team.
//
//
// GitLab API docs:
// GitLab API docs:
// https://docs.gitlab.com/ce/api/environments.html#remove-a-environment-from-a-group-or-project
// https://docs.gitlab.com/ce/api/environments.html#remove-a-environment-from-a-group-or-project
...
@@ -164,3 +164,22 @@ func (s *EnvironmentsService) DeleteEnvironment(pid interface{}, environment int
...
@@ -164,3 +164,22 @@ func (s *EnvironmentsService) DeleteEnvironment(pid interface{}, environment int
return
s
.
client
.
Do
(
req
,
nil
)
return
s
.
client
.
Do
(
req
,
nil
)
}
}
// StopEnvironment stop an environment from a project team.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/environments.html#stop-an-environment
func
(
s
*
EnvironmentsService
)
StopEnvironment
(
pid
interface
{},
environmentID
int
,
options
...
OptionFunc
)
(
*
Response
,
error
)
{
project
,
err
:=
parseID
(
pid
)
if
err
!=
nil
{
return
nil
,
err
}
u
:=
fmt
.
Sprintf
(
"projects/%s/environments/%d/stop"
,
url
.
QueryEscape
(
project
),
environmentID
)
req
,
err
:=
s
.
client
.
NewRequest
(
"POST"
,
u
,
nil
,
options
)
if
err
!=
nil
{
return
nil
,
err
}
return
s
.
client
.
Do
(
req
,
nil
)
}
\ No newline at end of file
environments_test.go
0 → 100644
View file @
198acc90
package
gitlab
import
(
"fmt"
"log"
"net/http"
"reflect"
"testing"
)
func
TestListEnvironments
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/api/v4/projects/1/environments"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"GET"
)
testURL
(
t
,
r
,
"/api/v4/projects/1/environments?page=1&per_page=10"
)
fmt
.
Fprint
(
w
,
`[{"id": 1,"name": "review/fix-foo", "slug": "review-fix-foo-dfjre3", "external_url": "https://review-fix-foo-dfjre3.example.gitlab.com"}]`
)
})
envs
,
_
,
err
:=
client
.
Environments
.
ListEnvironments
(
1
,
&
ListEnvironmentsOptions
{
Page
:
1
,
PerPage
:
10
})
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
want
:=
[]
*
Environment
{{
ID
:
1
,
Name
:
"review/fix-foo"
,
Slug
:
"review-fix-foo-dfjre3"
,
ExternalURL
:
"https://review-fix-foo-dfjre3.example.gitlab.com"
}}
if
!
reflect
.
DeepEqual
(
want
,
envs
)
{
t
.
Errorf
(
"Environments.ListEnvironments returned %+v, want %+v"
,
envs
,
want
)
}
}
func
TestCreateEnvironment
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/api/v4/projects/1/environments"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"POST"
)
testURL
(
t
,
r
,
"/api/v4/projects/1/environments"
)
fmt
.
Fprint
(
w
,
`{"id": 1,"name": "deploy", "slug": "deploy", "external_url": "https://deploy.example.gitlab.com"}`
)
})
envs
,
_
,
err
:=
client
.
Environments
.
CreateEnvironment
(
1
,
&
CreateEnvironmentOptions
{
Name
:
String
(
"deploy"
),
ExternalURL
:
String
(
"https://deploy.example.gitlab.com"
)})
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
want
:=
&
Environment
{
ID
:
1
,
Name
:
"deploy"
,
Slug
:
"deploy"
,
ExternalURL
:
"https://deploy.example.gitlab.com"
}
if
!
reflect
.
DeepEqual
(
want
,
envs
)
{
t
.
Errorf
(
"Environments.CreateEnvironment returned %+v, want %+v"
,
envs
,
want
)
}
}
func
TestEditEnvironment
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/api/v4/projects/1/environments/1"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"PUT"
)
testURL
(
t
,
r
,
"/api/v4/projects/1/environments/1"
)
fmt
.
Fprint
(
w
,
`{"id": 1,"name": "staging", "slug": "staging", "external_url": "https://staging.example.gitlab.com"}`
)
})
envs
,
_
,
err
:=
client
.
Environments
.
EditEnvironment
(
1
,
1
,
&
EditEnvironmentOptions
{
Name
:
String
(
"staging"
),
ExternalURL
:
String
(
"https://staging.example.gitlab.com"
)})
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
want
:=
&
Environment
{
ID
:
1
,
Name
:
"staging"
,
Slug
:
"staging"
,
ExternalURL
:
"https://staging.example.gitlab.com"
}
if
!
reflect
.
DeepEqual
(
want
,
envs
)
{
t
.
Errorf
(
"Environments.EditEnvironment returned %+v, want %+v"
,
envs
,
want
)
}
}
func
TestDeleteEnvironment
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/api/v4/projects/1/environments/1"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"DELETE"
)
testURL
(
t
,
r
,
"/api/v4/projects/1/environments/1"
)
})
_
,
err
:=
client
.
Environments
.
DeleteEnvironment
(
1
,
1
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
}
func
TestStopEnvironment
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/api/v4/projects/1/environments/1/stop"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"POST"
)
testURL
(
t
,
r
,
"/api/v4/projects/1/environments/1/stop"
)
})
_
,
err
:=
client
.
Environments
.
StopEnvironment
(
1
,
1
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
}
\ No newline at end of file
issues_test.go
View file @
198acc90
...
@@ -272,6 +272,8 @@ func TestListMergeRequestsClosingIssue(t *testing.T) {
...
@@ -272,6 +272,8 @@ func TestListMergeRequestsClosingIssue(t *testing.T) {
mux
.
HandleFunc
(
"/api/v4/projects/1/issues/5/closed_by"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
mux
.
HandleFunc
(
"/api/v4/projects/1/issues/5/closed_by"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"GET"
)
testMethod
(
t
,
r
,
"GET"
)
testURL
(
t
,
r
,
"/api/v4/projects/1/issues/5/closed_by?page=1&per_page=10"
)
fmt
.
Fprint
(
w
,
`[{"id":1, "title" : "test merge one"},{"id":2, "title" : "test merge two"}]`
)
fmt
.
Fprint
(
w
,
`[{"id":1, "title" : "test merge one"},{"id":2, "title" : "test merge two"}]`
)
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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