mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Adding JSON format validation API tests
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user