From 02ba64d9df2f4f1fd931bc06f4969115d2ad64b7 Mon Sep 17 00:00:00 2001 From: Ned Palacios Date: Tue, 30 Jan 2024 11:05:36 +0800 Subject: [PATCH] feat: add test extract variables for multiple errors --- error_template_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/error_template_test.go b/error_template_test.go index 327609d..2eea9fd 100644 --- a/error_template_test.go +++ b/error_template_test.go @@ -229,6 +229,50 @@ func TestExtractVariables(t *testing.T) { t.Fatalf("expected %v, got %v", exp, variables) } }) + + t.Run("Multiple", func(t *testing.T) { + inputs := []string{ + "invalid input '123abc'\nin main at /home/user/main.py:123\nin main at /home/user/main.py:1", + "invalid input 'shouldNotBeIncluded'\nin main at /home/user/main.py:123\nin main at /home/user/main.py:1", + } + input := strings.Join(inputs, "\n\n") + if !tmp.Match(input) { + t.Fatalf("expected template to match input, got false instead") + } + + variables := tmp.ExtractVariables(input) + exp := map[string]string{ + "stacktrace": "\nin main at /home/user/main.py:123\nin main at /home/user/main.py:1", + "input": "123abc", + } + + fmt.Printf("%q\n", variables) + if !reflect.DeepEqual(variables, exp) { + t.Fatalf("expected %v, got %v", exp, variables) + } + }) + + t.Run("Multiple no stack trace", func(t *testing.T) { + inputs := []string{ + "invalid input '123abc'", + "invalid input 'shouldNotBeIncluded'", + } + input := strings.Join(inputs, "\n\n") + if !tmp.Match(input) { + t.Fatalf("expected template to match input, got false instead") + } + + variables := tmp.ExtractVariables(input) + exp := map[string]string{ + "stacktrace": "\nin main at /home/user/main.py:123\nin main at /home/user/main.py:1", + "input": "123abc", + } + + fmt.Printf("%q\n", variables) + if !reflect.DeepEqual(variables, exp) { + t.Fatalf("expected %v, got %v", exp, variables) + } + }) } func TestExtractStackTrace(t *testing.T) {