Last active
December 11, 2018 22:44
-
-
Save denismakogon/f69d8aeb859a2ff8060457c0d0eebabe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################ | |
################################################################################ | |
################################################################################ | |
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