Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openfaas-faas
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
Team Jaz CS 598 CCC Final Project
openfaas-faas
Commits
031a0bc1
Commit
031a0bc1
authored
7 years ago
by
Alex Young
Committed by
Alex Ellis
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add tests around error handing done in #196
Signed-off-by:
Alex Young
<
alex@heuris.io
>
parent
63fcf825
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gateway/handlers/createhandler.go
+3
-2
3 additions, 2 deletions
gateway/handlers/createhandler.go
gateway/tests/integration/createfunction_test.go
+93
-5
93 additions, 5 deletions
gateway/tests/integration/createfunction_test.go
with
96 additions
and
7 deletions
gateway/handlers/createhandler.go
+
3
−
2
View file @
031a0bc1
...
...
@@ -30,6 +30,7 @@ func MakeNewFunctionHandler(metricsOptions metrics.MetricOptions, c *client.Clie
request
:=
requests
.
CreateFunctionRequest
{}
err
:=
json
.
Unmarshal
(
body
,
&
request
)
if
err
!=
nil
{
log
.
Println
(
"Error parsing request:"
,
err
)
w
.
WriteHeader
(
http
.
StatusBadRequest
)
return
}
...
...
@@ -43,7 +44,7 @@ func MakeNewFunctionHandler(metricsOptions metrics.MetricOptions, c *client.Clie
if
len
(
request
.
RegistryAuth
)
>
0
{
auth
,
err
:=
BuildEncodedAuthConfig
(
request
.
RegistryAuth
,
request
.
Image
)
if
err
!=
nil
{
log
.
Println
(
"Error
while
building registry auth configuration"
,
err
)
log
.
Println
(
"Error building registry auth configuration
:
"
,
err
)
w
.
WriteHeader
(
http
.
StatusBadRequest
)
w
.
Write
([]
byte
(
"Invalid registry auth"
))
return
...
...
@@ -54,7 +55,7 @@ func MakeNewFunctionHandler(metricsOptions metrics.MetricOptions, c *client.Clie
response
,
err
:=
c
.
ServiceCreate
(
context
.
Background
(),
spec
,
options
)
if
err
!=
nil
{
log
.
Println
(
err
)
log
.
Println
(
"Error creating service:"
,
err
)
w
.
WriteHeader
(
http
.
StatusBadRequest
)
w
.
Write
([]
byte
(
"Deployment error: "
+
err
.
Error
()))
return
...
...
This diff is collapsed.
Click to expand it.
gateway/tests/integration/createfunction_test.go
+
93
−
5
View file @
031a0bc1
...
...
@@ -4,13 +4,42 @@
package
inttests
import
(
"encoding/json"
"net/http"
"strings"
"testing"
)
func
TestCreate_ValidJson
(
t
*
testing
.
T
)
{
reqBody
:=
`{}`
_
,
code
,
err
:=
fireRequest
(
"http://localhost:8080/system/functions"
,
http
.
MethodPost
,
reqBody
)
type
PostFunctionRequest
struct
{
Image
string
`json:"image"`
EnvProcess
string
`json:"envProcess"`
Network
string
`json:"network"`
Service
string
`json:"service"`
}
type
DeleteFunctionRequest
struct
{
FunctionName
string
`json:"functionName"`
}
func
createFunction
(
request
PostFunctionRequest
)
(
string
,
int
,
error
)
{
marshalled
,
_
:=
json
.
Marshal
(
request
)
return
fireRequest
(
"http://localhost:8080/system/functions"
,
http
.
MethodPost
,
string
(
marshalled
))
}
func
deleteFunction
(
name
string
)
(
string
,
int
,
error
)
{
marshalled
,
_
:=
json
.
Marshal
(
DeleteFunctionRequest
{
name
})
return
fireRequest
(
"http://localhost:8080/system/functions"
,
http
.
MethodDelete
,
string
(
marshalled
))
}
func
TestCreate_ValidRequest
(
t
*
testing
.
T
)
{
request
:=
PostFunctionRequest
{
"functions/resizer"
,
""
,
"func_functions"
,
"test_resizer"
,
}
_
,
code
,
err
:=
createFunction
(
request
)
if
err
!=
nil
{
t
.
Log
(
err
)
...
...
@@ -18,11 +47,70 @@ func TestCreate_ValidJson(t *testing.T) {
}
if
code
!=
http
.
StatusOK
{
t
.
Errorf
(
"Got HTTP code: %d, want %d
\n
"
,
code
,
http
.
StatusBadRequest
)
t
.
Errorf
(
"Got HTTP code: %d, want %d
\n
"
,
code
,
http
.
StatusOK
)
return
}
deleteFunction
(
"test_resizer"
)
}
func
TestCreate_InvalidImage
(
t
*
testing
.
T
)
{
request
:=
PostFunctionRequest
{
"a b c"
,
""
,
"func_functions"
,
"test_resizer"
,
}
body
,
code
,
err
:=
createFunction
(
request
)
if
err
!=
nil
{
t
.
Log
(
err
)
t
.
Fail
()
}
expectedErrorCode
:=
http
.
StatusBadRequest
if
code
!=
expectedErrorCode
{
t
.
Errorf
(
"Got HTTP code: %d, want %d
\n
"
,
code
,
expectedErrorCode
)
return
}
expectedErrorSlice
:=
"is not a valid repository/tag"
if
!
strings
.
Contains
(
body
,
expectedErrorSlice
)
{
t
.
Errorf
(
"Error message %s does not contain: %s
\n
"
,
body
,
expectedErrorSlice
)
return
}
}
func
TestCreate_InvalidNetwork
(
t
*
testing
.
T
)
{
request
:=
PostFunctionRequest
{
"functions/resizer"
,
""
,
"non_existent_network"
,
"test_resizer"
,
}
body
,
code
,
err
:=
createFunction
(
request
)
if
err
!=
nil
{
t
.
Log
(
err
)
t
.
Fail
()
}
expectedErrorCode
:=
http
.
StatusBadRequest
if
code
!=
expectedErrorCode
{
t
.
Errorf
(
"Got HTTP code: %d, want %d
\n
"
,
code
,
expectedErrorCode
)
return
}
expectedErrorSlice
:=
"network non_existent_network not found"
if
!
strings
.
Contains
(
body
,
expectedErrorSlice
)
{
t
.
Errorf
(
"Error message %s does not contain: %s
\n
"
,
body
,
expectedErrorSlice
)
return
}
}
func
TestCreate
BadFunctionNot
Json
(
t
*
testing
.
T
)
{
func
TestCreate
_Invalid
Json
(
t
*
testing
.
T
)
{
reqBody
:=
`not json`
_
,
code
,
err
:=
fireRequest
(
"http://localhost:8080/system/functions"
,
http
.
MethodPost
,
reqBody
)
...
...
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