javaScriptHttpsEndpoint returns a callable function to setup an HTTPS endpoint that exposes the given JavaScript source and returns a teardown function to terminate the underlying httptest server instance.
(t *testing.T, js string)
| 1674 | // the given JavaScript source and returns a teardown function to terminate the underlying |
| 1675 | // httptest server instance. |
| 1676 | func javaScriptHttpsEndpoint(t *testing.T, js string) func() (path string, teardownFn func()) { |
| 1677 | return func() (path string, teardownFn func()) { |
| 1678 | ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 1679 | _, err := fmt.Fprint(w, js) |
| 1680 | require.NoError(t, err) |
| 1681 | })) |
| 1682 | teardownFn = func() { ts.Close() } |
| 1683 | return ts.URL, teardownFn |
| 1684 | } |
| 1685 | } |
| 1686 | |
| 1687 | func TestLoadJavaScript(t *testing.T) { |
| 1688 | const js = `function (doc, oldDoc) { if (doc.published) { channel("public"); } }` |
no test coverage detected