Skip to content

Commit

Permalink
Moved TestSharder to fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mterhar committed Nov 2, 2023
1 parent 472d3ce commit 4ed1442
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
2 changes: 2 additions & 0 deletions collect/collect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/honeycombio/refinery/logger"
"github.com/honeycombio/refinery/metrics"
"github.com/honeycombio/refinery/sample"
"github.com/honeycombio/refinery/sharder"
"github.com/honeycombio/refinery/transmit"
"github.com/honeycombio/refinery/types"
)
Expand Down Expand Up @@ -792,6 +793,7 @@ func TestDependencyInjection(t *testing.T) {
&inject.Object{Value: &sample.SamplerFactory{}},
&inject.Object{Value: &MockStressReliever{}, Name: "stressRelief"},
&inject.Object{Value: &peer.MockPeers{}},
&inject.Object{Value: &sharder.TestSharder{}},
)
if err != nil {
t.Error(err)
Expand Down
21 changes: 2 additions & 19 deletions route/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func TestDebugTrace(t *testing.T) {

rr := httptest.NewRecorder()
router := &Router{
Sharder: &TestSharder{},
Sharder: &sharder.TestSharder{},
}

router.debugTrace(rr, req)
Expand Down Expand Up @@ -425,7 +425,7 @@ func TestDependencyInjection(t *testing.T) {
&inject.Object{Value: http.DefaultTransport, Name: "upstreamTransport"},
&inject.Object{Value: &transmit.MockTransmission{}, Name: "upstreamTransmission"},
&inject.Object{Value: &transmit.MockTransmission{}, Name: "peerTransmission"},
&inject.Object{Value: &TestSharder{}},
&inject.Object{Value: &sharder.TestSharder{}},
&inject.Object{Value: &collect.InMemCollector{}},
&inject.Object{Value: &metrics.NullMetrics{}, Name: "metrics"},
&inject.Object{Value: &metrics.NullMetrics{}, Name: "genericMetrics"},
Expand All @@ -440,23 +440,6 @@ func TestDependencyInjection(t *testing.T) {
}
}

type TestSharder struct{}

func (s *TestSharder) MyShard() sharder.Shard { return nil }

func (s *TestSharder) WhichShard(string) sharder.Shard {
return &TestShard{
addr: "http://localhost:12345",
}
}

type TestShard struct {
addr string
}

func (s *TestShard) Equals(other sharder.Shard) bool { return true }
func (s *TestShard) GetAddress() string { return s.addr }

func TestEnvironmentCache(t *testing.T) {
t.Run("calls getFn on cache miss", func(t *testing.T) {
cache := newEnvironmentCache(time.Second, func(key string) (string, error) {
Expand Down
18 changes: 18 additions & 0 deletions sharder/mock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package sharder

type TestSharder struct{}

func (s *TestSharder) MyShard() Shard { return nil }

func (s *TestSharder) WhichShard(string) Shard {
return &TestShard{
addr: "http://localhost:12345",
}
}

type TestShard struct {
addr string
}

func (s *TestShard) Equals(other Shard) bool { return true }
func (s *TestShard) GetAddress() string { return s.addr }

0 comments on commit 4ed1442

Please sign in to comment.