forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrapers_test.go
65 lines (55 loc) · 1.78 KB
/
scrapers_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
package kv_test
import (
"context"
"testing"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/kv"
"github.com/influxdata/influxdb/v2/mock"
"github.com/influxdata/influxdb/v2/tenant"
influxdbtesting "github.com/influxdata/influxdb/v2/testing"
"go.uber.org/zap/zaptest"
)
func TestBoltScraperTargetStoreService(t *testing.T) {
influxdbtesting.ScraperService(initBoltTargetService, t)
}
func initBoltTargetService(f influxdbtesting.TargetFields, t *testing.T) (influxdb.ScraperTargetStoreService, string, func()) {
s, closeFn := influxdbtesting.NewTestBoltStore(t)
svc, op, closeSvc := initScraperTargetStoreService(s, f, t)
return svc, op, func() {
closeSvc()
closeFn()
}
}
func initScraperTargetStoreService(s kv.SchemaStore, f influxdbtesting.TargetFields, t *testing.T) (influxdb.ScraperTargetStoreService, string, func()) {
ctx := context.Background()
tenantStore := tenant.NewStore(s)
tenantSvc := tenant.NewService(tenantStore)
svc := kv.NewService(zaptest.NewLogger(t), s, tenantSvc)
if f.IDGenerator != nil {
svc.IDGenerator = f.IDGenerator
}
for _, target := range f.Targets {
if err := svc.PutTarget(ctx, target); err != nil {
t.Fatalf("failed to populate targets: %v", err)
}
}
for _, o := range f.Organizations {
mock.SetIDForFunc(&tenantStore.OrgIDGen, o.ID, func() {
if err := tenantSvc.CreateOrganization(ctx, o); err != nil {
t.Fatalf("failed to populate organization")
}
})
}
return svc, kv.OpPrefix, func() {
for _, target := range f.Targets {
if err := svc.RemoveTarget(ctx, target.ID); err != nil {
t.Logf("failed to remove targets: %v", err)
}
}
for _, o := range f.Organizations {
if err := tenantSvc.DeleteOrganization(ctx, o.ID); err != nil {
t.Logf("failed to remove orgs: %v", err)
}
}
}
}