Skip to content

Instantly share code, notes, and snippets.

@denismakogon
Last active December 11, 2018 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save denismakogon/f69d8aeb859a2ff8060457c0d0eebabe to your computer and use it in GitHub Desktop.
Save denismakogon/f69d8aeb859a2ff8060457c0d0eebabe to your computer and use it in GitHub Desktop.
################################################################################
################################################################################
################################################################################
func withError(ctx context.Context, in io.Reader, out io.Writer) {
err := myHandler(ctx, in, out)
if err != nil {
fdk.WriteStatus(out, http.StatusInternalServerError)
out.Write([]byte(err.Error()))
return
}
fdk.WriteStatus(out, http.StatusOK)
}
func myHandler(ctx context.Context, in io.Reader, out io.Writer) error {
io.WriteString(out, "hello world")
return nil
}
func main() {
fdk.Handle(withError)
}
################################################################################
################################################################################
################################################################################
type context struct {
}
func (c context) Config() map[string]string { return nil }
func (c context) Header() http.Header {
hs := http.Header{}
hs.Set("blah-blah-header", "blah-blah-value")
return hs
}
func (c context) ContentType() string { return "" }
func (c context) CallID() string { return "blah" }
func (c context) AppID() string { return "blah-id" }
func (c context) FnID() string { return "blah-fn-id" }
func TestFunc(t *testing.T) {
t.Run("test-hello-world", func(t *testing.T) {
ctx := fdk.WithContext(context.Background(), context{})
var out bytes.Buffer
err := myHandler(ctx, nil, &out)
if err != nil {
// do report here
}
if !strings.Contains("hello world", out.String()) {
// do report here
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment