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