Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
83d06b4e
Commit
83d06b4e
authored
3 years ago
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Add testing
parent
3d0837bb
No related branches found
No related tags found
2 merge requests
!23
Release
,
!5
Services rewrite
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/services.go
+2
-0
2 additions, 0 deletions
api/services.go
api/services_test.go
+122
-0
122 additions, 0 deletions
api/services_test.go
with
124 additions
and
0 deletions
api/services.go
+
2
−
0
View file @
83d06b4e
...
@@ -101,6 +101,8 @@ func (s *services) stop() error {
...
@@ -101,6 +101,8 @@ func (s *services) stop() error {
return
errors
.
WithMessage
(
err
,
"Failed to stop services"
)
return
errors
.
WithMessage
(
err
,
"Failed to stop services"
)
}
}
s
.
state
=
Stopped
return
nil
return
nil
}
}
...
...
This diff is collapsed.
Click to expand it.
api/services_test.go
0 → 100644
+
122
−
0
View file @
83d06b4e
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package
api
import
(
"errors"
"gitlab.com/elixxir/client/stoppable"
"reflect"
"testing"
"time"
)
// Unit test
func
TestNewServices
(
t
*
testing
.
T
)
{
expected
:=
&
services
{
services
:
make
([]
Service
,
0
),
stoppable
:
stoppable
.
NewMulti
(
"services"
),
state
:
Stopped
,
}
received
:=
newServices
()
if
!
reflect
.
DeepEqual
(
expected
,
received
)
{
t
.
Fatalf
(
"Unexpected value in constructor (newServices): "
+
"
\n\t
Expected: %v"
+
"
\n\t
Received: %v"
,
expected
,
received
)
}
}
// Unit test
func
TestServices_Add
(
t
*
testing
.
T
)
{
mockService
:=
func
()
(
stoppable
.
Stoppable
,
error
)
{
return
nil
,
nil
}
mockServices
:=
newServices
()
err
:=
mockServices
.
add
(
mockService
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to add mock service to services: %v"
,
err
)
}
err
=
mockServices
.
start
(
500
*
time
.
Millisecond
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to start mock services: %v"
,
err
)
}
// Add a doomed to fail process
mockServiceErr
:=
func
()
(
stoppable
.
Stoppable
,
error
)
{
return
nil
,
errors
.
New
(
"Expected failure case"
)
}
err
=
mockServices
.
add
(
mockServiceErr
)
if
err
==
nil
{
t
.
Fatalf
(
"Expected error case: "
+
"Service should have started and failed"
)
}
}
func
TestServices_Start
(
t
*
testing
.
T
)
{
mockService
:=
func
()
(
stoppable
.
Stoppable
,
error
)
{
return
nil
,
nil
}
mockServices
:=
newServices
()
err
:=
mockServices
.
add
(
mockService
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to add mock service to services: %v"
,
err
)
}
err
=
mockServices
.
start
(
500
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to start mock services: %v"
,
err
)
}
// Try and start again should error
err
=
mockServices
.
start
(
500
*
time
.
Millisecond
)
if
err
==
nil
{
t
.
Fatalf
(
"Should fail when calling start with running processes"
)
}
}
func
TestServices_Stop
(
t
*
testing
.
T
)
{
mockService
:=
func
()
(
stoppable
.
Stoppable
,
error
)
{
return
stoppable
.
NewSingle
(
"test"
),
nil
}
mockServices
:=
newServices
()
err
:=
mockServices
.
add
(
mockService
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to add mock service to services: %v"
,
err
)
}
err
=
mockServices
.
stop
()
if
err
==
nil
{
t
.
Fatalf
(
"Should error when calling "
+
"stop on non-running service"
)
}
err
=
mockServices
.
start
(
500
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to start mock services: %v"
,
err
)
}
err
=
mockServices
.
stop
()
if
err
!=
nil
{
t
.
Fatalf
(
"Should not error when calling stop; %v"
,
err
)
}
err
=
mockServices
.
stop
()
if
err
==
nil
{
t
.
Fatalf
(
"Should error when stopping a stopped service"
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment