1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
// Copyright 2023 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package github
import (
"context"
"encoding/json"
"fmt"
"net/http"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestMarkdownService_Markdown(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
input := &markdownRenderRequest{
Text: String("# text #"),
Mode: String("gfm"),
Context: String("google/go-github"),
}
mux.HandleFunc("/markdown", func(w http.ResponseWriter, r *http.Request) {
v := new(markdownRenderRequest)
assertNilError(t, json.NewDecoder(r.Body).Decode(v))
testMethod(t, r, "POST")
if !cmp.Equal(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
fmt.Fprint(w, `<h1>text</h1>`)
})
ctx := context.Background()
md, _, err := client.Markdown.Render(ctx, "# text #", &MarkdownOptions{
Mode: "gfm",
Context: "google/go-github",
})
if err != nil {
t.Errorf("Render returned error: %v", err)
}
if want := "<h1>text</h1>"; want != md {
t.Errorf("Render returned %+v, want %+v", md, want)
}
const methodName = "Render"
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Markdown.Render(ctx, "# text #", &MarkdownOptions{
Mode: "gfm",
Context: "google/go-github",
})
if got != "" {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}
func TestMarkdownRenderRequest_Marshal(t *testing.T) {
testJSONMarshal(t, &markdownRenderRequest{}, "{}")
a := &markdownRenderRequest{
Text: String("txt"),
Mode: String("mode"),
Context: String("ctx"),
}
want := `{
"text": "txt",
"mode": "mode",
"context": "ctx"
}`
testJSONMarshal(t, a, want)
}
|