Skip to content

Commit

Permalink
Remove TestMultierror
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed Apr 7, 2023
1 parent 8e91dd4 commit f9c05c5
Showing 1 changed file with 2 additions and 75 deletions.
77 changes: 2 additions & 75 deletions common/remote_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ package common

import (
"encoding/json"
"errors"
"fmt"
"math"
"testing"

"github.com/grafana/xk6-browser/k6ext/k6test"

"github.com/chromedp/cdproto/runtime"
"github.com/dop251/goja"
"github.com/mailru/easyjson"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/grafana/xk6-browser/k6ext/k6test"
)

func TestValueFromRemoteObject(t *testing.T) {
Expand Down Expand Up @@ -236,74 +234,3 @@ func TestParseRemoteObject(t *testing.T) {
})
}
}

func TestMultierror(t *testing.T) {
t.Parallel()

var (
mockErr1 = errors.New("mockErr1")
mockErr2 = errors.New("mockErr2")
mockErr3 = errors.New("mockErr3")

mockMultiErr = &multiError{
Errors: []error{mockErr1},
}
mockWrappedMultiErr = fmt.Errorf("%w", mockMultiErr)
)

tests := []struct {
name string
initial error
errs []error
exp []error
expStr string
}{
{
name: "initial error is nil",
initial: nil,
errs: []error{mockErr1},
exp: []error{mockErr1},
expStr: mockErr1.Error(),
},
{
name: "initial error is std error",
initial: mockErr1,
errs: []error{mockErr2, mockErr3},
exp: []error{mockErr1, mockErr2, mockErr3},
expStr: fmt.Sprintf(
"3 errors occurred:\n\t* %s\n\t* %s\n\t* %s\n",
mockErr1, mockErr2, mockErr3),
},
{
name: "initial error is multiError",
initial: mockMultiErr,
errs: []error{mockErr3},
exp: []error{mockErr1, mockErr3},
expStr: fmt.Sprintf(
"2 errors occurred:\n\t* %s\n\t* %s\n",
mockErr1, mockErr3),
},
{
name: "initial error is wrapped multiError",
initial: mockWrappedMultiErr,
errs: []error{mockErr3, mockErr2},
exp: []error{mockWrappedMultiErr, mockErr3, mockErr2},
expStr: fmt.Sprintf(
"3 errors occurred:\n\t* %s\n\t* %s\n\t* %s\n",
mockWrappedMultiErr, mockErr3, mockErr2),
},
}

for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

err := multierror(tc.initial, tc.errs...)
var me *multiError
assert.True(t, errors.As(err, &me))
assert.Equal(t, tc.exp, me.Errors)
assert.Equal(t, tc.expStr, me.Error())
})
}
}

0 comments on commit f9c05c5

Please sign in to comment.