mirror of
https://github.com/hanzoai/o11y.git
synced 2026-10-30 14:56:15 +00:00
* chore: custom notifiers in alert manager * chore: lint fixs * chore: fix email linter * chore: added tracing to msteamsv2 notifier * feat: alert manager template to template title and notification body * chore: updated test name + code for timeout errors * chore: added utils for using variables with $ notation * chore: exposed templates for alertmanager types * feat: added preprocessor for alert templater * chore: hooked preProcess function in expandTitle and body, added labels and annotations in alertdata * chore: fix lint issues * chore: added handling for missing variable used in template * feat: converted alerttemplater to interface and updated tests * refactor: added extractCommonKV instead of 2 different functions * test: fix preprocessor test case * feat: added support for and in templating * chore: lint fix * chore: renamed the interface * chore: added test for missing function * refactor: test case and sb related changed * refactor: comments and test improvements * chore: lint fix * chore: updated comments * feat: added basic html markdown templater * chore: updated newline to markdown format * feat: slack blockkit renderer using goldmark * test: added test for html rendering * feat: integrated slack blockit in markdownrenderer package and removed plaintext format * chore: updated br with new line in test and logs added * refactor: review comments * refactor: lint fixes * chore: updated licenses for notifiers * chore: updated email notifier from upstream * feat: return single templating result from with flag for template type * fix: variables with symbols in template * feat: slack mrkdwn renderer * feat: custom raw html renderer to escape <no value> * chore: integrated slack mrkdwn renderer and added NoOp formatter * chore: removed notifier test files * fix: concurrent rendering in markdown renderer * refactor: changes as per internal review * chore: lint issue * chore: removed special handling for softline break * refactor: removed logger as markdown renderer dependency * refactor: changed markdown renderer from interface to package-level functions --------- Co-authored-by: Srikanth Chekuri <[email protected]>
116 lines
3.5 KiB
Go
116 lines
3.5 KiB
Go
package mrkdwn
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/yuin/goldmark"
|
|
)
|
|
|
|
func TestRenderer(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
markdown string
|
|
expected string
|
|
}{
|
|
{
|
|
name: "Heading with Thematic Break",
|
|
markdown: "# Title 1\n# Hello World\n---\nthis is sometext",
|
|
expected: "*Title 1*\n\n*Hello World*\n\n---\n\nthis is sometext\n\n",
|
|
},
|
|
{
|
|
name: "Blockquote",
|
|
markdown: "> This is a quote\n> It continues",
|
|
expected: "> This is a quote\n> It continues\n\n",
|
|
},
|
|
{
|
|
name: "Fenced Code Block",
|
|
markdown: "```go\npackage main\nfunc main() {}\n```",
|
|
expected: "```\npackage main\nfunc main() {}\n```\n\n",
|
|
},
|
|
{
|
|
name: "Unordered List",
|
|
markdown: "- item 1\n- item 2\n- item 3",
|
|
expected: "• item 1\n• item 2\n• item 3\n\n",
|
|
},
|
|
{
|
|
name: "nested unordered list",
|
|
markdown: "- item 1\n- item 2\n\t- item 2.1\n\t\t- item 2.1.1\n\t\t- item 2.1.2\n\t- item 2.2\n- item 3",
|
|
expected: "• item 1\n• item 2\n\t• item 2.1\n\t\t• item 2.1.1\n\t\t• item 2.1.2\n\t• item 2.2\n• item 3\n\n",
|
|
},
|
|
{
|
|
name: "Ordered List",
|
|
markdown: "1. item 1\n2. item 2\n3. item 3",
|
|
expected: "1. item 1\n2. item 2\n3. item 3\n\n",
|
|
},
|
|
{
|
|
name: "nested ordered list",
|
|
markdown: "1. item 1\n2. item 2\n\t1. item 2.1\n\t\t1. item 2.1.1\n\t\t2. item 2.1.2\n\t2. item 2.2\n\t3. item 2.3\n3. item 3\n4. item 4",
|
|
expected: "1. item 1\n2. item 2\n\t1. item 2.1\n\t\t1. item 2.1.1\n\t\t2. item 2.1.2\n\t2. item 2.2\n\t3. item 2.3\n3. item 3\n4. item 4\n\n",
|
|
},
|
|
{
|
|
name: "Links and AutoLinks",
|
|
markdown: "This is a [link](https://example.com) and an autolink <https://test.com>",
|
|
expected: "This is a <https://example.com|link> and an autolink <https://test.com>\n\n",
|
|
},
|
|
{
|
|
name: "Images",
|
|
markdown: "An image ",
|
|
expected: "An image <https://example.com/image.png|alt text>\n\n",
|
|
},
|
|
{
|
|
name: "Emphasis",
|
|
markdown: "This is **bold** and *italic* and __bold__ and _italic_",
|
|
expected: "This is *bold* and _italic_ and *bold* and _italic_\n\n",
|
|
},
|
|
{
|
|
name: "Strikethrough",
|
|
markdown: "This is ~~strike~~",
|
|
expected: "This is ~strike~\n\n",
|
|
},
|
|
{
|
|
name: "Code Span",
|
|
markdown: "This is `inline code` embedded.",
|
|
expected: "This is `inline code` embedded.\n\n",
|
|
},
|
|
{
|
|
name: "Table",
|
|
markdown: "Col 1 | Col 2 | Col 3\n--- | --- | ---\nVal 1 | Long Value 2 | 3\nShort | V | 1000",
|
|
expected: "```\nCol 1 | Col 2 | Col 3\n------|--------------|------\nVal 1 | Long Value 2 | 3 \nShort | V | 1000 \n```\n\n",
|
|
},
|
|
{
|
|
name: "Mixed Nested Lists",
|
|
markdown: "1. first\n\t- nested bullet\n\t- another bullet\n2. second",
|
|
expected: "1. first\n\t• nested bullet\n\t• another bullet\n2. second\n\n",
|
|
},
|
|
{
|
|
name: "Email AutoLink",
|
|
markdown: "<[email protected]>",
|
|
expected: "<mailto:[email protected]|[email protected]>\n\n",
|
|
},
|
|
{
|
|
name: "No value string parsed as is",
|
|
markdown: "Service: <no value>",
|
|
expected: "Service: <no value>\n\n",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
md := goldmark.New(goldmark.WithExtensions(Extender))
|
|
|
|
var buf bytes.Buffer
|
|
if err := md.Convert([]byte(tt.markdown), &buf); err != nil {
|
|
t.Fatalf("failed to convert: %v", err)
|
|
}
|
|
|
|
// Do exact string matching
|
|
actual := buf.String()
|
|
if actual != tt.expected {
|
|
t.Errorf("\nExpected:\n%q\nGot:\n%q\nRaw Expected:\n%s\nRaw Got:\n%s",
|
|
tt.expected, actual, tt.expected, actual)
|
|
}
|
|
})
|
|
}
|
|
}
|