fixing tests

This commit is contained in:
zach rice committed 2019-11-17 11:56:16 -06:00
1 parent f3eac0c958
commit 8cbb84c50f
6 files changed
+32 -405

No files matched your search

+19 -1
View File
@@ -1,8 +1,11 @@
package manager
import (
"crypto/rand"
"fmt"
"github.com/zricethezav/gitleaks/config"
"github.com/zricethezav/gitleaks/options"
"io"
"testing"
)
@@ -28,7 +31,10 @@ func TestSendReceiveLeaks(t *testing.T) {
m, _ := NewManager(opts, cfg)
for i := 0; i < test.leaksToAdd; i++ {
m.SendLeaks(Leak{})
// we are testing the sync of sending/receiving leaks so we need
// the hash generation in sendLeaks to be unique for each iteration
// so I'm just setting the offender string as a uuid
m.SendLeaks(Leak{Offender: newUUID()})
}
got := m.GetLeaks()
if len(got) != test.leaksToAdd {
@@ -86,3 +92,15 @@ func TestSendReceiveMeta(t *testing.T) {
}
}
}
// newUUID generates a random UUID according to RFC 4122
// Ripped from https://play.golang.org/p/4FkNSiUDMg
func newUUID() string {
uuid := make([]byte, 16)
io.ReadFull(rand.Reader, uuid)
// variant bits; see section 4.1.1
uuid[8] = uuid[8]&^0xc0 | 0x80
// version 4 (pseudo-random); see section 4.1.3
uuid[6] = uuid[6]&^0xf0 | 0x40
return fmt.Sprintf("%x-%x-%x-%x-%x", uuid[0:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:])
}