my computer will still die soon
This commit is contained in:
1 parent
e80f2601ab
commit
52a13b9cab
7 files changed
+62
-6
No files matched your search
@@ -11,3 +11,13 @@ func JoinAsError(msg []string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func JoinErrors(errs []error) error {
|
||||
msgs := make([]string, 0, len(errs))
|
||||
for _, err := range errs {
|
||||
if err != nil {
|
||||
msgs = append(msgs, err.Error())
|
||||
}
|
||||
}
|
||||
return JoinAsError(msgs)
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package helper
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -19,3 +20,19 @@ func TestJoinAsError(t *testing.T) {
|
||||
t.Error("bad error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestJoinErrors(t *testing.T) {
|
||||
var errs []error = nil
|
||||
if JoinErrors(errs) != nil {
|
||||
t.Error("expected no errors")
|
||||
}
|
||||
errs = make([]error, 0)
|
||||
if JoinErrors(errs) != nil {
|
||||
t.Error("expected no errors")
|
||||
}
|
||||
|
||||
errs = []error{errors.New("a"), errors.New("b")}
|
||||
if JoinErrors(errs).Error() != "a\nb" {
|
||||
t.Error("bad error")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user