-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathhashing_test.go
More file actions
51 lines (42 loc) · 803 Bytes
/
hashing_test.go
File metadata and controls
51 lines (42 loc) · 803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"os"
"testing"
)
func TestNewJSONHashStore(t *testing.T) {
f, err := os.CreateTemp("", "")
if err != nil {
t.Fatal(err)
}
h, err := NewJSONHashStore(f.Name(), HashStrategyReadWrite)
if err != nil {
t.Fatal(err)
}
if err := h.Add("foo", "bar"); err != nil {
t.Fatal(err)
}
if err := h.Save(); err != nil {
t.Fatal(err)
}
h, err = NewJSONHashStore(f.Name(), HashStrategyRead)
if err != nil {
t.Fatal(err)
}
hash, err := h.Get("foo")
if err != nil {
t.Fatal(err)
}
if hash != "bar" {
t.Fatal("Expected hash to match")
}
}
func TestNewJSONHashStore_InvalidJSON(t *testing.T) {
f, err := os.CreateTemp("", "")
if err != nil {
t.Fatal(err)
}
_, err = NewJSONHashStore(f.Name(), HashStrategyReadWrite)
if err != nil {
t.Fatal(err)
}
}