-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_test.go
50 lines (41 loc) · 959 Bytes
/
resource_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 (
"os"
"testing"
)
func TestCommit(t *testing.T) {
rs := resource{Dir: "/a/b", Content: "test1"}
err := rs.commit()
if err == nil {
defer deleteResource(rs.Dir, rs.ID)
}
fetchedResource, _ := getResource(rs.Dir, rs.ID)
if fetchedResource.Content != rs.Content {
t.Error("invalid commited content")
}
}
func TestDelete(t *testing.T) {
rs := resource{Dir: "/a/b", Content: "test1"}
rs.commit()
deleteResource(rs.Dir, rs.ID)
_, err := getResource(rs.Dir, rs.ID)
if err != os.ErrNotExist {
t.Error("error deleting resource")
}
}
func TestUpdate(t *testing.T) {
rs := resource{Dir: "/a/b", Content: "test1"}
err := rs.commit()
if err == nil {
defer deleteResource(rs.Dir, rs.ID)
}
rs.Content = "test2"
err = rs.update()
if err != nil {
t.Fatal(err)
}
fetchedResource, err := getResource(rs.Dir, rs.ID)
if fetchedResource.Content != rs.Content || err != nil {
t.Error("error updating resource")
}
}