key
Juan Batiz-Benet committed
Jul 5, 2014 at 14:55 UTC
4d80a2d214ff1a94a8ad0138282d49887299da25
2 files changed
+32
-1
util/util.go
+4
-1
@@ -1,4 +1,4 @@
1
-package data
1
+package util
2
3
import (
4
"fmt"
@@ -8,6 +8,9 @@ import (
8
var Debug bool
9
var NotImplementedError = fmt.Errorf("Error: not implemented yet.")
10
11
+// a Key for maps. It's a string (rep of a multihash).
12
+type Key string
13
+
14
// Shorthand printing functions.
15
func PErr(format string, a ...interface{}) {
16
fmt.Fprintf(os.Stderr, format, a...)
util/util_test.go
new
+28
@@ -0,0 +1,28 @@
1
+package util
2
+
3
+import (
4
+ "bytes"
5
+ "fmt"
6
+ mh "github.com/jbenet/go-multihash"
7
+ "testing"
8
+)
9
+
10
+func TestKey(t *testing.T) {
11
+
12
+ h1, err := mh.Sum([]byte("beep boop"), mh.SHA2_256, -1)
13
+ if err != nil {
14
+ t.Error(err)
15
+ }
16
+
17
+ k1 := Key(h1)
18
+ h2 := mh.Multihash(k1)
19
+ k2 := Key(h2)
20
+
21
+ if !bytes.Equal(h1, h2) {
22
+ t.Error("Multihashes not equal.")
23
+ }
24
+
25
+ if k1 != k2 {
26
+ t.Error("Keys not equal.")
27
+ }
28
+}