Adding JSON format validation API tests

This commit is contained in:
Denis Makogon
2017-10-01 15:09:56 +03:00
parent 588d9e523b
commit 3ae55af392
6 changed files with 159 additions and 5 deletions

View File

@@ -7,6 +7,7 @@ import (
"log"
"net/http"
"os"
"strconv"
)
type Person struct {
@@ -34,7 +35,6 @@ func main() {
}
person := Person{}
stderr.Encode(in.Body)
stderr.Encode(fmt.Sprintf(in.Body))
if len(in.Body) != 0 {
if err := json.NewDecoder(bytes.NewReader([]byte(in.Body))).Decode(&person); err != nil {
log.Fatalf("Unable to decode Person object data: %s", err.Error())
@@ -51,9 +51,13 @@ func main() {
log.Fatalf("Unable to marshal JSON response body: %s", err.Error())
fmt.Fprintf(os.Stderr, err.Error())
}
h := http.Header{}
h.Set("Content-Type", "application/json")
h.Set("Content-Length", strconv.Itoa(len(b)))
out := &JSON{
StatusCode: http.StatusOK,
Body: string(b),
Headers: h,
}
stderr.Encode(out)
if err := stdout.Encode(out); err != nil {