-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
acceptance_e2e_test.go
113 lines (94 loc) · 4 KB
/
acceptance_e2e_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
112
113
package objtesting
import (
"context"
"io/ioutil"
"sort"
"strings"
"testing"
"github.com/improbable-eng/thanos/pkg/objstore"
"github.com/improbable-eng/thanos/pkg/testutil"
)
// TestObjStoreAcceptanceTest_e2e tests all known implementation against interface behaviour contract we agreed on.
// This ensures consistent behaviour across all implementations.
// NOTE: This test assumes strong consistency, but in the same way it does not guarantee that if it passes, the
// used object store is strongly consistent.
func TestObjStore_AcceptanceTest_e2e(t *testing.T) {
ForeachStore(t, func(t testing.TB, bkt objstore.Bucket) {
_, err := bkt.Get(context.Background(), "")
testutil.NotOk(t, err)
testutil.Assert(t, !bkt.IsObjNotFoundErr(err), "expected user error got not found %s", err)
_, err = bkt.Get(context.Background(), "id1/obj_1.some")
testutil.NotOk(t, err)
testutil.Assert(t, bkt.IsObjNotFoundErr(err), "expected not found error got %s", err)
ok, err := bkt.Exists(context.Background(), "id1/obj_1.some")
testutil.Ok(t, err)
testutil.Assert(t, !ok, "expected not exits")
// Upload first object.
testutil.Ok(t, bkt.Upload(context.Background(), "id1/obj_1.some", strings.NewReader("@test-data@")))
// Double check we can immediately read it.
rc1, err := bkt.Get(context.Background(), "id1/obj_1.some")
testutil.Ok(t, err)
defer func() { testutil.Ok(t, rc1.Close()) }()
content, err := ioutil.ReadAll(rc1)
testutil.Ok(t, err)
testutil.Equals(t, "@test-data@", string(content))
rc2, err := bkt.GetRange(context.Background(), "id1/obj_1.some", 1, 3)
testutil.Ok(t, err)
defer func() { testutil.Ok(t, rc2.Close()) }()
content, err = ioutil.ReadAll(rc2)
testutil.Ok(t, err)
testutil.Equals(t, "tes", string(content))
ok, err = bkt.Exists(context.Background(), "id1/obj_1.some")
testutil.Ok(t, err)
testutil.Assert(t, ok, "expected exits")
// Upload other objects.
testutil.Ok(t, bkt.Upload(context.Background(), "id1/obj_2.some", strings.NewReader("@test-data2@")))
testutil.Ok(t, bkt.Upload(context.Background(), "id1/obj_3.some", strings.NewReader("@test-data3@")))
testutil.Ok(t, bkt.Upload(context.Background(), "id2/obj_4.some", strings.NewReader("@test-data4@")))
testutil.Ok(t, bkt.Upload(context.Background(), "obj_5.some", strings.NewReader("@test-data5@")))
// Can we iter over items from top dir?
var seen []string
testutil.Ok(t, bkt.Iter(context.Background(), "", func(fn string) error {
seen = append(seen, fn)
return nil
}))
expected := []string{"obj_5.some", "id1/", "id2/"}
sort.Strings(expected)
sort.Strings(seen)
testutil.Equals(t, expected, seen)
// Can we iter over items from id1/ dir?
seen = []string{}
testutil.Ok(t, bkt.Iter(context.Background(), "id1/", func(fn string) error {
seen = append(seen, fn)
return nil
}))
testutil.Equals(t, []string{"id1/obj_1.some", "id1/obj_2.some", "id1/obj_3.some"}, seen)
// Can we iter over items from id1 dir?
seen = []string{}
testutil.Ok(t, bkt.Iter(context.Background(), "id1", func(fn string) error {
seen = append(seen, fn)
return nil
}))
testutil.Equals(t, []string{"id1/obj_1.some", "id1/obj_2.some", "id1/obj_3.some"}, seen)
// Can we iter over items from not existing dir?
testutil.Ok(t, bkt.Iter(context.Background(), "id0", func(fn string) error {
t.Error("Not expected to loop through not existing directory")
t.FailNow()
return nil
}))
testutil.Ok(t, bkt.Delete(context.Background(), "id1/obj_2.some"))
// Can we iter over items from id1/ dir and see obj2 being deleted?
seen = []string{}
testutil.Ok(t, bkt.Iter(context.Background(), "id1/", func(fn string) error {
seen = append(seen, fn)
return nil
}))
testutil.Equals(t, []string{"id1/obj_1.some", "id1/obj_3.some"}, seen)
testutil.Ok(t, objstore.DeleteDir(context.Background(), bkt, "id1"))
testutil.Ok(t, bkt.Iter(context.Background(), "id1/", func(fn string) error {
t.Error("Not expected to loop through empty / non existing directory")
t.FailNow()
return nil
}))
})
}