(t *testing.T)
| 1685 | } |
| 1686 | |
| 1687 | func TestLoadJavaScript(t *testing.T) { |
| 1688 | const js = `function (doc, oldDoc) { if (doc.published) { channel("public"); } }` |
| 1689 | var tests = []struct { |
| 1690 | name string |
| 1691 | jsInput func() (path string, teardownFn func()) |
| 1692 | insecureSkipVerify bool |
| 1693 | jsExpected string |
| 1694 | errExpected error |
| 1695 | }{ |
| 1696 | { |
| 1697 | name: "Load inline JavaScript", |
| 1698 | jsInput: inlineJavaScript(js), |
| 1699 | insecureSkipVerify: false, |
| 1700 | jsExpected: js, |
| 1701 | errExpected: nil, |
| 1702 | }, |
| 1703 | { |
| 1704 | name: "Load JavaScript from an external http endpoint", |
| 1705 | jsInput: javaScriptHttpEndpoint(t, js), |
| 1706 | insecureSkipVerify: false, |
| 1707 | jsExpected: js, |
| 1708 | errExpected: nil, |
| 1709 | }, |
| 1710 | { |
| 1711 | name: "Load JavaScript from an external https endpoint with ssl verification enabled", |
| 1712 | jsInput: javaScriptHttpsEndpoint(t, js), |
| 1713 | insecureSkipVerify: false, |
| 1714 | jsExpected: "", |
| 1715 | errExpected: x509.UnknownAuthorityError{}, |
| 1716 | }, |
| 1717 | { |
| 1718 | name: "Load JavaScript from an external https endpoint with ssl verification disabled", |
| 1719 | jsInput: javaScriptHttpsEndpoint(t, js), |
| 1720 | insecureSkipVerify: true, |
| 1721 | jsExpected: js, |
| 1722 | errExpected: nil, |
| 1723 | }, |
| 1724 | { |
| 1725 | name: "Load JavaScript from an external endpoint that returns an error", |
| 1726 | jsInput: javaScriptHttpErrorEndpoint(), |
| 1727 | insecureSkipVerify: false, |
| 1728 | jsExpected: "", |
| 1729 | errExpected: errInternalServerError, |
| 1730 | }, |
| 1731 | { |
| 1732 | name: "Load JavaScript from an external file", |
| 1733 | jsInput: javaScriptFile(t, js), |
| 1734 | insecureSkipVerify: false, |
| 1735 | jsExpected: js, |
| 1736 | errExpected: nil, |
| 1737 | }, |
| 1738 | { |
| 1739 | name: "Load JavaScript from an external empty file", |
| 1740 | jsInput: emptyJavaScriptFile(t), |
| 1741 | insecureSkipVerify: false, |
| 1742 | jsExpected: "", |
| 1743 | errExpected: nil, |
| 1744 | }, |
nothing calls this directly
no test coverage detected