-
Notifications
You must be signed in to change notification settings - Fork 784
/
fixtures.go
72 lines (59 loc) · 1.65 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
package cassandra
import (
"context"
"os"
"github.com/cortexproject/cortex/pkg/chunk"
"github.com/cortexproject/cortex/pkg/chunk/testutils"
)
// GOCQL doesn't provide nice mocks, so we use a real Cassandra instance.
// To enable these tests:
// $ docker run --name cassandra --rm -p 9042:9042 cassandra:3.11
// $ CASSANDRA_TEST_ADDRESSES=localhost:9042 go test ./pkg/chunk/storage
type fixture struct {
name string
indexClient chunk.IndexClient
objectClient chunk.Client
tableClient chunk.TableClient
schemaConfig chunk.SchemaConfig
}
func (f fixture) Name() string {
return f.name
}
func (f fixture) Clients() (chunk.IndexClient, chunk.Client, chunk.TableClient, chunk.SchemaConfig, error) {
return f.indexClient, f.objectClient, f.tableClient, f.schemaConfig, nil
}
func (f fixture) Teardown() error {
return nil
}
// Fixtures for unit testing Cassandra integration.
func Fixtures() ([]testutils.Fixture, error) {
addresses := os.Getenv("CASSANDRA_TEST_ADDRESSES")
if addresses == "" {
return nil, nil
}
cfg := Config{
Addresses: addresses,
Keyspace: "test",
Consistency: "QUORUM",
ReplicationFactor: 1,
}
// Get a SchemaConfig with the defaults.
schemaConfig := testutils.DefaultSchemaConfig("cassandra")
storageClient, err := NewStorageClient(cfg, schemaConfig)
if err != nil {
return nil, err
}
tableClient, err := NewTableClient(context.Background(), cfg)
if err != nil {
return nil, err
}
return []testutils.Fixture{
fixture{
name: "Cassandra",
indexClient: storageClient,
objectClient: storageClient,
tableClient: tableClient,
schemaConfig: schemaConfig,
},
}, nil
}