forked from ipfs/go-datastore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
features_test.go
77 lines (71 loc) · 1.83 KB
/
features_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
package datastore
import (
"fmt"
"reflect"
"testing"
)
func TestFeatureByName(t *testing.T) {
feat, ok := FeatureByName(FeatureNameBatching)
if !ok {
t.Fatalf("expected a batching feature")
}
if feat.Name != FeatureNameBatching ||
feat.Interface != (*BatchingFeature)(nil) ||
feat.DatastoreInterface != (*Batching)(nil) {
t.Fatalf("expected a batching feature, got %v", feat)
}
feat, ok = FeatureByName("UnknownFeature")
if ok {
t.Fatalf("expected UnknownFeature not to be found")
}
}
func featuresByNames(names []string) (fs []Feature) {
for _, n := range names {
f, ok := FeatureByName(n)
if !ok {
panic(fmt.Sprintf("unknown feature %s", n))
}
fs = append(fs, f)
}
return
}
func TestFeaturesForDatastore(t *testing.T) {
cases := []struct {
name string
d Datastore
expectedFeatures []string
}{
{
name: "MapDatastore",
d: &MapDatastore{},
expectedFeatures: []string{"Batching"},
},
{
name: "NullDatastore",
d: &NullDatastore{},
expectedFeatures: []string{"Batching", "Checked", "GC", "Persistent", "Scrubbed", "Transaction"},
},
{
name: "LogDatastore",
d: &LogDatastore{},
expectedFeatures: []string{"Batching", "Checked", "GC", "Persistent", "Scrubbed"},
},
{
name: "nil datastore",
d: nil,
expectedFeatures: nil,
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
feats := FeaturesForDatastore(c.d)
if len(feats) != len(c.expectedFeatures) {
t.Fatalf("expected %d features, got %v", len(c.expectedFeatures), feats)
}
expectedFeats := featuresByNames(c.expectedFeatures)
if !reflect.DeepEqual(expectedFeats, feats) {
t.Fatalf("expected features %v, got %v", c.expectedFeatures, feats)
}
})
}
}