Skip to content

Commit

Permalink
Minor clean-up
Browse files Browse the repository at this point in the history
Signed-off-by: Yuri Shkuro <ys@uber.com>
  • Loading branch information
Yuri Shkuro committed Jan 3, 2018
1 parent d2140b8 commit b11efc9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
11 changes: 5 additions & 6 deletions plugin/storage/cassandra/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (

"github.com/stretchr/testify/assert"
"github.com/uber/jaeger-lib/metrics"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/pkg/cassandra"
"github.com/jaegertracing/jaeger/pkg/cassandra/mocks"
"github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/testutils"
"github.com/jaegertracing/jaeger/storage"
)

Expand All @@ -47,14 +47,13 @@ func TestCassandraFactory(t *testing.T) {
command.ParseFlags([]string{})
f.InitFromViper(v)

logger, _ := testutils.NewLogger()
// after InitFromViper, f.primaryConfig points to a real sssion builder that will fail in unit tests
// so we override it with mock
// after InitFromViper, f.primaryConfig points to a real session builder that will fail in unit tests,
// so we override it with a mock.
f.primaryConfig = &mockSessionBuilder{err: errors.New("made-up error")}
assert.EqualError(t, f.Initialize(metrics.NullFactory, logger), "made-up error")
assert.EqualError(t, f.Initialize(metrics.NullFactory, zap.NewNop()), "made-up error")

f.primaryConfig = &mockSessionBuilder{}
assert.NoError(t, f.Initialize(metrics.NullFactory, logger))
assert.NoError(t, f.Initialize(metrics.NullFactory, zap.NewNop()))

_, err := f.CreateSpanReader()
assert.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions plugin/storage/cassandra/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ func addFlags(flagSet *flag.FlagSet, nsConfig *namespaceConfig) {

// InitFromViper initializes Options with properties from viper
func (opt *Options) InitFromViper(v *viper.Viper) {
initNamespaceFromViper(opt.primary, v)
opt.primary.initFromViper(v)
for _, cfg := range opt.others {
initNamespaceFromViper(cfg, v)
cfg.initFromViper(v)
}
opt.SpanStoreWriteCacheTTL = v.GetDuration(opt.primary.namespace + suffixSpanStoreWriteCacheTTL)
opt.DepStoreDataFrequency = v.GetDuration(opt.primary.namespace + suffixDepStoreDataFrequency)
}

func initNamespaceFromViper(cfg *namespaceConfig, v *viper.Viper) {
func (cfg *namespaceConfig) initFromViper(v *viper.Viper) {
cfg.ConnectionsPerHost = v.GetInt(cfg.namespace + suffixConnPerHost)
cfg.MaxRetryAttempts = v.GetInt(cfg.namespace + suffixMaxRetryAttempts)
cfg.Timeout = v.GetDuration(cfg.namespace + suffixTimeout)
Expand Down
13 changes: 6 additions & 7 deletions plugin/storage/es/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import (

"github.com/stretchr/testify/assert"
"github.com/uber/jaeger-lib/metrics"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/es"
escfg "github.com/jaegertracing/jaeger/pkg/es/config"
"github.com/jaegertracing/jaeger/pkg/es/mocks"
"github.com/jaegertracing/jaeger/pkg/testutils"
"github.com/jaegertracing/jaeger/storage"
)

Expand All @@ -43,20 +43,19 @@ func (m *mockClientBuilder) NewClient() (es.Client, error) {
return nil, m.err
}

func TestFactory(t *testing.T) {
func TestElasticsearchFactory(t *testing.T) {
f := NewFactory()
v, command := config.Viperize(f.AddFlags)
command.ParseFlags([]string{})
f.InitFromViper(v)

logger, _ := testutils.NewLogger()
// after InitFromViper, f.primaryConfig points to a real sssion builder that will fail in unit tests
// so we override it with mock
// after InitFromViper, f.primaryConfig points to a real session builder that will fail in unit tests,
// so we override it with a mock.
f.primaryConfig = &mockClientBuilder{err: errors.New("made-up error")}
assert.EqualError(t, f.Initialize(metrics.NullFactory, logger), "made-up error")
assert.EqualError(t, f.Initialize(metrics.NullFactory, zap.NewNop()), "made-up error")

f.primaryConfig = &mockClientBuilder{}
assert.NoError(t, f.Initialize(metrics.NullFactory, logger))
assert.NoError(t, f.Initialize(metrics.NullFactory, zap.NewNop()))

_, err := f.CreateSpanReader()
assert.NoError(t, err)
Expand Down

0 comments on commit b11efc9

Please sign in to comment.