According to https://github.com/golang/go/issues/5373, go recognizes (and optimizes for) the following syntax: ```go for i := range b { b[i] = 0 } ``` so let's use it. Limited testing shows ~7.5x speed increase, compared to the previously used syntax. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com> Upstream-commit: f0cab0e28512de5eecc0412212425cc74d62af71 Component: engine
28 lines
642 B
Go
28 lines
642 B
Go
package testutil
|
|
|
|
import (
|
|
"io"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// ErrorContains checks that the error is not nil, and contains the expected
|
|
// substring.
|
|
func ErrorContains(t require.TestingT, err error, expectedError string, msgAndArgs ...interface{}) {
|
|
require.Error(t, err, msgAndArgs...)
|
|
assert.Contains(t, err.Error(), expectedError, msgAndArgs...)
|
|
}
|
|
|
|
// DevZero acts like /dev/zero but in an OS-independent fashion.
|
|
var DevZero io.Reader = devZero{}
|
|
|
|
type devZero struct{}
|
|
|
|
func (d devZero) Read(p []byte) (n int, err error) {
|
|
for i := range p {
|
|
p[i] = 0
|
|
}
|
|
return len(p), nil
|
|
}
|