my computer is about to die!!!
This commit is contained in:
1 parent
d863dc3bd1
commit
e80f2601ab
13 files changed
+244
-11
No files matched your search
@@ -0,0 +1,13 @@
|
||||
package helper
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func JoinAsError(msg []string) error {
|
||||
if len(msg) > 0 {
|
||||
return errors.New(strings.Join(msg, "\n"))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package helper
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestJoinAsError(t *testing.T) {
|
||||
var errs []string = nil
|
||||
if JoinAsError(errs) != nil {
|
||||
t.Error("expected no errors")
|
||||
}
|
||||
errs = make([]string, 0)
|
||||
if JoinAsError(errs) != nil {
|
||||
t.Error("expected no errors")
|
||||
}
|
||||
|
||||
errs = []string{"a", "b"}
|
||||
if JoinAsError(errs).Error() != "a\nb" {
|
||||
t.Error("bad error")
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,10 @@ import (
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"os"
|
||||
)
|
||||
|
||||
func B(x int64) *big.Int {
|
||||
@@ -120,3 +122,19 @@ func GetRSAPrivateKey(size int) *rsa.PrivateKey {
|
||||
return key
|
||||
|
||||
}
|
||||
|
||||
func GetTmpEmptyFile() *os.File {
|
||||
if f, err := ioutil.TempFile("", ""); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return f
|
||||
}
|
||||
}
|
||||
|
||||
func GetTmpEmptyDir() string {
|
||||
if dirName, err := ioutil.TempDir("", ""); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return dirName
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user