Add test for /spawn
Required small refactor
This commit is contained in:
parent
68d117e0d8
commit
b152861222
6 changed files with 43 additions and 14 deletions
pkg/server
|
@ -6,6 +6,8 @@ import (
|
|||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestHandleStatus(t *testing.T) {
|
||||
|
@ -47,3 +49,25 @@ func TestHandleRegister(t *testing.T) {
|
|||
t.Errorf("got false for /register")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleSpawn(t *testing.T) {
|
||||
s := NewServer()
|
||||
a, err := s.accountant.RegisterAccount("test")
|
||||
assert.NoError(t, err, "Error registering account")
|
||||
data := SpawnData{BasicAccountData: BasicAccountData{Id: a.Id.String()}}
|
||||
|
||||
b, err := json.Marshal(data)
|
||||
assert.NoError(t, err, "Error marshalling data")
|
||||
|
||||
request, _ := http.NewRequest(http.MethodPost, "/spawn", bytes.NewReader(b))
|
||||
response := httptest.NewRecorder()
|
||||
|
||||
s.HandleSpawn(response, request)
|
||||
|
||||
var status SpawnResponse
|
||||
json.NewDecoder(response.Body).Decode(&status)
|
||||
|
||||
if status.Success != true {
|
||||
t.Errorf("got false for /spawn")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue