Skip to content

Commit

Permalink
Tests: asserting panic values
Browse files Browse the repository at this point in the history
  • Loading branch information
michurin committed Nov 10, 2024
1 parent d61ce26 commit 51fb8bb
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions slogtotext/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,28 @@ func TestFormatter_invalidArgs(t *testing.T) {
}
}

func TestFormatter_invalidFunction(t *testing.T) {
require.Panics(t, func() {
slogtotext.MustFormatter(nil, "{{ . | notExists }}")
})
}

func TestFormatter_invalidTemplate(t *testing.T) {
require.Panics(t, func() {
slogtotext.MustFormatter(nil, "{{")
})
func TestMustFormatter_invalid(t *testing.T) {
for _, cs := range []struct {
name string
template string
value string
}{
{
name: "function",
template: "{{ . | notExists }}",
value: `template: base:1: function "notExists" not defined`,
},
{
name: "template",
template: "{{",
value: "template: base:1: unclosed action",
},
} {
cs := cs
t.Run(cs.name, func(t *testing.T) {
require.PanicsWithValue(t, cs.value, func() {
slogtotext.MustFormatter(nil, cs.template)
})
})
}
}

0 comments on commit 51fb8bb

Please # to comment.