-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackend_test.go
50 lines (40 loc) · 1.05 KB
/
backend_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
package main
import (
"github.com/dchest/uniuri"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Backend", func() {
var backend *MongoBackend
It("should create a backend", func() {
backend = &MongoBackend{
Collection: "files",
Database: "test-fe",
Host: "localhost",
}
Ω(backend.Init()).To(BeNil())
})
It("should create and id", func() {
Ω(backend.NewId()).ToNot(BeNil())
Ω(len(backend.NewId())).ToNot(Equal(0))
})
It("should set something and get it", func() {
id := backend.NewId()
Ω(id).ToNot(BeNil())
data := map[string]interface{}{
"test": uniuri.New(),
}
Ω(backend.Set(id, data)).To(BeNil())
from := make(map[string]interface{})
from, err := backend.Get(id)
Ω(err).To(BeNil())
Ω(from).ToNot(BeNil())
Ω(from["test"]).ToNot(BeNil())
Ω(from["test"]).To(Equal(data["test"]))
Ω(backend.Delete(id)).To(BeNil())
Ω(backend.Delete(id)).To(Equal(ErrNotFound))
from = make(map[string]interface{})
from, err = backend.Get(id)
Ω(err).To(Equal(ErrNotFound))
})
})