Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Chiefs
ChiefSend2
Commits
908d0d70
Commit
908d0d70
authored
Mar 26, 2021
by
Lukas Böhm
🎱
Browse files
TestOpenShare
parent
b5a8e689
Changes
2
Hide whitespace changes
Inline
Side-by-side
api/api.go
View file @
908d0d70
...
...
@@ -152,7 +152,7 @@ func OpenShare(w http.ResponseWriter, r *http.Request) *HTTPError {
var
newShare
Share
err
=
json
.
Unmarshal
(
reqBody
,
&
newShare
)
if
err
!=
nil
{
return
&
HTTPError
{
err
,
"Can't parse
data
"
,
5
00
}
return
&
HTTPError
{
err
,
"Can't parse
body
"
,
4
00
}
}
// create temporary db entries
...
...
api/api_test.go
View file @
908d0d70
...
...
@@ -2,6 +2,7 @@ package main
import
(
"encoding/json"
"fmt"
"github.com/google/uuid"
"github.com/gorilla/mux"
"github.com/stretchr/testify/assert"
...
...
@@ -9,6 +10,7 @@ import (
"log"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
...
...
@@ -131,27 +133,45 @@ func TestGetShare(t *testing.T) {
}
func
TestDownloadFile
(
t
*
testing
.
T
)
{
Reset
()
router
:=
mux
.
NewRouter
()
ts
:=
httptest
.
NewServer
(
router
)
router
.
Handle
(
"/share/{id}"
,
endpointREST
(
GetShare
))
.
Methods
(
"GET"
)
defer
ts
.
Close
()
t
.
Run
(
"happy path"
,
func
(
t
*
testing
.
T
)
{
})
}
//func TestOpenShare(t *testing.T) {
// t.Run("happy path", func(t *testing.T) {
// b, _ := json.Marshal(Share {
// ID: uuid.MustParse("e5134044-2704-4864-85be-318fb158009f"),
// Name: "TopKek",
// })
// read := strings.NewReader(string(b))
// res := DoRequest(t, "POST", "http://localhost:6969/shares", read, OpenShare, nil)
// assert.Equal(t, http.StatusCreated, res.Code)
// })
//
// t.Run("bad request", func(t *testing.T) {
// res := DoRequest(t, "POST", "http://localhost:6969/shares", nil, OpenShare, nil)
// assert.Equal(t, http.StatusBadRequest, res.Code)
// })
//}
func
TestOpenShare
(
t
*
testing
.
T
)
{
Reset
()
router
:=
mux
.
NewRouter
()
ts
:=
httptest
.
NewServer
(
router
)
router
.
Handle
(
"/shares"
,
endpointREST
(
OpenShare
))
.
Methods
(
"POST"
)
defer
ts
.
Close
()
t
.
Run
(
"happy path"
,
func
(
t
*
testing
.
T
)
{
b
,
_
:=
json
.
Marshal
(
Share
{
ID
:
uuid
.
MustParse
(
"e5134044-2704-4864-85be-318fb158009f"
),
Name
:
"TopKek"
,
})
req
,
_
:=
http
.
NewRequest
(
"POST"
,
ts
.
URL
+
"/shares"
,
strings
.
NewReader
(
string
(
b
)))
res
,
_
:=
http
.
DefaultClient
.
Do
(
req
)
//body, _ := ioutil.ReadAll(res.Body)
assert
.
Equal
(
t
,
http
.
StatusOK
,
res
.
StatusCode
)
})
t
.
Run
(
"bad request"
,
func
(
t
*
testing
.
T
)
{
req
,
_
:=
http
.
NewRequest
(
"POST"
,
ts
.
URL
+
"/shares"
,
nil
)
res
,
_
:=
http
.
DefaultClient
.
Do
(
req
)
body
,
_
:=
ioutil
.
ReadAll
(
res
.
Body
)
fmt
.
Println
(
string
(
body
))
assert
.
Equal
(
t
,
http
.
StatusBadRequest
,
res
.
StatusCode
)
})
}
func
TestCloseShare
(
t
*
testing
.
T
)
{
t
.
Run
(
"happy path"
,
func
(
t
*
testing
.
T
)
{
...
...
Write
Preview
Supports
Markdown
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