Skip to content

Commit

Permalink
feat: add test extract variables for multiple errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nedpals committed Jan 30, 2024
1 parent 42c7864 commit 02ba64d
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions error_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 02ba64d

Please sign in to comment.