Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcamou committed Nov 13, 2024
1 parent 2f610f9 commit 47d3841
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
23 changes: 16 additions & 7 deletions pkg/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ import (
"github.com/masa-finance/masa-oracle/pkg/workers"
)

var constantOptions = []node.Option{
node.WithOracleProtocol(OracleProtocol),
node.WithNodeDataSyncProtocol(NodeDataSyncProtocol),
node.WithNodeGossipTopic(NodeGossipTopic),
node.WithRendezvous(Rendezvous),
node.WithPageSize(PageSize),
}

// WithConstantOptions adds options that are set to constant values. We need to add them to
// the node to avoid a dependency loop.
func WithConstantOptions(nodes ...node.Option) []node.Option {
return append(nodes, constantOptions...)
}

func InitOptions(cfg *AppConfig) ([]node.Option, *workers.WorkHandlerManager, *pubsub.PublicKeySubscriptionHandler) {

Check warning on line 23 in pkg/config/options.go

View check run for this annotation

Codecov / codecov/patch

pkg/config/options.go#L23

Added line #L23 was not covered by tests
// WorkerManager configuration
workerManagerOptions := []workers.WorkerOptionFunc{
Expand All @@ -17,7 +31,7 @@ func InitOptions(cfg *AppConfig) ([]node.Option, *workers.WorkHandlerManager, *p
cachePath = cfg.MasaDir + "/cache"
}

masaNodeOptions := []node.Option{
masaNodeOptions := WithConstantOptions(

Check warning on line 34 in pkg/config/options.go

View check run for this annotation

Codecov / codecov/patch

pkg/config/options.go#L34

Added line #L34 was not covered by tests
node.EnableStaked,
// WithService(),

Check warning on line 36 in pkg/config/options.go

View check run for this annotation

Codecov / codecov/patch

pkg/config/options.go#L36

Added line #L36 was not covered by tests
node.WithEnvironment(cfg.Environment),
Expand All @@ -27,13 +41,8 @@ func InitOptions(cfg *AppConfig) ([]node.Option, *workers.WorkHandlerManager, *p
node.WithMasaDir(cfg.MasaDir),
node.WithCachePath(cachePath),
node.WithKeyManager(cfg.KeyManager),
node.WithOracleProtocol(OracleProtocol),
node.WithNodeDataSyncProtocol(NodeDataSyncProtocol),
node.WithNodeGossipTopic(NodeGossipTopic),
node.WithRendezvous(Rendezvous),
node.WithPageSize(PageSize),
node.WithWorkerProtocol(WorkerProtocol),
}
)

Check warning on line 45 in pkg/config/options.go

View check run for this annotation

Codecov / codecov/patch

pkg/config/options.go#L43-L45

Added lines #L43 - L45 were not covered by tests

if cfg.TwitterScraper {
workerManagerOptions = append(workerManagerOptions, workers.EnableTwitterWorker)
Expand Down
4 changes: 2 additions & 2 deletions pkg/pubsub/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (sm *Manager) AddSubscription(topicName string, handler types.SubscriptionH
for {
msg, err := sub.Next(sm.ctx)
if err != nil {
logrus.Errorf("[-] Error reading from topic: %v", err)
logrus.Errorf("[-] AddSubscription: Error reading from topic: %v", err)
if errors.Is(err, context.Canceled) {
return
}
Expand Down Expand Up @@ -221,7 +221,7 @@ func (sm *Manager) Subscribe(topicName string, handler types.SubscriptionHandler
for {
msg, err := sub.Next(sm.ctx)
if err != nil {
logrus.Errorf("[-] Error reading from topic: %v", err)
logrus.Errorf("[-] Subscribe: Error reading from topic: %v", err)

Check warning on line 224 in pkg/pubsub/manager.go

View check run for this annotation

Codecov / codecov/patch

pkg/pubsub/manager.go#L224

Added line #L224 was not covered by tests
if errors.Is(err, context.Canceled) {
return
}
Expand Down
18 changes: 12 additions & 6 deletions pkg/tests/integration/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"

. "github.com/masa-finance/masa-oracle/node"
"github.com/masa-finance/masa-oracle/pkg/config"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand All @@ -19,8 +20,10 @@ var _ = Describe("Oracle integration tests", func() {

n, err := NewOracleNode(
ctx,
EnableStaked,
EnableRandomIdentity,
config.WithConstantOptions(
EnableStaked,
EnableRandomIdentity,
)...,
)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -36,10 +39,13 @@ var _ = Describe("Oracle integration tests", func() {
}

By(fmt.Sprintf("Generating second node with bootnodes %+v", bootNodes))
n2, err := NewOracleNode(ctx,
EnableStaked,
WithBootNodes(bootNodes...),
EnableRandomIdentity,
n2, err := NewOracleNode(
ctx,
config.WithConstantOptions(
EnableStaked,
WithBootNodes(bootNodes...),
EnableRandomIdentity,
)...,
)
Expect(err).ToNot(HaveOccurred())
Expect(n.Host.ID()).ToNot(Equal(n2.Host.ID()))
Expand Down
7 changes: 5 additions & 2 deletions pkg/tests/node_data/node_data_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
. "github.com/onsi/gomega"

. "github.com/masa-finance/masa-oracle/node"
"github.com/masa-finance/masa-oracle/pkg/config"
"github.com/masa-finance/masa-oracle/pkg/pubsub"
)

Expand All @@ -16,8 +17,10 @@ var _ = Describe("NodeDataTracker", func() {
It("should correctly update NodeData Twitter fields", func() {
testNode, err := NewOracleNode(
context.Background(),
EnableStaked,
EnableRandomIdentity,
config.WithConstantOptions(
EnableStaked,
EnableRandomIdentity,
)...,
)
Expect(err).NotTo(HaveOccurred())

Expand Down

0 comments on commit 47d3841

Please sign in to comment.