forked from git-lfs/lfs-test-server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmeta_store_test.go
111 lines (89 loc) · 2.49 KB
/
meta_store_test.go
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
import (
"fmt"
"os"
"testing"
)
var (
metaStoreTest *MetaStore
)
func TestGetWithAuth(t *testing.T) {
setupMeta()
defer teardownMeta()
meta, err := metaStoreTest.Get(&RequestVars{Authorization: testAuth, Oid: contentOid})
if err != nil {
t.Fatalf("Error retreiving meta: %s", err)
}
if meta.Oid != contentOid {
t.Errorf("expected to get content oid, got: %s", meta.Oid)
}
if meta.Size != contentSize {
t.Errorf("expected to get content size, got: %d", meta.Size)
}
}
func TestGetWithoutAuth(t *testing.T) {
setupMeta()
defer teardownMeta()
_, err := metaStoreTest.Get(&RequestVars{Authorization: badAuth, Oid: contentOid})
if !isAuthError(err) {
t.Errorf("expected auth error, got: %s", err)
}
}
func TestPutWithAuth(t *testing.T) {
setupMeta()
defer teardownMeta()
meta, err := metaStoreTest.Put(&RequestVars{Authorization: testAuth, Oid: nonexistingOid, Size: 42})
if err != nil {
t.Errorf("expected put to succeed, got : %s", err)
}
if meta.Existing {
t.Errorf("expected meta to not have existed")
}
meta, err = metaStoreTest.Get(&RequestVars{Authorization: testAuth, Oid: nonexistingOid})
if err != nil {
t.Errorf("expected to be able to retreive new put, got : %s", err)
}
if meta.Oid != nonexistingOid {
t.Errorf("expected oids to match, got: %s", meta.Oid)
}
if meta.Size != 42 {
t.Errorf("expected sizes to match, got: %d", meta.Size)
}
meta, err = metaStoreTest.Put(&RequestVars{Authorization: testAuth, Oid: nonexistingOid, Size: 42})
if err != nil {
t.Errorf("expected put to succeed, got : %s", err)
}
if !meta.Existing {
t.Errorf("expected meta to now exist")
}
}
func TestPuthWithoutAuth(t *testing.T) {
setupMeta()
defer teardownMeta()
_, err := metaStoreTest.Put(&RequestVars{Authorization: badAuth, Oid: contentOid, Size: 42})
if !isAuthError(err) {
t.Errorf("expected auth error, got: %s", err)
}
}
func setupMeta() {
store, err := NewMetaStore("test-meta-store.db")
if err != nil {
fmt.Printf("error initializing test meta store: %s\n", err)
os.Exit(1)
}
metaStoreTest = store
if err := metaStoreTest.AddUser(testUser, testPass); err != nil {
teardownMeta()
fmt.Printf("error adding test user to meta store: %s\n", err)
os.Exit(1)
}
rv := &RequestVars{Authorization: testAuth, Oid: contentOid, Size: contentSize}
if _, err := metaStoreTest.Put(rv); err != nil {
teardownMeta()
fmt.Printf("error seeding test meta store: %s\n", err)
os.Exit(1)
}
}
func teardownMeta() {
os.RemoveAll("test-meta-store.db")
}