testhub/server_integration_test.go

40 lines
795 B
Go

package main
import (
"bytes"
"encoding/json"
"log"
"net/http"
"net/http/httptest"
"git.andreafazzi.eu/andrea/testhub/models"
"git.andreafazzi.eu/andrea/testhub/store"
"github.com/remogatto/prettytest"
)
type integrationTestSuite struct {
prettytest.Suite
}
func (t *integrationTestSuite) TestPOSTQuestionAndGETQuestion() {
server := NewTestHubCollectorServer(store.NewMemoryTestHubCollectorStore())
// POST a new question using a JSON payload
question := &models.Question{
Text: "Question 1",
}
payload, err := json.Marshal(question)
if err != nil {
panic(err)
}
request, _ := http.NewRequest(http.MethodPost, "/questions", bytes.NewReader(payload))
response := httptest.NewRecorder()
log.Println(response.Body.String())
server.ServeHTTP(response, request)
}