forked from grafana/loki
/
fixtures.go
80 lines (66 loc) · 1.55 KB
/
fixtures.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
package local
import (
"io"
"io/ioutil"
"os"
"time"
"github.com/prometheus/common/model"
"github.com/frelon/loki/v2/pkg/storage/chunk"
"github.com/frelon/loki/v2/pkg/storage/chunk/objectclient"
"github.com/frelon/loki/v2/pkg/storage/chunk/testutils"
)
type fixture struct {
name string
dirname string
}
func (f *fixture) Name() string {
return f.name
}
func (f *fixture) Clients() (
indexClient chunk.IndexClient, chunkClient chunk.Client, tableClient chunk.TableClient,
schemaConfig chunk.SchemaConfig, closer io.Closer, err error,
) {
f.dirname, err = ioutil.TempDir(os.TempDir(), "boltdb")
if err != nil {
return
}
indexClient, err = NewBoltDBIndexClient(BoltDBConfig{
Directory: f.dirname,
})
if err != nil {
return
}
oClient, err := NewFSObjectClient(FSConfig{Directory: f.dirname})
if err != nil {
return
}
chunkClient = objectclient.NewClient(oClient, objectclient.FSEncoder, chunk.SchemaConfig{})
tableClient, err = NewTableClient(f.dirname)
if err != nil {
return
}
schemaConfig = chunk.SchemaConfig{
Configs: []chunk.PeriodConfig{{
IndexType: "boltdb",
From: chunk.DayTime{Time: model.Now()},
ChunkTables: chunk.PeriodicTableConfig{
Prefix: "chunks",
Period: 10 * time.Minute,
},
IndexTables: chunk.PeriodicTableConfig{
Prefix: "index",
Period: 10 * time.Minute,
},
}},
}
closer = testutils.CloserFunc(func() error {
return os.RemoveAll(f.dirname)
})
return
}
// Fixtures for unit testing GCP storage.
var Fixtures = []testutils.Fixture{
&fixture{
name: "boltdb",
},
}